-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix missing var in control unit dialog e2e test
- Loading branch information
1 parent
2198d23
commit 8d5549c
Showing
8 changed files
with
126 additions
and
11 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...n/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...r/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministrationUTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
...ses/CreateOrUpdateAdministrationUTests.kt → ...ion/CreateOrUpdateAdministrationUTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...ain/use_cases/CreateOrUpdateBaseUTests.kt → ...se_cases/base/CreateOrUpdateBaseUTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...CreateOrUpdateControlUnitContactUTests.kt → ...CreateOrUpdateControlUnitContactUTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...reateOrUpdateControlUnitResourceUTests.kt → ...reateOrUpdateControlUnitResourceUTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
..._cases/CreateOrUpdateControlUnitUTests.kt → ...olUnit/CreateOrUpdateControlUnitUTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters