-
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.
feat: 오프라인 출석 코드 refresh 기능 추가 (#121)
* feat: 세션 수정 API에 누락된 code response 추가 * feat: 오프라인 출석 코드 refresh 기능 추가 * test: 오프라인 출석 코드 refresh 기능 테스트 코드 작성
- Loading branch information
Showing
6 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
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
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/com/depromeet/makers/domain/usecase/RefreshSessionCode.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,18 @@ | ||
package com.depromeet.makers.domain.usecase | ||
|
||
import com.depromeet.makers.domain.gateway.SessionGateway | ||
import com.depromeet.makers.domain.model.Session | ||
|
||
class RefreshSessionCode( | ||
val sessionGateway: SessionGateway, | ||
) : UseCase<String, Session> { | ||
override fun execute(sessionId: String): Session { | ||
val session = sessionGateway.getById(sessionId) | ||
|
||
return sessionGateway.save( | ||
session.update( | ||
code = Session.generateCode(), | ||
), | ||
) | ||
} | ||
} |
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
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
58 changes: 58 additions & 0 deletions
58
src/test/kotlin/com/depromeet/makers/domain/usecase/RefreshSessionCodeTest.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,58 @@ | ||
package com.depromeet.makers.domain.usecase | ||
|
||
import com.depromeet.makers.domain.gateway.SessionGateway | ||
import com.depromeet.makers.domain.model.Place | ||
import com.depromeet.makers.domain.model.Session | ||
import com.depromeet.makers.domain.model.SessionType | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.shouldNotBe | ||
import io.kotest.matchers.string.shouldBeInteger | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import java.time.LocalDateTime | ||
|
||
class RefreshSessionCodeTest : | ||
BehaviorSpec({ | ||
Given("세션 코드를 갱신할 때") { | ||
val sessionGateway = mockk<SessionGateway>() | ||
val refreshSessionCode = RefreshSessionCode(sessionGateway = sessionGateway) | ||
|
||
val previousCode = "previousCode" | ||
val mockSession = | ||
Session( | ||
sessionId = "123e4567-e89b-12d3-a456-426614174000", | ||
generation = 15, | ||
week = 1, | ||
title = "세션 제목", | ||
description = "세션 설명", | ||
startTime = LocalDateTime.of(2030, 10, 1, 10, 0), | ||
sessionType = SessionType.OFFLINE, | ||
place = | ||
Place.newPlace( | ||
name = "테스트 장소", | ||
address = "전북 익산시 부송동 100", | ||
longitude = 35.9418, | ||
latitude = 126.9544, | ||
), | ||
code = previousCode, | ||
) | ||
|
||
every { sessionGateway.getById(any()) } returns mockSession | ||
every { sessionGateway.save(any()) } returns mockSession.update(code = Session.generateCode()) | ||
|
||
When("execute가 실행되면") { | ||
val result = | ||
refreshSessionCode.execute( | ||
sessionId = mockSession.sessionId, | ||
) | ||
|
||
Then("세션 코드가 갱신된 세션이 반환된다") { | ||
result.code shouldNotBe previousCode | ||
result.code shouldNotBe null | ||
result.code.shouldBeInteger() | ||
result.code!!.length shouldBe 4 | ||
} | ||
} | ||
} | ||
}) |