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

[Missions] Correction du l'écriture de mission_source #2470

Merged
merged 3 commits into from
Sep 1, 2023
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 @@ -207,7 +207,7 @@ context('Side Window > Mission Form > Main Form', () => {
id: 2,
isClosed: false,
isGeometryComputedFromControls: false,
missionSource: 'MONITORFISH',
missionSource: 'POSEIDON_CNSP',
missionTypes: ['SEA'],
observationsCacem:
'Maybe own each college away likely major. Former space technology million cell. Outside body my drop require.',
Expand Down Expand Up @@ -444,7 +444,7 @@ context('Side Window > Mission Form > Main Form', () => {
id: 6,
isClosed: false,
isGeometryComputedFromControls: false,
missionSource: 'MONITORFISH',
missionSource: 'POSEIDON_CNSP',
missionTypes: ['AIR'],
observationsCacem: 'Toward agency blue now hand. Meet answer someone stand.',
observationsCnsp: null,
Expand Down
21 changes: 12 additions & 9 deletions frontend/src/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ import type { Self } from '../domain/types/env'
*/
export function getEnvironmentVariable(name: string) {
// eslint-disable-next-line no-restricted-globals
const injectedValue = (self as Self).env[name]
if (injectedValue !== `__${name}__`) {
if (injectedValue === 'true') {
return true
}
if ((self as Self).env) {
// eslint-disable-next-line no-restricted-globals
const injectedValue = (self as Self).env[name]
if (injectedValue !== `__${name}__`) {
if (injectedValue === 'true') {
return true
}

if (injectedValue === 'false') {
return false
}
if (injectedValue === 'false') {
return false
}

return injectedValue
return injectedValue
}
}

const valueFromProcess = process.env[name]
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/features/SideWindow/MissionForm/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,13 @@ export function getMissionDataFromMissionFormValues(
const missionBaseValues = omit(['controlUnits'], mainFormValues)

const validControlUnits = mainFormValues.controlUnits.map(getValidMissionDataControlUnit)
const missionSource = Mission.MissionSource.MONITORFISH
const missionTypes = mainFormValues.missionTypes || []

return {
...missionBaseValues,
controlUnits: validControlUnits,
isClosed: mustClose || !!missionBaseValues.isClosed,
missionSource,
missionSource: mainFormValues.missionSource || Mission.MissionSource.MONITORFISH,
missionTypes
}
}
Expand Down
60 changes: 60 additions & 0 deletions frontend/src/features/SideWindow/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { expect } from '@jest/globals'

import { Mission } from '../../../domain/entities/mission/types'
import { getMissionDataFromMissionFormValues } from '../MissionForm/utils'

import MissionSource = Mission.MissionSource
import MissionType = Mission.MissionType

describe('utils/getMissionDataFromMissionFormValues()', () => {
it('should keep the existing missionSource if previously set', () => {
const missionForm = {
controlUnits: [
{
administration: 'DDTM',
contact: undefined,
id: 10001,
isArchived: false,
name: 'Cultures marines – DDTM 40',
resources: [
{
id: 2,
name: 'Semi-rigide 2'
}
]
}
],
endDateTimeUtc: '2023-12-31T23:30:00.000000Z',
isClosed: false,
isGeometryComputedFromControls: true,
isUnderJdp: true,
isValid: true,
missionSource: MissionSource.POSEIDON_CNSP,
missionTypes: [MissionType.SEA],
startDateTimeUtc: '2022-12-31T23:30:00.000000Z'
}

const result = getMissionDataFromMissionFormValues(missionForm)

expect(result).toStrictEqual({
controlUnits: [
{
administration: 'DDTM',
contact: undefined,
id: 10001,
isArchived: false,
name: 'Cultures marines – DDTM 40',
resources: [{ id: 2, name: 'Semi-rigide 2' }]
}
],
endDateTimeUtc: '2023-12-31T23:30:00.000000Z',
isClosed: false,
isGeometryComputedFromControls: true,
isUnderJdp: true,
isValid: true,
missionSource: 'POSEIDON_CNSP',
missionTypes: ['SEA'],
startDateTimeUtc: '2022-12-31T23:30:00.000000Z'
})
})
})
Loading