Files: 0b4d6451ce5d4f2f2c503793f5ac1c61b10bc4ac / test / nestedServices.js
1588 bytesRaw
1 | var test = require('tape') |
2 | |
3 | var vas = require('../') |
4 | var pull = vas.pull |
5 | |
6 | test('can create client and server streams with nested services', function(t) { |
7 | t.plan(2) |
8 | var expectedPeople = ["Timmy", "Bob"] |
9 | var expectedCats = ["Fluffy", "Meow"] |
10 | var services = { |
11 | cats: { |
12 | name: 'cats', |
13 | version: '0.0.0', |
14 | permissions: function (path, args) {}, |
15 | manifest: { |
16 | find: 'source' |
17 | }, |
18 | init: function (server, config) { |
19 | return { find } |
20 | |
21 | function find () { |
22 | return pull.values(expectedCats) |
23 | } |
24 | }, |
25 | services: { |
26 | people: { |
27 | name: 'people', |
28 | version: '0.0.0', |
29 | permissions: function (path, args) {}, |
30 | manifest: { |
31 | find: 'source' |
32 | }, |
33 | init: function (server, config) { |
34 | return { find } |
35 | |
36 | function find () { |
37 | return pull.values(expectedPeople) |
38 | } |
39 | } |
40 | } |
41 | } |
42 | } |
43 | } |
44 | |
45 | var client = vas.createClient(services, {}) |
46 | var server = vas.createServer(services, {}) |
47 | var clientStream = client.createStream() |
48 | var serverStream = server.createStream() |
49 | |
50 | pull( |
51 | clientStream, |
52 | serverStream, |
53 | clientStream |
54 | ) |
55 | |
56 | pull( |
57 | client.cats.find(), |
58 | pull.collect(function(err, arr) { |
59 | t.deepEqual(arr, expectedCats) |
60 | }) |
61 | ) |
62 | pull( |
63 | client.cats.people.find(), |
64 | pull.collect(function(err, arr) { |
65 | t.deepEqual(arr, expectedPeople) |
66 | }) |
67 | ) |
68 | }) |
69 | |
70 |
Built with git-ssb-web