Skip to content
Snippets Groups Projects
Commit cf231ac5 authored by BITARD Michaël's avatar BITARD Michaël
Browse files

chore(common): ajoute des tests (!1505)

parent eba62dee
No related branches found
No related tags found
1 merge request!1505chore(common): ajoute des tests
Pipeline #426454 failed
Showing
with 386 additions and 24 deletions
...@@ -14,6 +14,7 @@ import { ...@@ -14,6 +14,7 @@ import {
isBefore, isBefore,
intervalleAnnees, intervalleAnnees,
caminoDateValidator, caminoDateValidator,
CaminoDate,
} from './date' } from './date'
import { test, expect } from 'vitest' import { test, expect } from 'vitest'
...@@ -76,7 +77,9 @@ test('anneePrecedente', () => { ...@@ -76,7 +77,9 @@ test('anneePrecedente', () => {
}) })
test('intervalleAnnees', () => { test('intervalleAnnees', () => {
expect(intervalleAnnees(toCaminoAnnee('1997'), toCaminoAnnee('1999'))).toStrictEqual([toCaminoAnnee('1997'), toCaminoAnnee('1998'), toCaminoAnnee('1999')]) expect(intervalleAnnees(toCaminoAnnee('1997'), toCaminoAnnee('1999'))).toStrictEqual([toCaminoAnnee('1997'), toCaminoAnnee('1998'), toCaminoAnnee('1999')])
expect(() => intervalleAnnees(toCaminoAnnee('1999'), toCaminoAnnee('1980'))).toThrowErrorMatchingInlineSnapshot(`[Error: L'année de départ 1999 doit être inférieure à l'année d'arrivée 1980]`)
}) })
test("retourne une erreur si aucune date n'est fournie", () => { test("retourne une erreur si aucune date n'est fournie", () => {
let tested = dateValidate(null) let tested = dateValidate(null)
...@@ -108,6 +111,10 @@ test.each([ ...@@ -108,6 +111,10 @@ test.each([
expect(dateAddDays(toCaminoDate(date), days)).toBe(result) expect(dateAddDays(toCaminoDate(date), days)).toBe(result)
}) })
test("ajoute une date qui n'en est pas une", () => {
expect(() => dateAddDays('plop' as CaminoDate, 12)).toThrowErrorMatchingInlineSnapshot(`[Error: Cette camino date plop n'est pas vraiment une caminoDate]`)
})
test.each([ test.each([
['2020-01-01', 1, '2020-02-01'], ['2020-01-01', 1, '2020-02-01'],
['2020-01-01', 12, '2021-01-01'], ['2020-01-01', 12, '2021-01-01'],
......
...@@ -81,16 +81,11 @@ export function toCaminoAnnee(annee: string | number): CaminoAnnee { ...@@ -81,16 +81,11 @@ export function toCaminoAnnee(annee: string | number): CaminoAnnee {
export const dateValidate = (str: CaminoDate | string | undefined | null): { valid: true; date: CaminoDate } | { valid: false; error: 'Date manquante' | 'Date invalide' } => { export const dateValidate = (str: CaminoDate | string | undefined | null): { valid: true; date: CaminoDate } | { valid: false; error: 'Date manquante' | 'Date invalide' } => {
if (isNullOrUndefined(str)) return { valid: false, error: 'Date manquante' } if (isNullOrUndefined(str)) return { valid: false, error: 'Date manquante' }
try {
if (typeof str === 'string') { return { valid: true, date: toCaminoDate(str) }
try { } catch (e) {
return { valid: true, date: toCaminoDate(str) } return { valid: false, error: 'Date invalide' }
} catch (e) {
return { valid: false, error: 'Date invalide' }
}
} }
return { valid: true, date: str }
} }
export const intervalleAnnees = (anneeDepart: CaminoAnnee, anneeArrivee: CaminoAnnee): CaminoAnnee[] => { export const intervalleAnnees = (anneeDepart: CaminoAnnee, anneeArrivee: CaminoAnnee): CaminoAnnee[] => {
......
/* v8 ignore next 5 */
export interface Definition<T> { export interface Definition<T> {
id: T id: T
nom: string nom: string
......
...@@ -5,6 +5,7 @@ import { proprietesGeothermieForagesElementIds } from './static/titresTypes_dema ...@@ -5,6 +5,7 @@ import { proprietesGeothermieForagesElementIds } from './static/titresTypes_dema
import { ETAPES_TYPES } from './static/etapesTypes' import { ETAPES_TYPES } from './static/etapesTypes'
import { toCaminoDate } from './date' import { toCaminoDate } from './date'
import { DEMARCHES_TYPES_IDS } from './static/demarchesTypes' import { DEMARCHES_TYPES_IDS } from './static/demarchesTypes'
import { TITRES_TYPES_IDS, TitreTypeId } from './static/titresTypes'
test('getDemarcheContenu arm', () => { test('getDemarcheContenu arm', () => {
expect( expect(
...@@ -161,7 +162,67 @@ test('getDemarcheContenu prm', () => { ...@@ -161,7 +162,67 @@ test('getDemarcheContenu prm', () => {
} }
`) `)
}) })
test('getDemarcheContenu cxw', () => { test('getDemarcheContenu prm edgeCasess', () => {
expect(
getDemarcheContenu(
[
{
sections_with_values: [
{
id: 'prx',
nom: 'Propriétés du permis exclusif de recherches',
elements: [
{ id: 'engagement', optionnel: true, type: 'number', value: 3201430 },
{
id: 'engagementDeviseId',
nom: "Devise de l'engagement",
description: '',
optionnel: true,
type: 'select',
options: [
{ id: 'EUR', nom: 'Euros' },
{ id: 'FRF', nom: 'Francs' },
{ id: 'XPF', nom: 'Francs Pacifique' },
],
value: 'NET',
},
],
},
{
id: 'publication',
nom: 'Références Légifrance',
elements: [
{ id: 'jorf', nom: 'Numéro JORF', description: '', optionnel: false, type: 'text', value: 'JORFTEXT000000774145' },
{ id: 'nor', nom: 'Numéro NOR', description: '', optionnel: true, type: 'text', value: 'ECOI0100462D' },
],
},
],
etape_type_id: 'dpu',
},
],
'prm'
)
).toMatchInlineSnapshot(`
{
"": "3 201 430 Euros",
}
`)
})
test.each<{ titreTypeId: TitreTypeId; result: unknown }>([
{
titreTypeId: TITRES_TYPES_IDS.CONCESSION_SOUTERRAIN,
result: {
Volume: '3 000 000 Mètre cube par an',
},
},
{
titreTypeId: TITRES_TYPES_IDS.CONCESSION_GRANULATS_MARINS,
result: {
Volume: '3 000 000 Mètre cube par an',
},
},
{ titreTypeId: TITRES_TYPES_IDS.PERMIS_D_EXPLOITATION_GRANULATS_MARINS, result: {} },
])('getDemarcheContenu %s', ({ titreTypeId, result }) => {
expect( expect(
getDemarcheContenu( getDemarcheContenu(
[ [
...@@ -254,15 +315,97 @@ test('getDemarcheContenu cxw', () => { ...@@ -254,15 +315,97 @@ test('getDemarcheContenu cxw', () => {
etape_type_id: 'dex', etape_type_id: 'dex',
}, },
], ],
titreTypeId
)
).toStrictEqual(result)
})
test('edge cases', () => {
expect(
getDemarcheContenu(
[
{
sections_with_values: [
{
id: 'cxx',
nom: 'Propriétés de la concession',
elements: [
{ id: 'volume', optionnel: true, type: 'text', value: 'notANumber' },
{
id: 'volumeUniteId',
nom: 'Unité du volume',
description: '',
optionnel: true,
type: 'select',
options: [{ id: 'deg', nom: 'degré' }],
value: 'unknown',
},
],
},
],
etape_type_id: 'dpu',
},
],
'cxw' 'cxw'
) )
).toMatchInlineSnapshot(`
{
"": "0 Mètre cube",
}
`)
expect(
getDemarcheContenu(
[
{
etape_type_id: 'mfr',
sections_with_values: [
{
id: 'arm',
elements: [
{ id: 'franchissements', type: 'text', value: null, optionnel: false },
{ id: 'mecanise', type: 'text', value: null, optionnel: false },
],
},
],
},
],
TITRES_TYPES_IDS.AUTORISATION_DE_RECHERCHE_METAUX
)
).toMatchInlineSnapshot(` ).toMatchInlineSnapshot(`
{ {
"Volume": "3 000 000 Mètre cube par an", "": "Non",
}
`)
expect(
getDemarcheContenu(
[
{
etape_type_id: 'mfr',
sections_with_values: [
{
id: 'pxg',
elements: [
{ id: 'volume', type: 'number', value: 12, optionnel: false, uniteId: 'deg' },
{ id: 'debit', type: 'number', value: 13, optionnel: false, uniteId: 'deg' },
{ id: 'profondeurToitNappe', type: 'number', value: 13, optionnel: false, uniteId: 'deg' },
{ id: 'profondeurBaseNappe', type: 'number', value: 13, optionnel: false, uniteId: 'deg' },
],
},
],
},
],
TITRES_TYPES_IDS.PERMIS_D_EXPLOITATION_GEOTHERMIE
)
).toMatchInlineSnapshot(`
{
"": "13 undefined",
} }
`) `)
})
expect(getDemarcheContenu([], TITRES_TYPES_IDS.CONCESSION_FOSSILES)).toMatchInlineSnapshot(`{}`)
})
test('getDemarcheContenu pxg', () => { test('getDemarcheContenu pxg', () => {
expect( expect(
getDemarcheContenu( getDemarcheContenu(
......
...@@ -129,6 +129,7 @@ export const getDemarcheContenu = (etapes: (Pick<DemarcheEtapeCommon, 'sections_ ...@@ -129,6 +129,7 @@ export const getDemarcheContenu = (etapes: (Pick<DemarcheEtapeCommon, 'sections_
if (engagementLabel !== null && engagement !== null && engagementDeviseId !== null) { if (engagementLabel !== null && engagement !== null && engagementDeviseId !== null) {
return { [engagementLabel]: `${numberFormat(engagement)} ${capitalize(Devises[engagementDeviseId].nom)}` } return { [engagementLabel]: `${numberFormat(engagement)} ${capitalize(Devises[engagementDeviseId].nom)}` }
} }
/* v8 ignore next 2 */
} }
} else if ( } else if (
titreTypeId === TITRES_TYPES_IDS.CONCESSION_SOUTERRAIN || titreTypeId === TITRES_TYPES_IDS.CONCESSION_SOUTERRAIN ||
......
import { test, expect } from 'vitest' import { test, expect } from 'vitest'
import { sirenValidator } from './entreprise' import { isEntrepriseId, sirenValidator, toEntrepriseDocumentId } from './entreprise'
import { toCaminoDate } from './date'
test('sirenValidator', () => { test('sirenValidator', () => {
expect(sirenValidator.safeParse('123456789').success).toBe(true) expect(sirenValidator.safeParse('123456789').success).toBe(true)
...@@ -9,3 +10,11 @@ test('sirenValidator', () => { ...@@ -9,3 +10,11 @@ test('sirenValidator', () => {
expect(sirenValidator.safeParse('1234567').success).toBe(false) expect(sirenValidator.safeParse('1234567').success).toBe(false)
expect(sirenValidator.safeParse('1234567890').success).toBe(false) expect(sirenValidator.safeParse('1234567890').success).toBe(false)
}) })
test('isEntrepriseId', () => {
expect(isEntrepriseId('id')).toBe(true)
})
test('toEntrepriseDocumentId', () => {
expect(toEntrepriseDocumentId(toCaminoDate('2023-01-01'), 'aac', 'hash')).toBe('2023-01-01-aac-hash')
})
import { test, expect } from 'vitest'
import { activitesFiltresNames } from './filters'
test('activitesFiltresNames', () => {
expect(activitesFiltresNames).toMatchInlineSnapshot(`
[
"titresIds",
"substancesIds",
"domainesIds",
"typesIds",
"statutsIds",
"annees",
"entreprisesIds",
"activiteTypesIds",
"activiteStatutsIds",
"references",
]
`)
})
/* v8 ignore next 16 */
export const HTTP_STATUS = { export const HTTP_STATUS = {
// OK // OK
OK: 200, OK: 200,
......
/* v8 ignore next 8 */
import { z } from 'zod' import { z } from 'zod'
import { titreIdValidator } from './validators/titres' import { titreIdValidator } from './validators/titres'
......
import { test, expect } from 'vitest' import { test, expect } from 'vitest'
import { crsUrnValidator, equalGeojson } from './perimetre' import { crsUrnValidator, equalGeojson, featureMultiPolygonValidator } from './perimetre'
test('equalGeojson', () => { test('equalGeojson', () => {
expect(equalGeojson(null, null)).toBe(true) expect(equalGeojson(null, null)).toBe(true)
...@@ -51,4 +51,40 @@ test('crsUrnValidator', () => { ...@@ -51,4 +51,40 @@ test('crsUrnValidator', () => {
expect(crsUrnValidator.safeParse('urn:ogc:def:crs:EPSG::PLOP').success).toBe(false) expect(crsUrnValidator.safeParse('urn:ogc:def:crs:EPSG::PLOP').success).toBe(false)
expect(crsUrnValidator.safeParse('urn:ogc:def:crs:EPSG::').success).toBe(false) expect(crsUrnValidator.safeParse('urn:ogc:def:crs:EPSG::').success).toBe(false)
expect(crsUrnValidator.safeParse('urn:ogc:def:crs:EPSG::27572').success).toBe(true) expect(crsUrnValidator.safeParse('urn:ogc:def:crs:EPSG::27572').success).toBe(true)
expect(crsUrnValidator.safeParse(12).success).toBe(false)
})
test('nullableToEmptyObject', () => {
featureMultiPolygonValidator.parse({
type: 'Feature',
properties: null,
geometry: {
type: 'MultiPolygon',
coordinates: [
[
[
[1, 2],
[1, 2],
[1, 2],
],
],
],
},
})
featureMultiPolygonValidator.parse({
type: 'Feature',
properties: {},
geometry: {
type: 'MultiPolygon',
coordinates: [
[
[
[1, 2],
[1, 2],
[1, 2],
],
],
],
},
})
}) })
...@@ -88,6 +88,8 @@ export const canEditActivite = async ( ...@@ -88,6 +88,8 @@ export const canEditActivite = async (
const entrepriseFetched = await entreprises() const entrepriseFetched = await entreprises()
return user.entrepriseIds.some(entrepriseId => entrepriseFetched.includes(entrepriseId)) && [ACTIVITES_STATUTS_IDS.ABSENT, ACTIVITES_STATUTS_IDS.EN_CONSTRUCTION].includes(activiteStatutId) return user.entrepriseIds.some(entrepriseId => entrepriseFetched.includes(entrepriseId)) && [ACTIVITES_STATUTS_IDS.ABSENT, ACTIVITES_STATUTS_IDS.EN_CONSTRUCTION].includes(activiteStatutId)
// code unreachable due to canReadTitreActivites
/* v8 ignore next 4 */
} }
return false return false
......
...@@ -27,6 +27,8 @@ export const canReadActivitesTypesEmails = (user: User, administrationId: Admini ...@@ -27,6 +27,8 @@ export const canReadActivitesTypesEmails = (user: User, administrationId: Admini
administrationIds.push(user.administrationId) administrationIds.push(user.administrationId)
return administrationIds.includes(administrationId) return administrationIds.includes(administrationId)
// unreachable code due to canReadAdministrations
/* v8 ignore next 4 */
} }
return false return false
......
...@@ -3,6 +3,7 @@ import { ...@@ -3,6 +3,7 @@ import {
dateTypeStepIsComplete, dateTypeStepIsComplete,
entrepriseDocumentsStepIsComplete, entrepriseDocumentsStepIsComplete,
entrepriseDocumentsStepIsVisible, entrepriseDocumentsStepIsVisible,
etapeAvisStepIsComplete,
etapeAvisStepIsVisible, etapeAvisStepIsVisible,
etapeDocumentsStepIsComplete, etapeDocumentsStepIsComplete,
etapeDocumentsStepIsVisible, etapeDocumentsStepIsVisible,
...@@ -25,6 +26,7 @@ import { ADMINISTRATION_IDS } from '../static/administrations' ...@@ -25,6 +26,7 @@ import { ADMINISTRATION_IDS } from '../static/administrations'
import { SUBSTANCES_FISCALES_IDS } from '../static/substancesFiscales' import { SUBSTANCES_FISCALES_IDS } from '../static/substancesFiscales'
import { DEMARCHES_TYPES_IDS } from '../static/demarchesTypes' import { DEMARCHES_TYPES_IDS } from '../static/demarchesTypes'
import { TITRES_TYPES_IDS } from '../static/titresTypes' import { TITRES_TYPES_IDS } from '../static/titresTypes'
import { ETAPES_TYPES } from '../static/etapesTypes'
describe('dateTypeStepIsComplete', () => { describe('dateTypeStepIsComplete', () => {
test.each<User>([ test.each<User>([
...@@ -599,6 +601,12 @@ test('etapeDocumentsStepIsComplete', () => { ...@@ -599,6 +601,12 @@ test('etapeDocumentsStepIsComplete', () => {
"valid": true, "valid": true,
} }
`) `)
expect(etapeDocumentsStepIsComplete({ typeId: 'pqr', contenu: {}, isBrouillon: ETAPE_IS_BROUILLON }, 'oct', 'axm', [], [])).toMatchInlineSnapshot(`
{
"valid": true,
}
`)
}) })
test('entrepriseDocumentsStepIsVisible', () => { test('entrepriseDocumentsStepIsVisible', () => {
...@@ -911,6 +919,15 @@ test('getDocumentsTypes', () => { ...@@ -911,6 +919,15 @@ test('getDocumentsTypes', () => {
}) })
test('getAvisType', () => { test('getAvisType', () => {
expect(getAvisTypes(ETAPES_TYPES.avisDesCollectivites, 'arm', [])).toMatchInlineSnapshot(`
[
{
"id": "avisDUneCollectivite",
"nom": "Avis d'une collectivité",
"optionnel": true,
},
]
`)
expect(getAvisTypes('mfr', 'arm', [])).toMatchInlineSnapshot('[]') expect(getAvisTypes('mfr', 'arm', [])).toMatchInlineSnapshot('[]')
expect(getAvisTypes('asc', 'arm', [])).toMatchInlineSnapshot(` expect(getAvisTypes('asc', 'arm', [])).toMatchInlineSnapshot(`
[ [
...@@ -1219,3 +1236,8 @@ test('etapeAvisStepIsVisible', () => { ...@@ -1219,3 +1236,8 @@ test('etapeAvisStepIsVisible', () => {
expect(etapeAvisStepIsVisible({ typeId: 'mfr' }, 'arm', [])).toBe(false) expect(etapeAvisStepIsVisible({ typeId: 'mfr' }, 'arm', [])).toBe(false)
expect(etapeAvisStepIsVisible({ typeId: 'asc' }, 'arm', [])).toBe(true) expect(etapeAvisStepIsVisible({ typeId: 'asc' }, 'arm', [])).toBe(true)
}) })
test('etapeAvisStepIsComplete', () => {
expect(etapeAvisStepIsComplete({ typeId: ETAPES_TYPES.avisDesServicesEtCommissionsConsultatives }, [{ avis_type_id: 'autreAvis' }], 'arm', []).valid).toBe(false)
expect(etapeAvisStepIsComplete({ typeId: ETAPES_TYPES.avisDesCollectivites }, [{ avis_type_id: 'autreAvis' }], 'arm', []).valid).toBe(true)
})
import { describe, expect, test } from 'vitest' import { describe, expect, test } from 'vitest'
import { AdministrationId } from '../static/administrations' import { AdministrationId } from '../static/administrations'
import { canEditDemarche, canCreateTravaux, canDeleteDemarche, canCreateDemarche, canPublishResultatMiseEnConcurrence } from './titres-demarches' import { canEditDemarche, canCreateTravaux, canDeleteDemarche, canCreateDemarche, canPublishResultatMiseEnConcurrence, canCreateEtapeByDemarche } from './titres-demarches'
import { testBlankUser, TestUser } from '../tests-utils' import { testBlankUser, TestUser } from '../tests-utils'
import { TitresStatutIds } from '../static/titresStatuts' import { TitresStatutIds } from '../static/titresStatuts'
import { caminoDateValidator, dateAddDays, toCaminoDate } from '../date' import { caminoDateValidator, dateAddDays, toCaminoDate } from '../date'
...@@ -218,3 +218,7 @@ describe('canPublishResultatMiseEnConcurrence', () => { ...@@ -218,3 +218,7 @@ describe('canPublishResultatMiseEnConcurrence', () => {
`) `)
}) })
}) })
test('canCreateEtapeByDemarche', () => {
canCreateEtapeByDemarche({ ...testBlankUser, role: 'super' }, 'arm', 'oct', [], 'dmi')
})
...@@ -17,6 +17,7 @@ import { ...@@ -17,6 +17,7 @@ import {
isEtapeDeposable, isEtapeDeposable,
InputPresence, InputPresence,
canEditPerimetre, canEditPerimetre,
canDeposeEtape,
} from './titres-etapes' } from './titres-etapes'
import { AdministrationId, ADMINISTRATION_IDS } from '../static/administrations' import { AdministrationId, ADMINISTRATION_IDS } from '../static/administrations'
import { test, expect, describe, vi } from 'vitest' import { test, expect, describe, vi } from 'vitest'
...@@ -78,6 +79,7 @@ test.each<{ titreTypeId: TitreTypeId; demarcheTypeId: DemarcheTypeId; etapeTypeI ...@@ -78,6 +79,7 @@ test.each<{ titreTypeId: TitreTypeId; demarcheTypeId: DemarcheTypeId; etapeTypeI
{ titreTypeId: 'prm', etapeTypeId: 'mfr', demarcheTypeId: 'dep', user: { role: 'lecteur', administrationId: ADMINISTRATION_IDS.BRGM }, canEdit: false }, { titreTypeId: 'prm', etapeTypeId: 'mfr', demarcheTypeId: 'dep', user: { role: 'lecteur', administrationId: ADMINISTRATION_IDS.BRGM }, canEdit: false },
{ titreTypeId: 'prm', etapeTypeId: 'mfr', demarcheTypeId: 'exp', user: { role: 'super' }, canEdit: false }, { titreTypeId: 'prm', etapeTypeId: 'mfr', demarcheTypeId: 'exp', user: { role: 'super' }, canEdit: false },
{ titreTypeId: 'prm', etapeTypeId: 'mfr', demarcheTypeId: 'mut', user: { role: 'super' }, canEdit: false }, { titreTypeId: 'prm', etapeTypeId: 'mfr', demarcheTypeId: 'mut', user: { role: 'super' }, canEdit: false },
{ titreTypeId: 'prm', etapeTypeId: 'dpu', demarcheTypeId: 'dec', user: { role: 'defaut' }, canEdit: false },
])('canEditDate $titreTypeId | $demarcheTypeId | $etapeTypeId | $user | $canEdit', ({ titreTypeId, demarcheTypeId, etapeTypeId, user, canEdit }) => { ])('canEditDate $titreTypeId | $demarcheTypeId | $etapeTypeId | $user | $canEdit', ({ titreTypeId, demarcheTypeId, etapeTypeId, user, canEdit }) => {
expect(canEditDates(titreTypeId, demarcheTypeId, etapeTypeId, { ...user, ...testBlankUser }).visibility === 'present').toEqual(canEdit) expect(canEditDates(titreTypeId, demarcheTypeId, etapeTypeId, { ...user, ...testBlankUser }).visibility === 'present').toEqual(canEdit)
}) })
...@@ -312,6 +314,13 @@ test('une entreprise peut modifier sa demande mais ne peut pas la supprimer', () ...@@ -312,6 +314,13 @@ test('une entreprise peut modifier sa demande mais ne peut pas la supprimer', ()
expect(canDeleteEtape(user, 'mfr', ETAPE_IS_BROUILLON, [entrepriseId], [], 'oct', { typeId: 'arm', titreStatutId: 'ind' })).toBe(false) expect(canDeleteEtape(user, 'mfr', ETAPE_IS_BROUILLON, [entrepriseId], [], 'oct', { typeId: 'arm', titreStatutId: 'ind' })).toBe(false)
}) })
test('canDeleteEtape', () => {
const entrepriseId = entrepriseIdValidator.parse('entrepriseId')
const user: EntrepriseUserNotNull = { ...testBlankUser, role: 'entreprise', entrepriseIds: [entrepriseId] }
expect(canDeleteEtape(user, 'mfr', ETAPE_IS_BROUILLON, [entrepriseId], [], 'oct', { typeId: 'arm', titreStatutId: 'ind' })).toBe(false)
expect(canDeleteEtape({ ...testBlankUser, role: 'super' }, 'mfr', ETAPE_IS_BROUILLON, [entrepriseId], [], 'oct', { typeId: 'arm', titreStatutId: 'ind' })).toBe(true)
})
const multiPolygonWith4Points: FeatureMultiPolygon = { const multiPolygonWith4Points: FeatureMultiPolygon = {
type: 'Feature', type: 'Feature',
properties: {}, properties: {},
...@@ -581,6 +590,28 @@ test.each<[number | null, EtapeTypeId, TitreTypeId, IsEtapeCompleteDocuments, Is ...@@ -581,6 +590,28 @@ test.each<[number | null, EtapeTypeId, TitreTypeId, IsEtapeCompleteDocuments, Is
} }
}) })
describe('canDeposeEtape', () => {
test("Une demande d'ARM complète brouillon", () => {
expect(
canDeposeEtape(
{ ...testBlankUser, role: 'super' },
{
typeId: 'arm',
titreStatutId: 'dmi',
titulaires: [],
administrationsLocales: [],
},
'oct',
{ ...etapeComplete, isBrouillon: ETAPE_IS_BROUILLON, contenu: { arm: { mecanise: { value: false, etapeHeritee: null, heritee: false } } } },
[...armDocuments],
[...armEntrepriseDocuments],
[],
[],
[]
)
).toStrictEqual(true)
})
})
describe('isEtapeDeposable', () => { describe('isEtapeDeposable', () => {
test("Une demande d'ARM complète brouillon", () => { test("Une demande d'ARM complète brouillon", () => {
expect( expect(
......
import { test, expect } from 'vitest' import { test, expect } from 'vitest'
import { getRestRoute } from './rest' import { getRestRoute, isCaminoRestRoute } from './rest'
import { utilisateurIdValidator } from './roles' import { utilisateurIdValidator } from './roles'
test('getRestRoute', () => { test('getRestRoute', () => {
...@@ -9,3 +9,8 @@ test('getRestRoute', () => { ...@@ -9,3 +9,8 @@ test('getRestRoute', () => {
) )
expect(getRestRoute('/rest/utilisateurs/:id/newsletter', { id: utilisateurIdValidator.parse('userId') }, { toto: 'plop' })).toBe('/rest/utilisateurs/userId/newsletter?toto=plop') expect(getRestRoute('/rest/utilisateurs/:id/newsletter', { id: utilisateurIdValidator.parse('userId') }, { toto: 'plop' })).toBe('/rest/utilisateurs/userId/newsletter?toto=plop')
}) })
test('isCaminoRestRoute', () => {
expect(isCaminoRestRoute('/toto')).toBe(false)
expect(isCaminoRestRoute('/rest/utilisateurs/:id/newsletter')).toBe(true)
})
...@@ -11,6 +11,11 @@ import { ...@@ -11,6 +11,11 @@ import {
isBureauDEtudes, isBureauDEtudes,
BaseUserNotNull, BaseUserNotNull,
toUtilisateurId, toUtilisateurId,
isAdministrationRole,
isSuperRole,
isDefautRole,
isEntrepriseRole,
isEntrepriseOrBureauDetudeRole,
} from './roles' } from './roles'
import { ADMINISTRATION_IDS } from './static/administrations' import { ADMINISTRATION_IDS } from './static/administrations'
import { test, expect, describe } from 'vitest' import { test, expect, describe } from 'vitest'
...@@ -105,4 +110,10 @@ test('isRole', () => { ...@@ -105,4 +110,10 @@ test('isRole', () => {
expect(isRole('')).toBe(false) expect(isRole('')).toBe(false)
expect(isRole(undefined)).toBe(false) expect(isRole(undefined)).toBe(false)
expect(isRole(null)).toBe(false) expect(isRole(null)).toBe(false)
expect(isAdministrationRole('defaut')).toBe(false)
expect(isSuperRole('defaut')).toBe(false)
expect(isDefautRole('defaut')).toBe(true)
expect(isEntrepriseRole('defaut')).toBe(false)
expect(isEntrepriseOrBureauDetudeRole('defaut')).toBe(false)
}) })
import { test, expect } from 'vitest' import { test, expect } from 'vitest'
import { isRadioElement, simpleContenuToFlattenedContenu, valeurFind } from './sections' import { flattenContenuToSimpleContenu, isRadioElement, simpleContenuToFlattenedContenu, valeurFind } from './sections'
import { caminoDateValidator } from './date' import { caminoDateValidator, toCaminoDate } from './date'
test('valeurFind', () => { test('valeurFind', () => {
expect(valeurFind({ id: 'camino', type: 'text', value: null, optionnel: false })).toBe('') expect(valeurFind({ id: 'camino', type: 'text', value: null, optionnel: false })).toBe('')
...@@ -19,6 +19,15 @@ test('valeurFind', () => { ...@@ -19,6 +19,15 @@ test('valeurFind', () => {
optionnel: false, optionnel: false,
}) })
).toBe('A, B') ).toBe('A, B')
expect(
valeurFind({
id: 'camino',
type: 'checkboxes',
value: ['c'],
options: [{ id: 'a', nom: 'A' }],
optionnel: false,
})
).toBe('')
expect( expect(
valeurFind({ valeurFind({
id: 'camino', id: 'camino',
...@@ -60,6 +69,7 @@ test('valeurFind', () => { ...@@ -60,6 +69,7 @@ test('valeurFind', () => {
expect(valeurFind({ id: 'camino', type: 'radio', value: false, optionnel: false })).toBe('Non') expect(valeurFind({ id: 'camino', type: 'radio', value: false, optionnel: false })).toBe('Non')
expect(valeurFind({ id: 'camino', type: 'checkbox', value: true, optionnel: false })).toBe('Oui') expect(valeurFind({ id: 'camino', type: 'checkbox', value: true, optionnel: false })).toBe('Oui')
expect(valeurFind({ id: 'camino', type: 'checkbox', value: false, optionnel: false })).toBe('Non') expect(valeurFind({ id: 'camino', type: 'checkbox', value: false, optionnel: false })).toBe('Non')
expect(valeurFind({ id: 'camino', type: 'checkbox', value: null, optionnel: false })).toBe('')
expect(valeurFind({ id: 'camino', type: 'url', value: 'test', optionnel: false })).toBe('test') expect(valeurFind({ id: 'camino', type: 'url', value: 'test', optionnel: false })).toBe('test')
}) })
...@@ -125,4 +135,64 @@ test('simpleContenuToFlattenedContenu', () => { ...@@ -125,4 +135,64 @@ test('simpleContenuToFlattenedContenu', () => {
}, },
} }
`) `)
expect(
simpleContenuToFlattenedContenu(
'arm',
'oct',
'mfr',
{ arm: {} },
{ arm: { mecanise: { actif: true, etape: { date: caminoDateValidator.parse('2023-02-02'), typeId: 'mfr', contenu: { arm: {} } } } } }
)
).toMatchInlineSnapshot(`
{
"arm": {
"franchissements": {
"etapeHeritee": null,
"heritee": false,
"value": null,
},
"mecanise": {
"etapeHeritee": {
"date": "2023-02-02",
"etapeTypeId": "mfr",
"value": null,
},
"heritee": true,
"value": null,
},
},
}
`)
})
test('flattenContenuToSimpleContenu', () => {
expect(
flattenContenuToSimpleContenu({
plop: undefined,
arm: {
franchissements: {
etapeHeritee: null,
heritee: false,
value: null,
},
mecanise: {
etapeHeritee: {
date: toCaminoDate('2023-02-02'),
etapeTypeId: 'mfr',
value: false,
},
heritee: false,
value: true,
},
},
})
).toMatchInlineSnapshot(`
{
"arm": {
"franchissements": null,
"mecanise": true,
},
"plop": {},
}
`)
}) })
...@@ -12,7 +12,7 @@ import { ...@@ -12,7 +12,7 @@ import {
urlElementValidator, urlElementValidator,
} from './static/titresTypes_demarchesTypes_etapesTypes/sections' } from './static/titresTypes_demarchesTypes_etapesTypes/sections'
import { z } from 'zod' import { z } from 'zod'
import { DeepReadonly, isNotNullNorUndefined, isNotNullNorUndefinedNorEmpty, isNullOrUndefined } from './typescript-tools' import { DeepReadonly, isNotNullNorUndefined, isNotNullNorUndefinedNorEmpty } from './typescript-tools'
import { TitreTypeId } from './static/titresTypes' import { TitreTypeId } from './static/titresTypes'
import { DemarcheTypeId } from './static/demarchesTypes' import { DemarcheTypeId } from './static/demarchesTypes'
import { EtapeTypeId } from './static/etapesTypes' import { EtapeTypeId } from './static/etapesTypes'
...@@ -93,9 +93,7 @@ export const valeurFind = (element: ElementWithValue): string | '–' => { ...@@ -93,9 +93,7 @@ export const valeurFind = (element: ElementWithValue): string | '–' => {
} }
if (element.type === 'radio' || element.type === 'checkbox') { if (element.type === 'radio' || element.type === 'checkbox') {
if (isNullOrUndefined(element.value)) return '' return element.value ? 'Oui' : 'Non'
else if (element.value) return 'Oui'
else return 'Non'
} }
return element.value return element.value
...@@ -134,10 +132,10 @@ export const simpleContenuToFlattenedContenu = ( ...@@ -134,10 +132,10 @@ export const simpleContenuToFlattenedContenu = (
} }
export const flattenContenuToSimpleContenu = (flattenContenu: FlattenEtape['contenu']): RestEtapeCreation['contenu'] => { export const flattenContenuToSimpleContenu = (flattenContenu: FlattenEtape['contenu']): RestEtapeCreation['contenu'] => {
return Object.keys(flattenContenu).reduce<RestEtapeCreation['contenu']>((sectionsAcc, section) => { return Object.entries(flattenContenu).reduce<RestEtapeCreation['contenu']>((sectionsAcc, [section, value]) => {
sectionsAcc = { sectionsAcc = {
...sectionsAcc, ...sectionsAcc,
[section]: Object.keys(flattenContenu[section] ?? {}).reduce<RestEtapeCreation['contenu'][string]>((elementsAcc, element) => { [section]: Object.keys(value ?? {}).reduce<RestEtapeCreation['contenu'][string]>((elementsAcc, element) => {
elementsAcc = { ...elementsAcc, [element]: flattenContenu[section]?.[element]?.value ?? null } elementsAcc = { ...elementsAcc, [element]: flattenContenu[section]?.[element]?.value ?? null }
return elementsAcc return elementsAcc
......
...@@ -29,6 +29,10 @@ test('levenshtein', () => { ...@@ -29,6 +29,10 @@ test('levenshtein', () => {
expect(levenshtein('port', 'or')).toBe(2) expect(levenshtein('port', 'or')).toBe(2)
expect(levenshtein('or', 'port')).toBe(2) expect(levenshtein('or', 'port')).toBe(2)
expect(levenshtein('', 'port')).toBe(4) expect(levenshtein('', 'port')).toBe(4)
expect(levenshtein('chien', 'chine')).toBe(2)
expect(levenshtein('abcd', 'xyzw')).toBe(4)
expect(levenshtein('chat', 'cha t')).toBe(1)
expect(levenshtein('p@ssw0rd!', 'password!')).toBe(2)
}) })
test('slugify', () => { test('slugify', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment