Skip to content
Snippets Groups Projects
Verified Commit cc928a0d authored by SAFINE LAGET Anis's avatar SAFINE LAGET Anis Committed by BITARD Michaël
Browse files

fix(heritage): corrige l'héritage des surfaces (!1599)

parent 76ae8e54
No related branches found
No related tags found
No related merge requests found
Pipeline #460588 canceled
......@@ -8,6 +8,7 @@ import { newEtapeId } from '../../database/models/_format/id-create'
import { ETAPE_HERITAGE_PROPS, EtapeHeritageProps } from 'camino-common/src/heritage'
import { EntrepriseId, entrepriseIdValidator } from 'camino-common/src/entreprise'
import { km2Validator } from 'camino-common/src/number'
describe('retourne l’étape en fonction de son héritage', () => {
test('l’étape n’est pas modifiée si elle n’a pas d’étape précédente et qu’elle n’a aucun héritage d’actif', () => {
......@@ -318,4 +319,31 @@ describe('retourne l’étape en fonction de son héritage', () => {
titreEtape: newTitreEtape,
})
})
test("l'héritage de la surface n'est pas considéré comme modifié quand null et 0", () => {
const titreEtapePrecedente = {
id: 'titreEtapePrecedenteId',
geojson4326Forages: undefined,
geojson4326Points: undefined,
geojsonOriginePoints: undefined,
geojsonOriginePerimetre: undefined,
geojsonOrigineGeoSystemeId: undefined,
geojsonOrigineForages: undefined,
surface: null,
geojson4326Perimetre: null,
heritageProps: ETAPE_HERITAGE_PROPS.reduce((acc, prop) => {
acc[prop] = { actif: false, etapeId: null }
return acc
}, {} as IHeritageProps),
} as ITitreEtape
const titreEtape = objectClone(titreEtapePrecedente) as ITitreEtape
titreEtape.surface = km2Validator.parse(0)
titreEtape.heritageProps!.perimetre.actif = true
titreEtape.id = newEtapeId('titreEtapeId')
ETAPE_HERITAGE_PROPS.forEach(prop => (titreEtape.heritageProps![prop].etapeId = titreEtapePrecedente.id))
expect(titreEtapeHeritagePropsFind(titreEtape, titreEtapePrecedente).hasChanged).toBe(false)
})
})
......@@ -28,11 +28,15 @@ type IPropValueArray = undefined | null | IEntreprise[] | SubstanceLegaleId[]
type IPropValue = number | string | IPropValueArray | FeatureMultiPolygon
const titreEtapePropCheck = (propId: string, oldValue?: IPropValue | null, newValue?: IPropValue | null): boolean => {
const titreEtapePropCheck = (propId: string, realPropId: keyof ITitreEtape, oldValue?: IPropValue | null, newValue?: IPropValue | null): boolean => {
if (['titulaires', 'amodiataires', 'substances'].includes(propId)) {
return propertyArrayCheck(oldValue as IPropValueArray, newValue as IPropValueArray, propId)
}
if (realPropId === 'surface') {
return (oldValue ?? 0) === (newValue ?? 0)
}
if (propId === 'perimetre' && isNotNullNorUndefined(oldValue) && isNotNullNorUndefined(newValue)) {
return equalGeojson((newValue as FeatureMultiPolygon).geometry, (oldValue as FeatureMultiPolygon).geometry)
}
......@@ -100,7 +104,7 @@ export const titreEtapeHeritagePropsFind = (
const oldValue = titreEtape[propIds[i]] as IPropValue | undefined | null
newValue = prevTitreEtape[propIds[i]] as IPropValue | undefined | null
if (!titreEtapePropCheck(propId, oldValue, newValue)) {
if (!titreEtapePropCheck(propId, propIds[i], oldValue, newValue)) {
propChanged = true
break
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment