Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Action & Infraction] Créer un nouvel id pour chaque élément dupliqué #1624

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { createPendingMission } from '../../utils/createPendingMission'
import { getFutureDate } from '../../utils/getFutureDate'

import type { Infraction } from 'domain/entities/missions'
import type { EnvActionControl, Infraction } from 'domain/entities/missions'

context('Side Window > Mission Form > Mission actions', () => {
beforeEach(() => {
Expand Down Expand Up @@ -33,23 +33,25 @@ context('Side Window > Mission Form > Mission actions', () => {
// Then
cy.wait('@updateMission').then(({ request, response }) => {
expect(response && response.statusCode).equal(200)
const { infractions } = request.body.envActions.find(a => a.id === 'b8007c8a-5135-4bc3-816f-c69c7b75d807')
const { infractions }: EnvActionControl = request.body.envActions.find(
a => a.id === 'b8007c8a-5135-4bc3-816f-c69c7b75d807'
)
expect(infractions.length).equal(2)
const duplicatedInfraction = infractions[1]

expect(duplicatedInfraction.controlledPersonIdentity).equal('John Doe')
expect(duplicatedInfraction.formalNotice).equal('PENDING')
expect(duplicatedInfraction.administrativeResponse).equal('PENDING')
expect(duplicatedInfraction.infractionType).equal('WITH_REPORT')
expect(duplicatedInfraction.natinf.length).equal(2)
expect(duplicatedInfraction.observations).equal("Pas d'observations")
expect(duplicatedInfraction.registrationNumber).equal('BALTIK')
expect(duplicatedInfraction.relevantCourt).equal('LOCAL_COURT')
expect(duplicatedInfraction.toProcess).equal(false)
expect(duplicatedInfraction.vesselSize).equal(45)
expect(duplicatedInfraction.vesselType).equal('COMMERCIAL')
expect(duplicatedInfraction.nbTarget).equal(1)
expect(duplicatedInfraction.id).not.equal('b8007c8a-5135-4bc3-816f-c69c7b75d807')
expect(duplicatedInfraction?.controlledPersonIdentity).equal('John Doe')
expect(duplicatedInfraction?.formalNotice).equal('PENDING')
expect(duplicatedInfraction?.administrativeResponse).equal('PENDING')
expect(duplicatedInfraction?.infractionType).equal('WITH_REPORT')
expect(duplicatedInfraction?.natinf?.length).equal(2)
expect(duplicatedInfraction?.observations).equal("Pas d'observations")
expect(duplicatedInfraction?.registrationNumber).equal('BALTIK')
expect(duplicatedInfraction?.relevantCourt).equal('LOCAL_COURT')
expect(duplicatedInfraction?.toProcess).equal(false)
expect(duplicatedInfraction?.vesselSize).equal(45)
expect(duplicatedInfraction?.vesselType).equal('COMMERCIAL')
expect(duplicatedInfraction?.nbTarget).equal(1)
expect(duplicatedInfraction?.id).not.equal(infractions[0]?.id)
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const NewInfractionSchema: Yup.SchemaOf<Infraction> = Yup.object().shape(
if (!actionNumberOfControls) {
return false
}

const unselectedInfractionNumber = infractions
.filter(infraction => infraction.id !== currentInfractionId)
.reduce((sumNbTarget, infraction) => sumNbTarget + infraction.nbTarget, 0)
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/features/missions/Missions.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ import type { AtLeast } from '../../types'

export const infractionFactory = (infraction?: Partial<Infraction>): NewInfraction => ({
administrativeResponse: 'NONE',
id: uuidv4(),
natinf: [],
nbTarget: 1,
observations: '',
toProcess: false,
...infraction
...infraction,
id: uuidv4()
})

export const actionFactory = ({
Expand All @@ -61,11 +61,11 @@ export const actionFactory = ({
}
],

id: uuidv4(),
infractions: [],
observations: '',
reportingIds: [],
...action
...action,
id: uuidv4()
} as NewEnvActionControl
case ActionTypeEnum.NOTE:
return {
Expand Down