From 9d342a460ca4ede4a5a2403843e0a1e6a5c10b1e Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 23 Sep 2021 16:35:30 -0400 Subject: [PATCH] Test for reliably auth info across reforges --- utils/GunSmith/GunSmith.spec.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/utils/GunSmith/GunSmith.spec.js b/utils/GunSmith/GunSmith.spec.js index 5dca306d..4b97340a 100644 --- a/utils/GunSmith/GunSmith.spec.js +++ b/utils/GunSmith/GunSmith.spec.js @@ -434,14 +434,18 @@ describe('gun smith', () => { const alias = words() const pass = words() + jest.setTimeout(20000) + it('provides an user node with create(), auth() and leave()', async done => { - expect.assertions(6) + expect.assertions(7) await whenReady() const ack = await new Promise(res => user.create(alias, pass, res)) expect(ack.err).toBeUndefined() const { pub } = ack + // eslint-disable-next-line jest/no-truthy-falsy + expect(pub).toBeTruthy() expect(user.is?.pub).toEqual(pub) user.leave() @@ -458,6 +462,28 @@ describe('gun smith', () => { done() release() }) + + it('reliably provides authentication information across re-forges', async done => { + expect.assertions(3) + await whenReady() + + /** @type {GunT.AuthAck} */ + const authAck = await new Promise(res => + user.auth(alias, pass, ack => res(ack)) + ) + const pub = authAck.sea?.pub + // eslint-disable-next-line jest/no-truthy-falsy + expect(pub).toBeTruthy() + + Gun._reforge() + expect(user.is?.pub).toEqual(pub) + await Gun._isReady() + expect(user.is?.pub).toEqual(pub) + + user.leave() + done() + release() + }) }) it('provides thenables for values', async done => {