diff --git a/package.json b/package.json index 9be10e88c..078934b69 100644 --- a/package.json +++ b/package.json @@ -52,8 +52,8 @@ "@sentry/integrations": "7.81.1", "@sentry/react-native": "5.16.0", "base-64": "^1.0.0", - "cozy-client": "^45.7.0", - "cozy-clisk": "^0.33.1", + "cozy-client": "^45.12.0", + "cozy-clisk": "^0.34.0", "cozy-device-helper": "^2.7.0", "cozy-flags": "^3.2.0", "cozy-intent": "^2.19.0", diff --git a/src/libs/Launcher.js b/src/libs/Launcher.js index 82f1b4082..5b9da173d 100644 --- a/src/libs/Launcher.js +++ b/src/libs/Launcher.js @@ -249,6 +249,7 @@ export default class Launcher { launcherClient, ...restOfContext } = startContext + const { sourceAccountIdentifier } = this.getUserData() || {} if (!account) { log.debug( @@ -270,6 +271,11 @@ export default class Launcher { launcherClient.setAppMetadata({ sourceAccount: account._id }) + if (sourceAccountIdentifier) { + launcherClient.setAppMetadata({ + sourceAccountIdentifier + }) + } const folder = await models.konnectorFolder.ensureKonnectorFolder(client, { konnector: { ...konnector, _id: konnector.id }, // _id attribute is missing in konnector object, which causes the reference to the konnector in the destination folder to be null account, diff --git a/src/libs/Launcher.spec.js b/src/libs/Launcher.spec.js index d6f444203..84027d210 100644 --- a/src/libs/Launcher.spec.js +++ b/src/libs/Launcher.spec.js @@ -43,6 +43,10 @@ describe('Launcher', () => { _id: 'createdfolderid' } }), + query: jest.fn().mockResolvedValue({ included: [] }), + get: jest.fn().mockResolvedValue({ data: {} }), + statById: jest.fn().mockResolvedValue({ data: {} }), + ensureDirectoryExists: jest.fn(), getInstanceOptions: jest.fn().mockReturnValueOnce({ locale: 'fr' }), save: jest.fn().mockResolvedValueOnce({ data: { message: { folder_to_save: 'newfolderid' } } @@ -326,7 +330,10 @@ describe('Launcher', () => { findReferencedBy: jest .fn() .mockResolvedValue({ included: existingMagicFolder }), - getInstanceOptions: jest.fn().mockReturnValue(() => ({ locale: 'fr' })), + getInstanceOptions: jest.fn().mockReturnValue({ locale: 'fr' }), + ensureDirectoryExists: jest.fn(), + get: jest.fn().mockResolvedValue({ data: {} }), + statById: jest.fn().mockResolvedValue({ data: {} }), queryAll: jest.fn().mockResolvedValue([ { _id: 'tokeep', @@ -338,7 +345,9 @@ describe('Launcher', () => { _id: 'toignore' } ]), - query: jest.fn().mockResolvedValue({ data: { path: 'folderPath' } }), + query: jest + .fn() + .mockResolvedValue({ data: { path: 'folderPath' }, included: [] }), save: jest.fn().mockImplementation(() => ({ _id: 'triggerid' })) } launcher.setStartContext({ @@ -390,7 +399,7 @@ describe('Launcher', () => { _type: 'io.cozy.triggers', message: { account: 'testaccountid', - folder_to_save: '/Administratif/Test Konnector/testaccountid' + folder_to_save: '/Administrative/Test Konnector/testaccountid' } }) expect(client.queryAll).toHaveBeenCalledTimes(2) diff --git a/src/libs/ReactNativeLauncher.spec.js b/src/libs/ReactNativeLauncher.spec.js index 508d0170f..6ffc3e097 100644 --- a/src/libs/ReactNativeLauncher.spec.js +++ b/src/libs/ReactNativeLauncher.spec.js @@ -68,6 +68,9 @@ describe('ReactNativeLauncher', () => { const statByPath = jest .fn() .mockResolvedValue({ data: { _id: 'testfolderid' } }) + const statById = jest + .fn() + .mockResolvedValue({ data: { _id: 'testfolderid' } }) const add = jest.fn() const client = { save: jest.fn(), @@ -85,6 +88,7 @@ describe('ReactNativeLauncher', () => { addReferencesTo, get, statByPath, + statById, add }), getInstanceOptions: jest.fn().mockReturnValueOnce({ locale: 'fr' }) @@ -109,15 +113,22 @@ describe('ReactNativeLauncher', () => { describe('start', () => { it('should ensure account and trigger', async () => { const { launcher, client, launch } = setup() + const konnector = { + slug: 'konnectorslug', + clientSide: true, + permissions: { files: { type: 'io.cozy.files' } } + } launcher.setStartContext({ client, - konnector: { slug: 'konnectorslug', clientSide: true }, + konnector, + manifest: konnector, launcherClient: { setAppMetadata: () => null } }) launch.mockResolvedValue({ data: fixtures.job }) - client.query.mockResolvedValue({ data: fixtures.account }) + client.query.mockResolvedValue({ data: fixtures.account, included: [] }) + client.queryAll.mockResolvedValue([]) client.save.mockImplementation(async doc => ({ data: { ...doc, _id: doc._id ? doc._id : 'newid' } })) @@ -168,17 +179,24 @@ describe('ReactNativeLauncher', () => { }) it('should launch the given trigger if any', async () => { const { launcher, client, launch } = setup() + const konnector = { + slug: 'konnectorslug', + clientSide: true, + permissions: { files: { type: 'io.cozy.files' } } + } launcher.setStartContext({ client, account: fixtures.account, trigger: fixtures.trigger, - konnector: { slug: 'konnectorslug', clientSide: true }, + konnector, + manifest: konnector, launcherClient: { setAppMetadata: () => null } }) launch.mockResolvedValue({ data: fixtures.job }) - client.query.mockResolvedValue({ data: fixtures.account }) + client.query.mockResolvedValue({ data: fixtures.account, included: [] }) + client.queryAll.mockResolvedValue([]) client.save.mockImplementation(async doc => ({ data: doc })) launcher.pilot.call .mockResolvedValueOnce(true) @@ -191,7 +209,11 @@ describe('ReactNativeLauncher', () => { }) it('should work normaly in nominal case', async () => { const { launcher, client, launch } = setup() - const konnector = { slug: 'konnectorslug', clientSide: true } + const konnector = { + slug: 'konnectorslug', + clientSide: true, + permissions: { files: { type: 'io.cozy.files' } } + } launcher.setStartContext({ client, account: fixtures.account, @@ -202,7 +224,8 @@ describe('ReactNativeLauncher', () => { setAppMetadata: () => null } }) - client.query.mockResolvedValue({ data: fixtures.account }) + client.query.mockResolvedValue({ data: fixtures.account, included: [] }) + client.queryAll.mockResolvedValue([]) client.save.mockImplementation(async doc => ({ data: doc })) launch.mockResolvedValue({ data: fixtures.job }) launcher.pilot.call @@ -273,6 +296,7 @@ describe('ReactNativeLauncher', () => { auth: { accountName: 'testsourceaccountidentifier' } }, trigger: fixtures.trigger, + existingFilesIndex: {}, job: { _id: 'normal_job_id' }, @@ -326,7 +350,7 @@ describe('ReactNativeLauncher', () => { setAppMetadata: () => null } }) - client.query.mockResolvedValue({ data: fixtures.account }) + client.query.mockResolvedValue({ data: fixtures.account, included: [] }) client.queryAll.mockResolvedValueOnce([ { name: 'file1.txt', @@ -370,7 +394,7 @@ describe('ReactNativeLauncher', () => { setAppMetadata: () => null } }) - client.query.mockResolvedValue({ data: fixtures.account }) + client.query.mockResolvedValue({ data: fixtures.account, included: [] }) client.save.mockImplementation(async doc => ({ data: doc })) launch.mockResolvedValue({ data: fixtures.job }) launcher.pilot.call diff --git a/yarn.lock b/yarn.lock index 95ec943e7..0829b5e63 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7944,10 +7944,10 @@ cosmiconfig@^7.0.1: path-type "^4.0.0" yaml "^1.10.0" -cozy-client@^45.7.0: - version "45.7.0" - resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-45.7.0.tgz#6ae92a4e84454c40da92749222d5b8b7e8f592ff" - integrity sha512-UrMuSk9cg6OJ5MXp1DAmIMgIxNKPP9dvjBuwITZTFHxkGvpTtA082LSDosMNiFrrc2W3+weCg1ExNF43I1N1Vg== +cozy-client@^45.12.0: + version "45.12.0" + resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-45.12.0.tgz#e550c86a5b5fc430fec71ebba43c7ba1cd58c0db" + integrity sha512-Vic8k6f6LKY1AJt0rMLe1AHX51kB3ROYsXnpj7JduUa3Tise1Y/9iCQfWmWMVdSicFtmEeZXqt0Z/ot3gt0W4A== dependencies: "@cozy/minilog" "1.0.0" "@types/jest" "^26.0.20" @@ -7969,10 +7969,10 @@ cozy-client@^45.7.0: sift "^6.0.0" url-search-params-polyfill "^8.0.0" -cozy-clisk@^0.33.1: - version "0.33.1" - resolved "https://registry.yarnpkg.com/cozy-clisk/-/cozy-clisk-0.33.1.tgz#78ff85abf7e2be95f035eedd259868fd1a8b3c5e" - integrity sha512-DbekMYZSG9i1p1IoB4gna4Ai51IKNgzoZdjjqcSE9DrenUMdq22qSOPCTfuCEXOSlQTfBqmAW1TQepgePkepaw== +cozy-clisk@^0.34.0: + version "0.34.0" + resolved "https://registry.yarnpkg.com/cozy-clisk/-/cozy-clisk-0.34.0.tgz#3fc513aca95ea1b77fa2592ec376a69fa9c822fa" + integrity sha512-C6qu/pkQvFI+v4yC3Qt5PJviAA+L7ZXlmNPjhD1lT4Mt5UU9Zu5YFdlsCq5lULRBzzqbwQ4hfzAf5Vi9UP7j9w== dependencies: "@cozy/minilog" "^1.0.0" bluebird-retry "^0.11.0"