Skip to content

Commit

Permalink
Fix missing var in control unit dialog e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Oct 24, 2023
1 parent 2198d23 commit 8d5549c
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 11 deletions.
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)
}
}
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
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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.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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d5549c

Please sign in to comment.