Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
fix coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
anis committed Sep 16, 2024
1 parent 688d8fd commit 567e14b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { titreEtapeForMachineValidator, toMachineEtapes } from '../rules-demarch
import { titreEtapesSortAscByOrdre } from '../utils/titre-etapes-sort'
import { titreInModificationEnInstance } from './titre-statut-id-find'
import { ETAPES_STATUTS, isEtapeStatusRejete } from 'camino-common/src/static/etapesStatuts'
import { DOMAINES_IDS } from 'camino-common/src/static/domaines'
const titreDemarchePublicLectureFind = (
publicLecture: boolean,
demarcheTypeId: DemarcheTypeId,
Expand Down Expand Up @@ -159,7 +160,7 @@ const titreDemarchePublicLectureFind = (
const domaineId = titreTypeId ? getDomaineId(titreTypeId) : null
if (
domaineId &&
['m', 'w', 'c'].includes(domaineId) &&
[DOMAINES_IDS.METAUX, DOMAINES_IDS.GRANULATS_MARINS, DOMAINES_IDS.CARRIERES].includes(domaineId) &&
[
ETAPES_TYPES.avisDeMiseEnConcurrenceAuJORF,
ETAPES_TYPES.decisionDeLadministration,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/permissions/entreprises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const canEditEntreprise = (user: User, entrepriseId?: EntrepriseId): bool
}

if (isEntreprise(user) || isBureauDEtudes(user)) {
return user.entrepriseIds?.includes(entrepriseId) ?? false
return user.entrepriseIds.includes(entrepriseId)
}

return false
Expand All @@ -27,7 +27,7 @@ export const canSeeEntrepriseDocuments = (user: User, entrepriseId: EntrepriseId
}

if (isEntreprise(user) || isBureauDEtudes(user)) {
return user.entrepriseIds?.includes(entrepriseId) ?? false
return user.entrepriseIds.includes(entrepriseId)
}

return false
Expand Down
71 changes: 70 additions & 1 deletion packages/common/src/permissions/etape-form.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from 'vitest'
import { describe, expect, test } from 'vitest'
import {
dateTypeStepIsComplete,
entrepriseDocumentsStepIsComplete,
entrepriseDocumentsStepIsVisible,
etapeAvisStepIsVisible,
Expand All @@ -19,6 +20,74 @@ import { toCaminoDate } from '../date'
import { testBlankUser } from '../tests-utils'
import { entrepriseIdValidator } from '../entreprise'
import { communeIdValidator } from '../static/communes'
import { User } from '../roles'
import { ADMINISTRATION_IDS } from '../static/administrations'

describe('dateTypeStepIsComplete', () => {
test.each<User>([
{ ...testBlankUser, role: 'super' },
{ ...testBlankUser, role: 'admin', administrationId: ADMINISTRATION_IDS.BRGM },
{ ...testBlankUser, role: 'editeur', administrationId: ADMINISTRATION_IDS.BRGM },
])('le date-type est toujours complet pour un %s', user => {
expect(
dateTypeStepIsComplete(
{
date: toCaminoDate('2024-01-01'),
typeId: 'mfr',
statutId: 'fai',
},
user
).valid
).toBe(true)
})

test('le date-type avec une date, un typeId, et un statutId est complet', () => {
const result = dateTypeStepIsComplete(
{
date: toCaminoDate('2024-01-01'),
typeId: 'mfr',
statutId: 'fai',
},
{
...testBlankUser,
role: 'super',
}
)
expect(result.valid).toBe(true)
})

test('le date-type avec une date, un typeId, et un statutId est complet', () => {
const result = dateTypeStepIsComplete(
{
date: toCaminoDate('2024-01-01'),
typeId: 'mfr',
statutId: 'fai',
},
{
...testBlankUser,
role: 'super',
}
)
expect(result.valid).toBe(true)
})

test('le date-type sans date, typeId, ou statutId est incomplet', () => {
const result = dateTypeStepIsComplete(
{
date: null,
typeId: null,
statutId: null,
},
{
...testBlankUser,
role: 'super',
}
)
expect(result.valid).toBe(false)
// @ts-ignore
expect(result.errors).toStrictEqual(["La date de l'étape est obligatoire", "Le type de l'étape est obligatoire", "Le statut de l'étape est obligatoire"])
})
})

test('fondamentaleStepIsVisible', () => {
expect(fondamentaleStepIsVisible('mfr')).toBe(true)
Expand Down
6 changes: 3 additions & 3 deletions packages/common/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export default defineConfig({
thresholds: {
// the endgame is to put thresholds at 100 and never touch it again :)
autoUpdate: true,
branches: 91.01,
branches: 91.57,
functions: 83.46,
lines: 96.68,
statements: 96.68,
lines: 96.73,
statements: 96.73,
perFile: false,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
<div class="fr-text--sm fr-mb-0">Lien public externe</div>
<div class="fr-text--md fr-mb-0" style="font-weight: 500;"><a target="_blank" rel="noopener noreferrer" href="https://beta.gouv.fr" title="Lien public externe - Lien externe">https://beta.gouv.fr</a></div>
</div>
<div>
<div class="fr-text--sm fr-mb-0">Durée en jours de l'enquête publique</div>
<div class="fr-text--md fr-mb-0" style="font-weight: 500;">
<p>7
<!----><span class="fr-info-text fr-mt-0">Du 24-10-2023 au 30-10-2023 (inclus)</span>
</p>
</div>
</div>
<div style="grid-column: 1 / -1; white-space: pre-line;">
<div class="fr-text--sm fr-mb-0">Notes</div>
<div class="fr-text--md fr-mb-0" style="font-weight: 500;">Super note</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
<div class="fr-text--sm fr-mb-0">Lien public externe</div>
<div class="fr-text--md fr-mb-0" style="font-weight: 500;"><a target="_blank" rel="noopener noreferrer" href="https://beta.gouv.fr" title="Lien public externe - Lien externe">https://beta.gouv.fr</a></div>
</div>
<div>
<div class="fr-text--sm fr-mb-0">Durée en jours de l'enquête publique</div>
<div class="fr-text--md fr-mb-0" style="font-weight: 500;">
<p>7
<!----><span class="fr-info-text fr-mt-0">Du 24-10-2023 au 30-10-2023 (inclus)</span>
</p>
</div>
</div>
<!---->
</div>
<!---->
Expand Down

0 comments on commit 567e14b

Please sign in to comment.