diff --git a/test/lib/stack-client/stack-client.init.spec.js b/test/lib/stack-client/stack-client.init.spec.js index 88be8f0da..d5a731e68 100644 --- a/test/lib/stack-client/stack-client.init.spec.js +++ b/test/lib/stack-client/stack-client.init.spec.js @@ -10,16 +10,24 @@ const { init } = stack describe('stack client', () => { describe('init', () => { - let cozyClient = new CozyClient({ - stackClient: { + let cozyClient, params + + const setup = async({ isLogged, isPublic }) => { + if (isLogged === undefined) { + throw new Error("Please define explicity isLogged in your tests.") + } + cozyClient = new CozyClient({ token: { token: 'mytoken' }, uri: 'https://test.mycozy.cloud' + }) + cozyClient.isLogged = isLogged + params = { + cozyClient, + isPublic, + onCreate: function() {}, + onDelete: function() {} } - }) - let params = { - cozyClient, - onCreate: function() {}, - onDelete: function() {} + await init(params) } beforeAll(async () => { @@ -31,44 +39,24 @@ describe('stack client', () => { }) it('should not called internal client', async () => { - await init(params) + await setup({ isLogged: false }) expect(internal.init).not.toHaveBeenCalled() }) it('should not have initialized the realtime if the user is not logged', async () => { - await init({ - ...params, - cozyClient: { - ...cozyClient, - isLogged: false - } - }) + await setup({ isLogged: false }) expect(initializeRealtime).toHaveBeenCalledTimes(0) }) it('should not have initialized the realtime if the user is not logged even if isPublic is set to false', async () => { - await init({ - ...params, - isPublic: false, - cozyClient: { - ...cozyClient, - isLogged: false - } - }) + await setup({ isLogged: false, isPublic: false}) expect(initializeRealtime).toHaveBeenCalledTimes(0) }) it('should have initialized the realtime is the user is logged', async () => { - const client = { - ...cozyClient, - isLogged: true - } - await init({ - ...params, - cozyClient: client - }) + await setup({ isLogged: true }) expect(initializeRealtime).toHaveBeenCalled() - expect(initializeRealtime.mock.calls[0][0].cozyClient).toBe(client) + expect(initializeRealtime.mock.calls[0][0].cozyClient).toBe(cozyClient) }) }) })