From 8d5549c8a9c6c524ce56c5574ea5157ea640ee84 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 24 Oct 2023 12:27:44 +0200 Subject: [PATCH] Fix missing var in control unit dialog e2e test --- .../ArchiveAdministrationUTests.kt | 44 +++++++++++ .../CanArchiveAdministrationUTests.kt | 76 +++++++++++++++++++ .../CreateOrUpdateAdministrationUTests.kt | 3 +- .../{ => base}/CreateOrUpdateBaseUTests.kt | 3 +- .../CreateOrUpdateControlUnitContactUTests.kt | 3 +- ...CreateOrUpdateControlUnitResourceUTests.kt | 3 +- .../CreateOrUpdateControlUnitUTests.kt | 3 +- .../control_unit_dialog/resource_list.spec.ts | 2 +- 8 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministrationUTests.kt rename backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/{ => administration}/CreateOrUpdateAdministrationUTests.kt (90%) rename backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/{ => base}/CreateOrUpdateBaseUTests.kt (90%) rename backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/{ => controlUnit}/CreateOrUpdateControlUnitContactUTests.kt (91%) rename backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/{ => controlUnit}/CreateOrUpdateControlUnitResourceUTests.kt (92%) rename backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/{ => controlUnit}/CreateOrUpdateControlUnitUTests.kt (91%) diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt new file mode 100644 index 0000000000..11b49b3dc8 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt @@ -0,0 +1,44 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.administration + +import com.nhaarman.mockitokotlin2.given +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions +import fr.gouv.cacem.monitorenv.domain.repositories.IAdministrationRepository +import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.exceptions.UnarchivedChildException +import org.assertj.core.api.Assertions.assertThatThrownBy +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.test.context.junit.jupiter.SpringExtension + +@ExtendWith(SpringExtension::class) +class ArchiveAdministrationUTests { + @MockBean + private lateinit var administrationRepository: IAdministrationRepository + + @MockBean + private lateinit var canArchiveAdministration: CanArchiveAdministration + + @Test + fun `execute() should archive when canArchive() returns true`() { + val administrationId = 1 + given(canArchiveAdministration.execute(administrationId)).willReturn(true) + + ArchiveAdministration(administrationRepository, canArchiveAdministration).execute(administrationId) + + verify(administrationRepository).archiveById(administrationId) + } + + @Test + fun `execute() should throw UnarchivedChildException when canArchive() returns false`() { + val administrationId = 1 + given(canArchiveAdministration.execute(administrationId)).willReturn(false) + + assertThatThrownBy { + ArchiveAdministration(administrationRepository, canArchiveAdministration).execute(administrationId) + } + .isInstanceOf(UnarchivedChildException::class.java) + + verifyNoMoreInteractions(administrationRepository) + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministrationUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministrationUTests.kt new file mode 100644 index 0000000000..177cffe10d --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministrationUTests.kt @@ -0,0 +1,76 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.administration + +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.entities.administration.AdministrationEntity +import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitEntity +import fr.gouv.cacem.monitorenv.domain.repositories.IAdministrationRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.administration.dtos.FullAdministrationDTO +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.test.context.junit.jupiter.SpringExtension + +@ExtendWith(SpringExtension::class) +class CanArchiveAdministrationUTests { + @MockBean + private lateinit var administrationRepository: IAdministrationRepository + + @Test + fun `execute() should return true when all control units are archived`() { + val administrationId = 1 + val administration = FullAdministrationDTO( + administration = AdministrationEntity( + id = 1, + name = "Administration Name", + isArchived = false, + ), + controlUnits = listOf( + ControlUnitEntity( + id = 0, + administrationId = 1, + areaNote = null, + departmentAreaInseeCode = null, + isArchived = true, + name = "Control Unit Name", + termsNote = null, + ), + ), + ) + + given(administrationRepository.findById(administrationId)).willReturn(administration) + + val result = CanArchiveAdministration(administrationRepository).execute(administrationId) + + assertThat(result).isTrue + } + + @Test + fun `execute() should return false when some control units are not archived`() { + val administrationId = 1 + val administration = FullAdministrationDTO( + administration = AdministrationEntity( + id = 1, + name = "Administration Name", + isArchived = false, + ), + controlUnits = listOf( + ControlUnitEntity( + id = 0, + administrationId = 1, + areaNote = null, + departmentAreaInseeCode = null, + isArchived = false, + name = "Control Unit Name", + termsNote = null, + ), + ), + ) + + given(administrationRepository.findById(administrationId)).willReturn(administration) + + val result = CanArchiveAdministration(administrationRepository).execute(administrationId) + + assertThat(result).isFalse + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateAdministrationUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CreateOrUpdateAdministrationUTests.kt similarity index 90% rename from backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateAdministrationUTests.kt rename to backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CreateOrUpdateAdministrationUTests.kt index c9a475a06f..4e937479cd 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateAdministrationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CreateOrUpdateAdministrationUTests.kt @@ -1,11 +1,10 @@ -package fr.gouv.cacem.monitorenv.domain.use_cases +package fr.gouv.cacem.monitorenv.domain.use_cases.administration import com.nhaarman.mockitokotlin2.given import com.nhaarman.mockitokotlin2.times import com.nhaarman.mockitokotlin2.verify import fr.gouv.cacem.monitorenv.domain.entities.administration.AdministrationEntity import fr.gouv.cacem.monitorenv.domain.repositories.IAdministrationRepository -import fr.gouv.cacem.monitorenv.domain.use_cases.administration.CreateOrUpdateAdministration import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateBaseUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/base/CreateOrUpdateBaseUTests.kt similarity index 90% rename from backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateBaseUTests.kt rename to backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/base/CreateOrUpdateBaseUTests.kt index b2a44a0114..299a2a749e 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateBaseUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/base/CreateOrUpdateBaseUTests.kt @@ -1,11 +1,10 @@ -package fr.gouv.cacem.monitorenv.domain.use_cases +package fr.gouv.cacem.monitorenv.domain.use_cases.base import com.nhaarman.mockitokotlin2.given import com.nhaarman.mockitokotlin2.times import com.nhaarman.mockitokotlin2.verify import fr.gouv.cacem.monitorenv.domain.entities.base.BaseEntity import fr.gouv.cacem.monitorenv.domain.repositories.IBaseRepository -import fr.gouv.cacem.monitorenv.domain.use_cases.base.CreateOrUpdateBase import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateControlUnitContactUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitContactUTests.kt similarity index 91% rename from backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateControlUnitContactUTests.kt rename to backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitContactUTests.kt index b142d5b380..c9ffe1594d 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateControlUnitContactUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitContactUTests.kt @@ -1,11 +1,10 @@ -package fr.gouv.cacem.monitorenv.domain.use_cases +package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import com.nhaarman.mockitokotlin2.given import com.nhaarman.mockitokotlin2.times import com.nhaarman.mockitokotlin2.verify import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitContactEntity import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitContactRepository -import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.CreateOrUpdateControlUnitContact import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateControlUnitResourceUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitResourceUTests.kt similarity index 92% rename from backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateControlUnitResourceUTests.kt rename to backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitResourceUTests.kt index fb39eb8b69..53c6b38172 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateControlUnitResourceUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitResourceUTests.kt @@ -1,4 +1,4 @@ -package fr.gouv.cacem.monitorenv.domain.use_cases +package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import com.nhaarman.mockitokotlin2.given import com.nhaarman.mockitokotlin2.times @@ -6,7 +6,6 @@ import com.nhaarman.mockitokotlin2.verify import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceEntity import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceType import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitResourceRepository -import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.CreateOrUpdateControlUnitResource import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateControlUnitUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitUTests.kt similarity index 91% rename from backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateControlUnitUTests.kt rename to backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitUTests.kt index e1d47f3a91..021ceda239 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/CreateOrUpdateControlUnitUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitUTests.kt @@ -1,11 +1,10 @@ -package fr.gouv.cacem.monitorenv.domain.use_cases +package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import com.nhaarman.mockitokotlin2.given import com.nhaarman.mockitokotlin2.times import com.nhaarman.mockitokotlin2.verify import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitEntity import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitRepository -import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.CreateOrUpdateControlUnit import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith diff --git a/frontend/cypress/e2e/main_window/control_unit_dialog/resource_list.spec.ts b/frontend/cypress/e2e/main_window/control_unit_dialog/resource_list.spec.ts index 85a4d332f4..af9894b8dc 100644 --- a/frontend/cypress/e2e/main_window/control_unit_dialog/resource_list.spec.ts +++ b/frontend/cypress/e2e/main_window/control_unit_dialog/resource_list.spec.ts @@ -56,7 +56,7 @@ context('Main Window > Control Unit Dialog > Resource List', () => { }) cy.get('p').contains('Ajouter un moyen').should('not.exist') - cy.contains('Avion – Avion').should('be.visible') + cy.contains(createdResourceName).should('be.visible') // ------------------------------------------------------------------------- // Edit