-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test adding someone back into the group #111
Changes from 14 commits
22e5fd6
acfaa9b
90d9f0e
c1e1d13
61269d3
9123c5c
438cfec
a1cd25f
c47037e
7a7e109
5457c45
5356f7b
909ae88
fc442e3
f438299
a89e9e4
2127602
07d785a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ | |
"test:only": "if grep -r --exclude-dir=node_modules --exclude-dir=.git --color 'test\\.only' ; then exit 1; fi", | ||
"test:bail": "npm run test:raw | tap-arc --bail", | ||
"test": "npm run test:raw | tap-arc && npm run test:only", | ||
"lint": "eslint .", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good, I've been missing this - I caught an "unused var" the other day, or maybe undefined var. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my editor's been running it automatically on save but realized we didn't have an official way of doing it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added to npm test |
||
"format-code": "prettier --write \"**/*.js\"", | ||
"format-code-staged": "pretty-quick --staged --pattern \"**/*.js\"", | ||
"coverage": "c8 --reporter=lcov npm run test" | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -447,3 +447,103 @@ test('addMembers adds to all the tip epochs and gives keys to all the old epochs | |||||||||||||||
p(david.close)(true), | ||||||||||||||||
]) | ||||||||||||||||
}) | ||||||||||||||||
|
||||||||||||||||
test('can or cannot add someone back into a group', async (t) => { | ||||||||||||||||
const alice = Testbot({ | ||||||||||||||||
keys: ssbKeys.generate(null, 'alice'), | ||||||||||||||||
mfSeed: Buffer.from( | ||||||||||||||||
'000000000000000000000000000000000000000000000000000000000000a1ce', | ||||||||||||||||
'hex' | ||||||||||||||||
), | ||||||||||||||||
}) | ||||||||||||||||
let bob = Testbot({ | ||||||||||||||||
name: 'bobrestart', | ||||||||||||||||
keys: ssbKeys.generate(null, 'bob'), | ||||||||||||||||
mfSeed: Buffer.from( | ||||||||||||||||
'0000000000000000000000000000000000000000000000000000000000000b0b', | ||||||||||||||||
'hex' | ||||||||||||||||
), | ||||||||||||||||
}) | ||||||||||||||||
|
||||||||||||||||
await Promise.all([alice.tribes2.start(), bob.tribes2.start()]) | ||||||||||||||||
|
||||||||||||||||
const bobRoot = await p(bob.metafeeds.findOrCreate)() | ||||||||||||||||
|
||||||||||||||||
await replicate(alice, bob).catch(t.error) | ||||||||||||||||
|
||||||||||||||||
const { id: groupId } = await alice.tribes2 | ||||||||||||||||
.create() | ||||||||||||||||
.catch((err) => t.error(err, 'alice failed to create group')) | ||||||||||||||||
|
||||||||||||||||
await alice.tribes2 | ||||||||||||||||
.addMembers(groupId, [bobRoot.id]) | ||||||||||||||||
.then(() => t.pass('added bob')) | ||||||||||||||||
.catch((err) => t.error(err, 'add bob fail')) | ||||||||||||||||
|
||||||||||||||||
await replicate(alice, bob).catch(t.error) | ||||||||||||||||
|
||||||||||||||||
await bob.tribes2.acceptInvite(groupId) | ||||||||||||||||
|
||||||||||||||||
await replicate(alice, bob).catch(t.error) | ||||||||||||||||
|
||||||||||||||||
await alice.tribes2 | ||||||||||||||||
.excludeMembers(groupId, [bobRoot.id]) | ||||||||||||||||
.then(() => t.pass('alice excluded bob')) | ||||||||||||||||
.catch((err) => t.error(err, 'remove member fail')) | ||||||||||||||||
|
||||||||||||||||
await replicate(alice, bob).catch(t.error) | ||||||||||||||||
|
||||||||||||||||
await alice.tribes2 | ||||||||||||||||
.addMembers(groupId, [bobRoot.id]) | ||||||||||||||||
.then(() => t.pass('added bob back in again')) | ||||||||||||||||
.catch((err) => t.error(err, 'add bob back fail')) | ||||||||||||||||
|
||||||||||||||||
await replicate(alice, bob).catch(t.error) | ||||||||||||||||
|
||||||||||||||||
const invites = await pull(bob.tribes2.listInvites(), pull.collectAsPromise()) | ||||||||||||||||
t.equal(invites.length, 1, 'got a reinvite') | ||||||||||||||||
t.equal(invites[0].id, groupId, 'got invite to correct group') | ||||||||||||||||
await bob.tribes2.acceptInvite(groupId).catch(t.error) | ||||||||||||||||
Powersource marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
|
||||||||||||||||
async function verifyInGroup(peer) { | ||||||||||||||||
const noInvites = await pull( | ||||||||||||||||
bob.tribes2.listInvites(), | ||||||||||||||||
pull.collectAsPromise() | ||||||||||||||||
) | ||||||||||||||||
t.deepEqual(noInvites, [], "we used the invite so there aren't any left") | ||||||||||||||||
|
||||||||||||||||
await peer.tribes2 | ||||||||||||||||
.acceptInvite(groupId) | ||||||||||||||||
.then(() => t.fail('consumed invite twice')) | ||||||||||||||||
.catch(() => t.pass("can't consume invite twice")) | ||||||||||||||||
|
||||||||||||||||
const list = await pull(peer.tribes2.list(), pull.collectAsPromise()) | ||||||||||||||||
t.equal(list.length, 1, 'one group') | ||||||||||||||||
t.equal(list[0].id, groupId, 'id in list is correct') | ||||||||||||||||
|
||||||||||||||||
const group = await bob.tribes2.get(groupId) | ||||||||||||||||
t.notEqual(group.writeKey, undefined, 'bob got writeKey back') | ||||||||||||||||
t.equal(group.excluded, undefined, 'bob is not excluded') | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
await verifyInGroup(bob) | ||||||||||||||||
|
||||||||||||||||
await p(setTimeout)(500) | ||||||||||||||||
await p(bob.close)(true).then(() => t.pass("bob's client was closed")) | ||||||||||||||||
bob = Testbot({ | ||||||||||||||||
rimraf: false, | ||||||||||||||||
name: 'bobrestart', | ||||||||||||||||
keys: ssbKeys.generate(null, 'bob'), | ||||||||||||||||
mfSeed: Buffer.from( | ||||||||||||||||
'0000000000000000000000000000000000000000000000000000000000000b0b', | ||||||||||||||||
'hex' | ||||||||||||||||
), | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extract as
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||||||||||||
}) | ||||||||||||||||
t.pass('bob got a new client') | ||||||||||||||||
await bob.tribes2.start().then(() => t.pass('bob restarted')) | ||||||||||||||||
|
||||||||||||||||
await verifyInGroup(bob) | ||||||||||||||||
Powersource marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
|
||||||||||||||||
await p(alice.close)(true) | ||||||||||||||||
await p(bob.close)(true) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||||||||||||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but you could do it will pull-streams tidily too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just seems slightly more complex?