Skip to content

Commit

Permalink
added tests for client subscirption rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim de Beer committed Oct 2, 2016
1 parent 94618ce commit edd7ec0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/client/downstream/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = function createContext (hub, socket, client, stamp) {
} else {
clientobj.device = 'server'
clientobj.platform = 'node.js'
clientobj.blurf = 'haha'
// write node version as well
}
clientobj.cache = {} // reuse old ONE!
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ require('./queue')
require('./clients')
require('./context')
require('./sync')
require('./subscribe')
require('./references')
require('./subscribe')
/*
context needs lots and lots of work
*/
40 changes: 34 additions & 6 deletions test/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,59 @@ test('subscribe - exec function gaurds', (t) => {
})
})


test('subscribe - client', { timeout: 1e3 }, (t) => {
const server = new Hub({
id: 'server',
port: 6000,
field: '$root.a'
})
const client = new Hub({
id: 1,
context: false,
url: 'ws://localhost:6000'
})
client.subscribe({
client: {
platform: { val: true },
ip: { val: true },
device: { val: true }
}
})
client.get('client.origin.platform', {}).once((val, stamp) => {
vstamp.done(stamp, () => {
t.same(client.client.origin().serialize(), {
id: 1,
platform: 'node.js',
ip: '::ffff:127.0.0.1',
device: 'server'
}, 'receive subscription')
client.remove()
server.remove()
t.end()
})
})
})

test('subscribe - switch', { timeout: 1e3 }, (t) => {
// make this failing

const server = new Hub({
id: 'server',
port: 6000,
field: '$root.a',
a: { title: 'it\'s a' },
b: { title: 'it\'s b' }
})

const client = new Hub({
id: 1,
context: false,
url: 'ws://localhost:6000'
})

const client2 = new Hub({
id: 2,
context: false,
url: 'ws://localhost:6000'
})

const subs = {
field: {
val: 1, // this should not be nessecary -- add val: 1 or somethign when switch or listen to switch
Expand All @@ -108,10 +138,8 @@ test('subscribe - switch', { timeout: 1e3 }, (t) => {
}
}
}

client.subscribe(subs)
client2.subscribe(subs)

client.get('field', {}).once((val, stamp) => vstamp.done(stamp, () => {
t.same(client.field.val, client.a, 'client receives reference on "field"')
t.same(client.a.title.val, 'it\'s a', 'client receives "a.title"')
Expand Down

0 comments on commit edd7ec0

Please sign in to comment.