Skip to content

Commit

Permalink
test: create recruitment fixture
Browse files Browse the repository at this point in the history
Co-authored-by: kbsat <[email protected]>
  • Loading branch information
dongho108 and kbsat committed Aug 7, 2022
1 parent 5e58f43 commit 856f534
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 1 deletion.
80 changes: 80 additions & 0 deletions src/test/kotlin/apply/acceptance/fixture/RecruitmentFixture.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package apply.acceptance.fixture

import apply.application.RecruitmentResponse
import apply.application.TermResponse
import apply.ui.api.ApiResponse
import io.restassured.RestAssured
import io.restassured.http.ContentType
import io.restassured.mapper.TypeRef
import java.time.LocalDateTime

data class RecruitmentRequest(
var title: String,
var term: TermResponse,
var startDateTime: LocalDateTime,
var endDateTime: LocalDateTime,
var recruitable: Boolean,
var hidden: Boolean,
var recruitmentItems: List<RecruitmentItemRequest>,
)

class RecruitmentBuilder {
var title: String = "웹 백엔드 3기"
var termId: Long = 0L
var startDateTime: LocalDateTime = LocalDateTime.now().minusYears(1)
var endDateTime: LocalDateTime = LocalDateTime.now().plusYears(1)
var recruitable: Boolean = false
var hidden: Boolean = true
var recruitmentItems: List<RecruitmentItemRequest> = recruitmentItems {
recruitmentItem()
recruitmentItem {
title = "프로그래밍 학습 과정과 현재 자신이 생각하는 역량은?"
position = 2
maximumLength = 1500
description = "우아한테크코스는..."
}
recruitmentItem {
title = "프로그래밍 학습 과정과 현재 자신이 생각하는 역량은?"
position = 3
maximumLength = 2000
description = "우아한테크코스는..."
}
}

fun build(): RecruitmentResponse {
val term = when (termId) {
0L -> term()
else -> getTermById(termId)
}

val recruitmentRequest = RecruitmentRequest(
title,
term,
startDateTime,
endDateTime,
recruitable,
hidden,
recruitmentItems
)

return postRecruitment(recruitmentRequest)
}

private fun postRecruitment(recruitmentRequest: RecruitmentRequest): RecruitmentResponse {
return RestAssured.given().log().all()
.contentType(ContentType.JSON)
.body(recruitmentRequest)
.`when`()
.post("/api/recruitments")
.`as`(object : TypeRef<ApiResponse<RecruitmentResponse>>() {})
.body as RecruitmentResponse
}
}

fun recruitment(builder: RecruitmentBuilder.() -> Unit): RecruitmentResponse {
return RecruitmentBuilder().apply(builder).build()
}

fun recruitment(): RecruitmentResponse {
return RecruitmentBuilder().build()
}
39 changes: 39 additions & 0 deletions src/test/kotlin/apply/acceptance/fixture/RecruitmentItemFixture.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package apply.acceptance.fixture

class RecruitmentItemRequest(
val title: String,
val position: Int,
val maximumLength: Int,
val description: String
)

class RecruitmentItemBuilder {
var title: String = "프로그래밍 학습 과정과 현재 자신이 생각하는 역량은?"
var position: Int = 1
var maximumLength: Int = 1000
var description: String = "우아한테크코스는..."

fun build(): RecruitmentItemRequest {
return RecruitmentItemRequest(title, position, maximumLength, description)
}
}

class RecruitmentItemsBuilder {
private var recruitmentItems = mutableListOf<RecruitmentItemRequest>()

fun recruitmentItem(builder: RecruitmentItemBuilder.() -> Unit) {
recruitmentItems.add(RecruitmentItemBuilder().apply(builder).build())
}

fun recruitmentItem() {
recruitmentItems.add(RecruitmentItemBuilder().build())
}

fun build(): List<RecruitmentItemRequest> {
return recruitmentItems
}
}

fun recruitmentItems(builder: RecruitmentItemsBuilder.() -> Unit): List<RecruitmentItemRequest> {
return RecruitmentItemsBuilder().apply(builder).build()
}
12 changes: 11 additions & 1 deletion src/test/kotlin/apply/acceptance/fixture/TermFixture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@ class TermBuilder {
return RestAssured.given().log().all()
.contentType(ContentType.JSON)
.body(termRequest)
.`when`().log().all()
.`when`()
.post("/api/terms")
.`as`(object : TypeRef<ApiResponse<TermResponse>>() {})
.body as TermResponse
}
}

fun getTermById(termId: Long): TermResponse {
val term = RestAssured.given()
.get("/api/terms/$termId")
.then()
.extract()
.`as`(object : TypeRef<ApiResponse<TermResponse>>() {})
.body as TermResponse
return TermResponse(term.id, term.name)
}

fun term(builder: TermBuilder.() -> Unit): TermResponse {
return TermBuilder().apply(builder).build()
}
Expand Down

0 comments on commit 856f534

Please sign in to comment.