Skip to content

Commit

Permalink
feat: Add sourceAccountIdentifier in LauncherContext
Browse files Browse the repository at this point in the history
The update of cozy-client allows to take this sourceAccountIdentifier
into account

The update of cozy-clisk allows to update existing documents with the
correct sourceAccountIdentifier in the correct place in cozyMetadata
  • Loading branch information
doubleface committed Feb 20, 2024
1 parent bfc5a3c commit a1dc3a6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 21 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions src/libs/Launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export default class Launcher {
launcherClient,
...restOfContext
} = startContext
const { sourceAccountIdentifier } = this.getUserData() || {}

if (!account) {
log.debug(
Expand All @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions src/libs/Launcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' } }
Expand Down Expand Up @@ -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',
Expand All @@ -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({
Expand Down Expand Up @@ -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)
Expand Down
40 changes: 32 additions & 8 deletions src/libs/ReactNativeLauncher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -85,6 +88,7 @@ describe('ReactNativeLauncher', () => {
addReferencesTo,
get,
statByPath,
statById,
add
}),
getInstanceOptions: jest.fn().mockReturnValueOnce({ locale: 'fr' })
Expand All @@ -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' }
}))
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -273,6 +296,7 @@ describe('ReactNativeLauncher', () => {
auth: { accountName: 'testsourceaccountidentifier' }
},
trigger: fixtures.trigger,
existingFilesIndex: {},
job: {
_id: 'normal_job_id'
},
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit a1dc3a6

Please sign in to comment.