diff --git a/src/lib/stack-client.js b/src/lib/stack-client.js index 890d5b852..208458af2 100644 --- a/src/lib/stack-client.js +++ b/src/lib/stack-client.js @@ -1,8 +1,8 @@ /* global __TARGET__ */ /* eslint-env browser */ -import internal from 'lib/stack-internal.js' import getIcon from 'lib/icon' +import initializeRealtime from 'lib/realtime' import { ForbiddenException, @@ -335,20 +335,23 @@ const cozyFetchJSON = function(cozy, method, path, body) { * @param {Function} arg.onDeleteApp * @returns {Promise} */ -const init = function(options) { - cozyClient = options.cozyClient - const legacyOptions = { - ...options, - cozyURL: getCozyURLOrigin(), - token: getStackClient().token.token - } - return internal.init(legacyOptions) +const init = function({ + cozyClient: client, + onCreateApp, + onDeleteApp +}) { + cozyClient = client + return initializeRealtime({ + getApp, + onCreateApp, + onDeleteApp, + token: getStackClient().token.token, + url: getCozyURLOrigin(), + }) } export default { - ...internal, get: { - ...internal.get, app: getApp, apps: getApps, context: withCache(getContext, {}), diff --git a/test/lib/stack-client/stack-client.init.spec.js b/test/lib/stack-client/stack-client.init.spec.js index c8b5ca365..30bf741c0 100644 --- a/test/lib/stack-client/stack-client.init.spec.js +++ b/test/lib/stack-client/stack-client.init.spec.js @@ -1,6 +1,10 @@ import stack from 'lib/stack-client' import internal from 'lib/stack-internal' +import initializeRealtime from 'lib/realtime' + +jest.mock('lib/realtime'); +initializeRealtime.mockResolvedValue(Promise.resolve()) const { init, @@ -33,23 +37,15 @@ describe("stack client", () => { jest.restoreAllMocks() }) - it("should called internal client", () => { - expect( internal.init ).toHaveBeenCalled() - }) - - it("should have set the cozy-client token", () => { - expect( internal.init.mock.calls[0][0].token ).toBe("mytoken") + it("should not called internal client", () => { + expect( internal.init ).not.toHaveBeenCalled() }) - it("should have set the cozy-client uri", () => { - expect( internal.init.mock.calls[0][0].cozyURL ).toBe("https://test.mycozy.cloud") + it("should have initialized the realtime", () => { + expect( initializeRealtime ).toHaveBeenCalled() + expect( initializeRealtime.mock.calls[0][0].token ).toBe("mytoken") + expect( initializeRealtime.mock.calls[0][0].url ).toBe("https://test.mycozy.cloud") }) - - it("should pass onCreateApp and onDeleteApp functions", () => { - expect( internal.init.mock.calls[0][0].onDeleteApp ).toBeInstanceOf(Function) - expect( internal.init.mock.calls[0][0].onCreateApp ).toBeInstanceOf(Function) - }) - }) }) \ No newline at end of file