Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusLevang committed Feb 29, 2024
1 parent c1cc457 commit 76934ce
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ fun CollectionsModel.getFirstObject(): CollectionsObject? {
return this.getObjects()?.first()
}

fun CollectionsModel.getFirstId(): String? {
return this.getObjects()?.first()?.priRef
}

// CollectionsObject
fun CollectionsObject.isSerial(): Boolean {
return this.workTypeList?.first()?.first()?.text == CollectionsDescriptionType.SERIAL.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class CollectionsModelMockData {
languageList = listOf(CollectionsLanguage("nob")),
placeOfPublicationList = listOf("Brakka"),
partsList = null,
workTypeList = null,
workTypeList = collectionsWorkTypeListSerialMock,
alternativeNumberList = null
)
)
Expand Down Expand Up @@ -384,6 +384,30 @@ class CollectionsModelMockData {
)
)

// As A Without parts
val collectionsModelMockManifestationB = CollectionsModel(
adlibJson = CollectionsRecordList(
recordList = listOf(
CollectionsObject(
priRef = "24",
titleList = listOf(CollectionsTitle(title = "Bikubeavisen 1999.12.24")),
recordTypeList = collectionsRecordTypeListManifestMock,
formatList = null,
partOfList = listOf(collectionsPartOfObjectMockYearWorkA),
subMediumList = null,
mediumList = null,
datingList = null,
publisherList = null,
languageList = null,
placeOfPublicationList = null,
partsList = null,
workTypeList = null,
alternativeNumberList = listOf(CollectionsAlternativeNumber("URN", "bikubeavisen_null_null_19991224_1_1_1"))
)
)
)
)

