Skip to content

Commit

Permalink
feat: Return flags with values and adapt TUs
Browse files Browse the repository at this point in the history
  • Loading branch information
KillianCourvoisier committed Jun 13, 2024
1 parent 0564482 commit cea0390
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
15 changes: 12 additions & 3 deletions src/libs/ReactNativeLauncher.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { sendKonnectorsLogs } from '/libs/konnectors/sendKonnectorsLogs'

import { wrapTimerFactory } from 'cozy-clisk'
import flag from 'cozy-flags'
import { listFlags } from 'cozy-flags/dist/flag'
import { listFlags, initialize } from 'cozy-flags/dist/flag'

import {
activateKeepAwake,
Expand Down Expand Up @@ -289,11 +289,12 @@ class ReactNativeLauncher extends Launcher {
}

async _start({ initKonnectorError } = {}) {
const { account: prevAccount, konnector, client } = this.getStartContext()
await initialize(client)
if (flag('clisk.html-on-error')) {
Minilog.pipe(Minilog.backends.array)
}
activateKeepAwake('clisk')
const { account: prevAccount, konnector } = this.getStartContext()
try {
if (initKonnectorError) {
log.info('Got initKonnectorError ' + initKonnectorError.message)
Expand Down Expand Up @@ -341,13 +342,21 @@ class ReactNativeLauncher extends Launcher {
const { account, trigger, job, manifest } = this.getStartContext()
const { sourceAccountIdentifier } = this.getUserData()
const cozyFlags = listFlags()
const flagsWithValues = {}
if (cozyFlags) {
for (const cozyFlag of cozyFlags) {
if (cozyFlag.startsWith('clisk')) {
flagsWithValues[cozyFlag] = flag(cozyFlag)
}
}
}
const pilotContext = {
manifest,
account,
trigger,
job,
sourceAccountIdentifier,
flags: cozyFlags
flags: flagsWithValues
}

if (hasPermission(manifest, 'io.cozy.files')) {
Expand Down
17 changes: 10 additions & 7 deletions src/libs/ReactNativeLauncher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jest.mock('./keychain', () => {
removeCredential: jest.fn()
}
})
jest.mock('cozy-flags', () => {
return {}
})
import CookieManager from '@react-native-cookies/cookies'
import { waitFor } from '@testing-library/react-native'

Expand Down Expand Up @@ -220,7 +223,7 @@ describe('ReactNativeLauncher', () => {
trigger: fixtures.trigger,
konnector,
manifest: konnector,
flags: [],
flags: {},
launcherClient: {
setAppMetadata: () => null
}
Expand Down Expand Up @@ -303,7 +306,7 @@ describe('ReactNativeLauncher', () => {
},
sourceAccountIdentifier: 'testsourceaccountidentifier',
manifest: konnector,
flags: []
flags: {}
})
expect(launcher.pilot.call).not.toHaveBeenCalledWith(
'ensureNotAuthenticated'
Expand All @@ -321,7 +324,7 @@ describe('ReactNativeLauncher', () => {
trigger: fixtures.trigger,
konnector,
manifest: konnector,
flags: [],
flags: {},
launcherClient: {
setAppMetadata: () => null
}
Expand Down Expand Up @@ -349,7 +352,7 @@ describe('ReactNativeLauncher', () => {
slug: 'testkonnector',
name: 'Test Konnector'
},
flags: [],
flags: {},
launcherClient: {
setAppMetadata: () => null
}
Expand Down Expand Up @@ -394,7 +397,7 @@ describe('ReactNativeLauncher', () => {
slug: 'testkonnector',
name: 'Test Konnector'
},
flags: [],
flags: {},
launcherClient: {
setAppMetadata: () => null
}
Expand Down Expand Up @@ -489,7 +492,7 @@ describe('ReactNativeLauncher', () => {
account: fixtures.account,
trigger: fixtures.trigger,
konnector: { slug: 'konnectorslug', clientSide: true },
flags: [],
flags: {},
launcherClient: {
setAppMetadata: () => null
}
Expand Down Expand Up @@ -532,7 +535,7 @@ describe('ReactNativeLauncher', () => {
account: fixtures.account,
trigger: fixtures.trigger,
konnector: { slug: 'konnectorslug', clientSide: true },
flags: [],
flags: {},
launcherClient: {
setAppMetadata: () => null
}
Expand Down

0 comments on commit cea0390

Please sign in to comment.