-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1007 from InseeFr/fix/sims
fix: add unit test
- Loading branch information
Showing
2 changed files
with
113 additions
and
13 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
83 changes: 83 additions & 0 deletions
83
src/packages/modules-operations/msd/pages/sims-creation/index.spec.tsx
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,83 @@ | ||
import { vi, expect, describe, it, beforeEach, Mock } from 'vitest'; | ||
import { generateSimsBeforeSubmit } from './index'; | ||
import * as utils from '../../utils'; | ||
|
||
describe('generateSimsBeforeSubmit', () => { | ||
beforeEach(() => { | ||
vi.mock('../../utils', () => ({ | ||
getParentIdName: vi.fn(), | ||
})); | ||
}); | ||
|
||
it('should generate the correct payload for CREATE mode', () => { | ||
(utils.getParentIdName as Mock).mockReturnValue('parentId'); | ||
|
||
const result = generateSimsBeforeSubmit( | ||
'CREATE', | ||
{ | ||
id: '123', | ||
labelLg1: 'Label 1', | ||
labelLg2: 'Label 2', | ||
created: '2023-01-01', | ||
}, | ||
'operation', | ||
'parent123', | ||
{ rubric1: 'value1' }, | ||
); | ||
|
||
expect(result).toEqual({ | ||
id: '123', | ||
labelLg1: 'Label 1', | ||
labelLg2: 'Label 2', | ||
parentId: 'parent123', | ||
created: '2023-01-01', | ||
rubrics: { rubric1: 'value1' }, | ||
}); | ||
}); | ||
|
||
it('should generate the correct payload for DUPLICATE mode', () => { | ||
(utils.getParentIdName as Mock).mockReturnValue('parentId'); | ||
|
||
const result = generateSimsBeforeSubmit( | ||
'DUPLICATE', | ||
{ | ||
id: '123', | ||
labelLg1: 'Label 1', | ||
labelLg2: 'Label 2', | ||
created: '2023-01-01', | ||
}, | ||
'series', | ||
'parent456', | ||
{ rubric2: 'value2' }, | ||
); | ||
|
||
expect(result).toEqual({ | ||
id: '', | ||
labelLg1: '', | ||
labelLg2: '', | ||
parentId: 'parent456', | ||
created: '', | ||
rubrics: { rubric2: 'value2' }, | ||
}); | ||
}); | ||
|
||
it('should use the correct parent ID name based on parent type', () => { | ||
(utils.getParentIdName as Mock).mockReturnValue('idOperation'); | ||
|
||
const result = generateSimsBeforeSubmit( | ||
'UPDATE', | ||
{ | ||
id: '123', | ||
labelLg1: 'Label 1', | ||
labelLg2: 'Label 2', | ||
created: '2023-01-01', | ||
}, | ||
'indicator', | ||
'parent789', | ||
{ rubric3: 'value3' }, | ||
); | ||
|
||
expect(result.idOperation).toBe('parent789'); | ||
expect(utils.getParentIdName).toHaveBeenCalledWith('indicator'); | ||
}); | ||
}); |