-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fc98d9
commit 2d52db0
Showing
18 changed files
with
606 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import nock from 'nock'; | ||
|
||
import { TargetModes } from '@/models/questionnaires'; | ||
|
||
import { | ||
type Questionnaire as PoguesQuestionnaire, | ||
SurveyModeEnum, | ||
} from './models/pogues'; | ||
import { | ||
getQuestionnaire, | ||
getQuestionnaires, | ||
postQuestionnaire, | ||
putQuestionnaire, | ||
} from './questionnaires'; | ||
|
||
vi.mock('@/contexts/oidc'); | ||
|
||
const poguesQuestionnaire = { | ||
id: 'id', | ||
Name: 'name', | ||
Label: ['title'], | ||
TargetMode: [SurveyModeEnum.CAPI], | ||
DataCollection: [], | ||
lastUpdatedDate: | ||
'Tue Nov 19 2024 11:36:56 GMT+0100 (heure normale d’Europe centrale)', | ||
}; | ||
|
||
const questionnaire = { | ||
id: 'id', | ||
title: 'title', | ||
targetModes: new Set([TargetModes.CAPI]), | ||
lastUpdatedDate: new Date('2024-11-19T10:36:56Z'), | ||
codesLists: [], | ||
}; | ||
|
||
it('Get questionnaires works', async () => { | ||
const questionnaires: PoguesQuestionnaire[] = [poguesQuestionnaire]; | ||
|
||
nock('https://mock-api') | ||
.get('/persistence/questionnaires/search/meta?owner=my-stamp') | ||
.reply(200, questionnaires); | ||
|
||
const res = await getQuestionnaires('my-stamp'); | ||
expect(res).toEqual([questionnaire]); | ||
}); | ||
|
||
it('Get questionnaire works', async () => { | ||
nock('https://mock-api') | ||
.get('/persistence/questionnaire/id') | ||
.reply(200, poguesQuestionnaire); | ||
|
||
const res = await getQuestionnaire('id'); | ||
expect(res).toEqual(questionnaire); | ||
}); | ||
|
||
it('Post questionnaire works', async () => { | ||
nock('https://mock-api').post('/persistence/questionnaires').reply(201); | ||
|
||
const res = await postQuestionnaire(questionnaire, 'my-stamp'); | ||
expect(res.status).toEqual(201); | ||
}); | ||
|
||
it('Put questionnaire works', async () => { | ||
nock('https://mock-api').put('/persistence/questionnaire/id').reply(200); | ||
|
||
const res = await putQuestionnaire('id', poguesQuestionnaire); | ||
expect(res.status).toEqual(200); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import nock from 'nock'; | ||
|
||
import { getStamps } from './stamps'; | ||
|
||
vi.mock('@/contexts/oidc'); | ||
|
||
it('Get stamps', async () => { | ||
const stamps = [{ label: 'my-stamp', value: 'stamp-1' }]; | ||
|
||
nock('https://mock-api') | ||
.get('/persistence/questionnaires/stamps') | ||
.reply(200, stamps); | ||
|
||
const res = await getStamps(); | ||
expect(res).toEqual(stamps); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { CodesList } from '@/models/codesLists'; | ||
|
||
import { CodeList as PoguesCodesList } from '../models/pogues'; | ||
import { computeCodesLists, computePoguesCodesLists } from './codesLists'; | ||
|
||
const codesLists: CodesList[] = [ | ||
{ | ||
id: 'id-1', | ||
label: 'label-1', | ||
codes: [ | ||
{ label: 'code-1', value: 'code-value-1' }, | ||
{ label: 'code-2', value: 'code-value-2' }, | ||
], | ||
}, | ||
]; | ||
|
||
const poguesCodesLists: PoguesCodesList[] = [ | ||
{ | ||
id: 'id-1', | ||
Name: 'label-1', | ||
Label: 'label-1', | ||
Code: [ | ||
{ Label: 'code-1', Value: 'code-value-1' }, | ||
{ Label: 'code-2', Value: 'code-value-2' }, | ||
], | ||
}, | ||
]; | ||
|
||
describe('computeCodesLists', () => { | ||
it('works', () => { | ||
expect(computeCodesLists(poguesCodesLists)).toEqual(codesLists); | ||
}); | ||
it('works with empty list', () => { | ||
expect(computeCodesLists([])).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('computePoguesCodesLists', () => { | ||
it('works', () => { | ||
expect(computePoguesCodesLists(codesLists)).toEqual(poguesCodesLists); | ||
}); | ||
it('works with empty list', () => { | ||
expect(computeCodesLists([])).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { FlowLogics } from '@/models/questionnaires'; | ||
|
||
import { FlowLogicEnum } from '../models/pogues'; | ||
import { computePoguesFlowLogic } from './flowLogic'; | ||
|
||
describe('computePoguesFlowLogic', () => { | ||
it.each([ | ||
[FlowLogics.Filter, FlowLogicEnum.Filter], | ||
[FlowLogics.Redirection, FlowLogicEnum.Redirection], | ||
])('%s -> %s', (input, expected) => { | ||
expect(computePoguesFlowLogic(input)).toEqual(expected); | ||
}); | ||
|
||
it('works with default', () => { | ||
expect(computePoguesFlowLogic()).toEqual(FlowLogicEnum.Filter); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { FlowLogics } from '@/models/questionnaires'; | ||
|
||
import { FlowLogicEnum } from '../models/pogues'; | ||
|
||
export function computePoguesFlowLogic(flowLogic?: FlowLogics): FlowLogicEnum { | ||
switch (flowLogic) { | ||
case FlowLogics.Redirection: | ||
return FlowLogicEnum.Redirection; | ||
case FlowLogics.Filter: | ||
default: | ||
return FlowLogicEnum.Filter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { FormulasLanguages } from '@/models/questionnaires'; | ||
|
||
import { FormulasLanguageEnum } from '../models/pogues'; | ||
import { computePoguesFormulasLanguage } from './formulasLanguage'; | ||
|
||
describe('computePoguesFormulasLanguage', () => { | ||
it.each([ | ||
[FormulasLanguages.VTL, FormulasLanguageEnum.VTL], | ||
[FormulasLanguages.XPath, FormulasLanguageEnum.XPath], | ||
])('%s -> %s', (input, expected) => { | ||
expect(computePoguesFormulasLanguage(input)).toEqual(expected); | ||
}); | ||
|
||
it('works with default', () => { | ||
expect(computePoguesFormulasLanguage()).toEqual(FormulasLanguageEnum.VTL); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { FormulasLanguages } from '@/models/questionnaires'; | ||
|
||
import { FormulasLanguageEnum } from '../models/pogues'; | ||
|
||
export function computePoguesFormulasLanguage( | ||
formulasLanguage?: FormulasLanguages, | ||
): FormulasLanguageEnum { | ||
switch (formulasLanguage) { | ||
case FormulasLanguages.XPath: | ||
return FormulasLanguageEnum.XPath; | ||
case FormulasLanguages.VTL: | ||
default: | ||
return FormulasLanguageEnum.VTL; | ||
} | ||
} |
Oops, something went wrong.