val collectionsModelMockYearWorkA = CollectionsModel(
adlibJson = CollectionsRecordList(
recordList = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlinx.serialization.json.Json
import no.nb.bikube.catalogue.collections.CollectionsModelMockData.Companion.collectionsModelEmptyRecordListMock
import no.nb.bikube.catalogue.collections.CollectionsModelMockData.Companion.collectionsModelMockItemA
import no.nb.bikube.catalogue.collections.CollectionsModelMockData.Companion.collectionsModelMockManifestationA
import no.nb.bikube.catalogue.collections.CollectionsModelMockData.Companion.collectionsModelMockManifestationB
import no.nb.bikube.catalogue.collections.CollectionsModelMockData.Companion.collectionsModelMockTitleA
import no.nb.bikube.catalogue.collections.CollectionsModelMockData.Companion.collectionsModelMockTitleB
import no.nb.bikube.catalogue.collections.CollectionsModelMockData.Companion.collectionsModelMockTitleC
Expand All @@ -19,10 +20,10 @@ import no.nb.bikube.catalogue.collections.enum.CollectionsDescriptionType
import no.nb.bikube.catalogue.collections.enum.CollectionsFormat
import no.nb.bikube.catalogue.collections.enum.CollectionsRecordType
import no.nb.bikube.catalogue.collections.model.*
import no.nb.bikube.catalogue.collections.repository.CollectionsRepository
import no.nb.bikube.core.model.Item
import no.nb.bikube.core.model.inputDto.ItemInputDto
import no.nb.bikube.newspaper.NewspaperMockData.Companion.newspaperItemMockCValidForCreation
import no.nb.bikube.catalogue.collections.repository.CollectionsRepository
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand All @@ -46,10 +47,10 @@ class ItemControllerIntegrationTest (
@MockkBean
private lateinit var collectionsRepository: CollectionsRepository

private val titleId = "1"
private val yearWorkId = "2"
private val manifestationId = "3"
private val itemId = "4"
private val titleId = collectionsModelMockTitleA.getFirstId()!!
private val yearWorkId = collectionsModelMockYearWorkA.getFirstId()!!
private val manifestationId = collectionsModelMockManifestationB.getFirstId()!!
private val itemId = collectionsModelMockItemA.getFirstId()!!

private fun createItem(item: ItemInputDto): ResponseSpec {
return webClient
Expand Down Expand Up @@ -77,7 +78,7 @@ class ItemControllerIntegrationTest (
val dto = json.decodeFromString<DtoMock>(encodedBody.captured)
when (dto.recordType) {
CollectionsRecordType.ITEM.value -> Mono.just(collectionsModelMockItemA)
CollectionsRecordType.MANIFESTATION.value -> Mono.just(collectionsModelMockManifestationA)
CollectionsRecordType.MANIFESTATION.value -> Mono.just(collectionsModelMockManifestationB)
CollectionsRecordType.WORK.value -> {
if (dto.descriptionType == CollectionsDescriptionType.SERIAL.value) {
Mono.just(collectionsModelMockTitleA)
Expand Down Expand Up @@ -166,8 +167,8 @@ class ItemControllerIntegrationTest (

@Test
fun `post-newspapers-items endpoint should create year work and manifestation if year work is not found`() {
every { collectionsRepository.getSingleCollectionsModel(titleId) } returns Mono.just(collectionsModelMockTitleB.copy())
every { collectionsRepository.getSingleCollectionsModel(yearWorkId) } returns Mono.just(collectionsModelMockYearWorkA.copy())
val mockTitle = Mono.just(collectionsModelMockTitleB.copy())
every { collectionsRepository.getSingleCollectionsModel(any()) } returnsMany listOf(mockTitle, mockTitle, Mono.just(collectionsModelMockItemA.copy()))

createItem(newspaperItemMockCValidForCreation)
.expectStatus().isCreated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import no.nb.bikube.catalogue.collections.CollectionsModelMockData.Companion.col
import no.nb.bikube.catalogue.collections.CollectionsModelMockData.Companion.collectionsTermModelMockLocationB
import no.nb.bikube.catalogue.collections.CollectionsModelMockData.Companion.collectionsTermModelWithEmptyRecordListA
import no.nb.bikube.catalogue.collections.enum.CollectionsDatabase
import no.nb.bikube.catalogue.collections.repository.CollectionsRepository
import no.nb.bikube.core.model.Title
import no.nb.bikube.core.model.inputDto.TitleInputDto
import no.nb.bikube.newspaper.NewspaperMockData.Companion.newspaperTitleInputDtoMockA
import no.nb.bikube.newspaper.NewspaperMockData.Companion.newspaperTitleInputDtoMockB
import no.nb.bikube.newspaper.NewspaperMockData.Companion.newspaperTitleMockB
import no.nb.bikube.catalogue.collections.repository.CollectionsRepository
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
Expand Down Expand Up @@ -54,6 +54,7 @@ class TitleControllerIntegrationTest (
webClient = webClient.mutate().responseTimeout(Duration.ofSeconds(1000)).build()

every { collectionsRepository.getSingleCollectionsModel(titleId) } returns Mono.just(collectionsModelEmptyRecordListMock.copy())
every { collectionsRepository.getSingleCollectionsModel("2") } returns Mono.just(collectionsModelMockTitleE.copy())
every { collectionsRepository.createTextsRecord(any()) } returns Mono.just(collectionsModelMockTitleE.copy())
every { collectionsRepository.searchPublisher(any()) } returns Mono.just(collectionsNameModelMockA.copy())
every { collectionsRepository.searchPublisherPlace(any()) } returns Mono.just(collectionsTermModelMockLocationB.copy())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class NewspaperServiceTest(
@Test
fun `createTitle should return Title object with default values from Title with only name and materialType`() {
every { collectionsRepository.createTextsRecord(any()) } returns Mono.just(collectionsModelMockTitleE)
every { collectionsRepository.getSingleCollectionsModel(any()) } returns Mono.just(collectionsModelMockTitleE)

val body = newspaperTitleInputDtoMockB.copy()

Expand Down Expand Up @@ -471,6 +472,8 @@ class NewspaperServiceTest(
@Test
fun `createTitle should return correctly mapped record`() {
every { collectionsRepository.createTextsRecord(any()) } returns Mono.just(collectionsModelMockTitleE)
every { collectionsRepository.getSingleCollectionsModel(any()) } returns Mono.just(collectionsModelMockTitleE)

newspaperService.createNewspaperTitle(newspaperTitleInputDtoMockB.copy())
.test()
.expectSubscription()
Expand All @@ -481,6 +484,7 @@ class NewspaperServiceTest(
@Test
fun `createTitle should correctly encode the title object sent to json string`() {
every { collectionsRepository.createTextsRecord(any()) } returns Mono.just(collectionsModelMockTitleE)
every { collectionsRepository.getSingleCollectionsModel(any()) } returns Mono.just(collectionsModelMockTitleE)

newspaperService.createNewspaperTitle(newspaperTitleInputDtoMockB.copy())
.test()
Expand Down

0 comments on commit 76934ce

Please sign in to comment.