From 9d23eaa1b8db2dfdaeb1d8c2c99eaf66ad60dc72 Mon Sep 17 00:00:00 2001 From: wow890209 Date: Sat, 4 Nov 2023 11:27:57 +0800 Subject: [PATCH] add test --- .../quest/it/AssignPlayerQuestUsecaseTest.kt | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/utopia-gamification/src/test/kotlin/tw/waterballsa/utopia/utopiagamification/quest/it/AssignPlayerQuestUsecaseTest.kt b/utopia-gamification/src/test/kotlin/tw/waterballsa/utopia/utopiagamification/quest/it/AssignPlayerQuestUsecaseTest.kt index 847df675..a7dbbf8a 100644 --- a/utopia-gamification/src/test/kotlin/tw/waterballsa/utopia/utopiagamification/quest/it/AssignPlayerQuestUsecaseTest.kt +++ b/utopia-gamification/src/test/kotlin/tw/waterballsa/utopia/utopiagamification/quest/it/AssignPlayerQuestUsecaseTest.kt @@ -4,28 +4,25 @@ import org.assertj.core.api.Assertions.* import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired -import org.springframework.data.mongodb.core.MongoTemplate import tw.waterballsa.utopia.utopiagamification.quest.domain.Mission import tw.waterballsa.utopia.utopiagamification.quest.domain.Player import tw.waterballsa.utopia.utopiagamification.quest.domain.exception.AssignedQuestException +import tw.waterballsa.utopia.utopiagamification.quest.domain.quests.QuestIds.Companion.unlockAcademyQuestId import tw.waterballsa.utopia.utopiagamification.quest.usecase.AssignPlayerQuestUsecase import tw.waterballsa.utopia.utopiagamification.repositories.MissionRepository import tw.waterballsa.utopia.utopiagamification.repositories.PlayerRepository import tw.waterballsa.utopia.utopiagamification.repositories.exceptions.NotFoundException import tw.waterballsa.utopia.utopiatestkit.annotations.UtopiaTest -private const val UNLOCK_QUEST_ID = 1 - @UtopiaTest class AssignPlayerQuestUsecaseTest @Autowired constructor( private val assignPlayerQuestUsecase: AssignPlayerQuestUsecase, private val playerRepository: PlayerRepository, - private val missionRepository: MissionRepository, - private val mongoTemplate: MongoTemplate + private val missionRepository: MissionRepository ) { private val playerA = Player("A", "A") - private val request = AssignPlayerQuestUsecase.Request(playerId = playerA.id, questId = UNLOCK_QUEST_ID) + private val request = AssignPlayerQuestUsecase.Request(playerId = playerA.id, questId = unlockAcademyQuestId) @BeforeEach fun setup() { @@ -35,7 +32,7 @@ class AssignPlayerQuestUsecaseTest @Autowired constructor( @Test fun `success assign a unlock quest to player A`() { //Given - val presenter = AssignPlayerQuestTestPresenter(playerA.id, UNLOCK_QUEST_ID) + val presenter = AssignPlayerQuestTestPresenter(playerA.id, unlockAcademyQuestId) //when assertThatNoException().isThrownBy { @@ -47,7 +44,7 @@ class AssignPlayerQuestUsecaseTest @Autowired constructor( assertThat(missions).hasSize(1) val mission = missions.first() assertThat(mission.player.id).isEqualTo(playerA.id) - assertThat(mission.quest.id).isEqualTo(UNLOCK_QUEST_ID) + assertThat(mission.quest.id).isEqualTo(unlockAcademyQuestId) assertThat(presenter.isExecuted).isTrue } @@ -55,7 +52,7 @@ class AssignPlayerQuestUsecaseTest @Autowired constructor( fun `given playerA has first quest when playerA assign first quest then playerA can't get same quest repeatedly`() { //given - val presenter = AssignPlayerQuestTestPresenter(playerA.id, UNLOCK_QUEST_ID) + val presenter = AssignPlayerQuestTestPresenter(playerA.id, unlockAcademyQuestId) //when assertThatNoException().isThrownBy { @@ -72,11 +69,12 @@ class AssignPlayerQuestUsecaseTest @Autowired constructor( fun `when assign a quest to the non-exist player, then should be fail`() { //given val nonExistPlayerId = "B" - val presenter = AssignPlayerQuestTestPresenter(nonExistPlayerId, UNLOCK_QUEST_ID) + val failRequest = AssignPlayerQuestUsecase.Request(playerId = nonExistPlayerId, questId = unlockAcademyQuestId) + val presenter = AssignPlayerQuestTestPresenter(nonExistPlayerId, unlockAcademyQuestId) //then assertThatExceptionOfType(NotFoundException::class.java).isThrownBy { - assignPlayerQuestUsecase.execute(request, presenter) + assignPlayerQuestUsecase.execute(failRequest, presenter) } }