-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signalements – Revoir le mode d'archivage des alertes "FAR 48h" (#3806)
## Linked issues - Resolve #3733 A exécuter en INTE/PROD : ``` DELETE FROM reportings WHERE value->>'type' == 'MISSING_FAR_48_HOURS_ALERT'; ``` ---- - [ ] Tests E2E (Cypress)
- Loading branch information
Showing
8 changed files
with
197 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
37 changes: 37 additions & 0 deletions
37
frontend/src/features/Reporting/useCases/__tests__/__mocks__/dummyReporting.ts
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,37 @@ | ||
import { Seafront } from '@constants/seafront' | ||
import { PendingAlertValueType } from '@features/Alert/types' | ||
import { ReportingType } from '@features/Reporting/types' | ||
|
||
import { VesselIdentifier } from '../../../../../domain/entities/vessel/types' | ||
|
||
import type { PendingAlertReporting } from '@features/Reporting/types' | ||
|
||
export const fortyHeightHourAlertReporting: PendingAlertReporting = { | ||
creationDate: '2023-10-30T09:10:00Z', | ||
externalReferenceNumber: '', | ||
flagState: 'ES', | ||
id: 12345, | ||
infraction: { | ||
infraction: | ||
'Pêche maritime non autorisée dans les eaux territoriales francaise par capitaine de navire communautaire', | ||
infractionCategory: 'FISHING', | ||
natinfCode: 2610, | ||
regulation: 'ART.L.945-2 §I AL.1, ART.L.945-5 1°,2°,3°,4° C.RUR' | ||
}, | ||
internalReferenceNumber: 'FR04504564', | ||
ircs: '', | ||
isArchived: false, | ||
isDeleted: false, | ||
type: ReportingType.ALERT, | ||
underCharter: null, | ||
validationDate: '2023-10-30T15:08:05.845121Z', | ||
value: { | ||
dml: null, | ||
natinfCode: 2610, | ||
seaFront: Seafront.NAMO, | ||
type: PendingAlertValueType.MISSING_FAR_48_HOURS_ALERT | ||
}, | ||
vesselId: 1234568, | ||
vesselIdentifier: VesselIdentifier.INTERNAL_REFERENCE_NUMBER, | ||
vesselName: 'A VESSEL' | ||
} |
70 changes: 70 additions & 0 deletions
70
frontend/src/features/Reporting/useCases/__tests__/archiveReporting.test.ts
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,70 @@ | ||
import { PendingAlertValueType } from '@features/Alert/types' | ||
import { fortyHeightHourAlertReporting } from '@features/Reporting/useCases/__tests__/__mocks__/dummyReporting' | ||
import { archiveReporting } from '@features/Reporting/useCases/archiveReporting' | ||
import { describe, it, expect, afterAll } from '@jest/globals' | ||
import { mockedDispatch } from '@store/__tests__/utils' | ||
|
||
import { VesselIdentifier } from '../../../../domain/entities/vessel/types' | ||
import { deleteReporting } from '../deleteReporting' | ||
|
||
/** | ||
* Warning: We could not add `jest` import as it makes the test to fail. | ||
* We need to have | ||
* @see: https://github.com/swc-project/jest/issues/14#issuecomment-2525330413 | ||
*/ | ||
|
||
// @ts-ignore | ||
jest.mock('../../reportingApi', () => jest.fn()) | ||
// @ts-ignore | ||
jest.mock('../deleteReporting', () => ({ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
__esModule: true, | ||
// @ts-ignore | ||
deleteReporting: jest.fn() | ||
})) | ||
|
||
describe('archiveReporting()', () => { | ||
const INITIAL_STATE = { | ||
vessel: { | ||
selectedVesselIdentity: { | ||
externalReferenceNumber: '', | ||
flagState: '', | ||
internalReferenceNumber: '', | ||
vesselId: 1234568, | ||
vesselIdentifier: VesselIdentifier.INTERNAL_REFERENCE_NUMBER, | ||
vesselName: '' | ||
} | ||
} | ||
} | ||
|
||
afterAll(() => { | ||
// Reset module registry to clear the mock | ||
// @ts-ignore | ||
jest.resetModules() | ||
}) | ||
|
||
it('Should delete reporting When alert is MISSING_FAR_48_HOURS_ALERT', async () => { | ||
// When | ||
mockedDispatch(archiveReporting(fortyHeightHourAlertReporting), INITIAL_STATE) | ||
|
||
// Then | ||
expect(deleteReporting).toHaveBeenCalled() | ||
}) | ||
|
||
it('Should not delete reporting When the alert is not an MISSING_FAR_48_HOURS_ALERT', async () => { | ||
// Given | ||
const otherAlertReporting = { | ||
...fortyHeightHourAlertReporting, | ||
value: { | ||
...fortyHeightHourAlertReporting.value, | ||
type: PendingAlertValueType.MISSING_FAR_ALERT | ||
} | ||
} | ||
|
||
// When | ||
mockedDispatch(archiveReporting(otherAlertReporting), INITIAL_STATE) | ||
|
||
// Then | ||
expect(deleteReporting).toHaveBeenCalledTimes(0) | ||
}) | ||
}) |
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,22 @@ | ||
import { jest } from '@jest/globals' | ||
|
||
/** | ||
* To be used to capture all dispatched actions. | ||
* | ||
* we could have more middleware functions being called within the | ||
* use-case middleware, and we should be able to capture all of these events. | ||
*/ | ||
export const mockedDispatch = (action, initialState) => { | ||
const store = { | ||
dispatch: jest.fn(fn => { | ||
if (typeof fn === 'function') { | ||
fn(store.dispatch, store.getState) | ||
} | ||
}), | ||
getState: jest.fn(() => initialState) | ||
} | ||
|
||
action(store.dispatch, store.getState) | ||
|
||
return store | ||
} |