Skip to content

Commit

Permalink
feat: Add shouldFullSync UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
KillianCourvoisier committed Jul 26, 2024
1 parent 7a573d4 commit df6ba20
Showing 1 changed file with 86 additions and 1 deletion.
87 changes: 86 additions & 1 deletion packages/cozy-clisk/src/contentscript/ContentScript.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ describe('ContentScript', () => {
)
})
})

describe('runInWorkerUntilTrue', () => {
const contentScript = new ContentScript()
contentScript.contentScriptType = PILOT_TYPE
Expand Down Expand Up @@ -200,4 +199,90 @@ describe('ContentScript', () => {
).rejects.toThrow('Timeout error')
})
})
describe('shouldFullSync', () => {
it('should force full sync => Flag', async () => {
const contentScript = new ContentScript()
contentScript.contentScriptType = PILOT_TYPE

const options = {
flags: {
'clisk.force-full-sync': true
},
trigger: {
current_state: {
last_execution: '2024-07-24T14:55:57.83761233+02:00',
last_failure: '2024-07-23T14:55:57.83761233+02:00',
last_success: '2024-07-24T14:55:57.83761233+02:00'
}
}
}
const result = await contentScript.shouldFullSync(options)
expect(result).toEqual({
forceFullSync: true,
distanceInDays: 0
})
})
it('should force full sync => First execution', async () => {
const contentScript = new ContentScript()
contentScript.contentScriptType = PILOT_TYPE

const options = {
flags: {
'clisk.force-full-sync': false
},
trigger: {
current_state: {}
}
}
const result = await contentScript.shouldFullSync(options)
expect(result).toEqual({
forceFullSync: true,
distanceInDays: 0
})
})
it('should force full sync => Last execution failed', async () => {
const contentScript = new ContentScript()
contentScript.contentScriptType = PILOT_TYPE

const options = {
flags: {
'clisk.force-full-sync': false
},
trigger: {
current_state: {
last_execution: '2024-07-24T14:55:57.83761233+02:00',
last_failure: '2024-07-24T14:55:57.83761233+02:00',
last_success: '2024-07-23T14:55:57.83761233+02:00'
}
}
}
const result = await contentScript.shouldFullSync(options)
expect(result).toEqual({
forceFullSync: true,
distanceInDays: 0
})
})
it('should not force full sync', async () => {
const contentScript = new ContentScript()
contentScript.contentScriptType = PILOT_TYPE

const options = {
flags: {
'clisk.force-full-sync': false
},
trigger: {
current_state: {
last_execution: '2024-07-24T14:55:57.83761233+02:00',
last_failure: '2024-07-23T14:55:57.83761233+02:00',
last_success: '2024-07-24T14:55:57.83761233+02:00'
}
}
}
const result = await contentScript.shouldFullSync(options)
expect(result).toEqual({
forceFullSync: false,
distanceInDays: 0
})
})
})
})

0 comments on commit df6ba20

Please sign in to comment.