-
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.
[KAN-104] 음식점 유닛테스트 코드 (테스트 커버리지 100%) (#78)
- Loading branch information
1 parent
0b73ceb
commit d8214a3
Showing
8 changed files
with
337 additions
and
51 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
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
54 changes: 54 additions & 0 deletions
54
src/test/kotlin/com/restaurant/be/restaurant/domain/entity/MenuTest.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,54 @@ | ||
package com.restaurant.be.restaurant.domain.entity | ||
|
||
import io.kotest.core.spec.style.DescribeSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class MenuTest : DescribeSpec({ | ||
|
||
describe("Menu entity") { | ||
it("should create a correct Menu instance") { | ||
// Arrange | ||
val menu = Menu( | ||
id = 1L, | ||
restaurantId = 1L, | ||
name = "Pizza", | ||
price = 1500, | ||
description = "Delicious cheese pizza", | ||
isRepresentative = true, | ||
imageUrl = "http://example.com/pizza.jpg" | ||
) | ||
|
||
// Assert | ||
menu.id shouldBe 1L | ||
menu.restaurantId shouldBe 1L | ||
menu.name shouldBe "Pizza" | ||
menu.price shouldBe 1500 | ||
menu.description shouldBe "Delicious cheese pizza" | ||
menu.isRepresentative shouldBe true | ||
menu.imageUrl shouldBe "http://example.com/pizza.jpg" | ||
} | ||
|
||
it("should correctly convert to MenuDto") { | ||
// Arrange | ||
val menu = Menu( | ||
id = 1L, | ||
restaurantId = 1L, | ||
name = "Pizza", | ||
price = 1500, | ||
description = "Delicious cheese pizza", | ||
isRepresentative = true, | ||
imageUrl = "http://example.com/pizza.jpg" | ||
) | ||
|
||
// Act | ||
val menuDto = menu.toDto() | ||
|
||
// Assert | ||
menuDto.name shouldBe "Pizza" | ||
menuDto.price shouldBe 1500 | ||
menuDto.description shouldBe "Delicious cheese pizza" | ||
menuDto.isRepresentative shouldBe true | ||
menuDto.imageUrl shouldBe "http://example.com/pizza.jpg" | ||
} | ||
} | ||
}) |
25 changes: 25 additions & 0 deletions
25
src/test/kotlin/com/restaurant/be/restaurant/domain/entity/RestaurantCategoryTest.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,25 @@ | ||
package com.restaurant.be.restaurant.domain.entity | ||
|
||
import io.kotest.core.spec.style.DescribeSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class RestaurantCategoryTest : DescribeSpec({ | ||
|
||
describe("RestaurantCategory") { | ||
it("should create a correct RestaurantCategory instance") { | ||
// Given | ||
val restaurantCategory = RestaurantCategory( | ||
id = 1L, | ||
restaurantId = 1, | ||
categoryId = 1 | ||
) | ||
|
||
// When | ||
|
||
// Then | ||
restaurantCategory.id shouldBe 1L | ||
restaurantCategory.restaurantId shouldBe 1 | ||
restaurantCategory.categoryId shouldBe 1 | ||
} | ||
} | ||
}) |
24 changes: 24 additions & 0 deletions
24
src/test/kotlin/com/restaurant/be/restaurant/domain/entity/RestaurantLikeTest.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,24 @@ | ||
package com.restaurant.be.restaurant.domain.entity | ||
|
||
import io.kotest.core.spec.style.DescribeSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class RestaurantLikeTest : DescribeSpec({ | ||
describe("RestaurantLike") { | ||
it("should create a correct RestaurantLike instance") { | ||
// Given | ||
val restaurantLike = RestaurantLike( | ||
id = 1L, | ||
restaurantId = 1, | ||
userId = 1 | ||
) | ||
|
||
// When | ||
|
||
// Then | ||
restaurantLike.id shouldBe 1L | ||
restaurantLike.restaurantId shouldBe 1 | ||
restaurantLike.userId shouldBe 1 | ||
} | ||
} | ||
}) |
96 changes: 96 additions & 0 deletions
96
src/test/kotlin/com/restaurant/be/restaurant/domain/entity/RestaurantTest.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,96 @@ | ||
package com.restaurant.be.restaurant.domain.entity | ||
|
||
import io.kotest.core.spec.style.DescribeSpec | ||
import io.kotest.matchers.doubles.shouldBeExactly | ||
import io.kotest.matchers.shouldBe | ||
|
||
class RestaurantTest : DescribeSpec({ | ||
describe("Restaurant entity") { | ||
lateinit var restaurant: Restaurant | ||
|
||
beforeEach { | ||
restaurant = Restaurant( | ||
id = 1L, | ||
name = "Test Restaurant", | ||
originalCategories = "Category1", | ||
reviewCount = 0, | ||
likeCount = 0, | ||
address = "123 Test St", | ||
contactNumber = "123-456-7890", | ||
ratingAvg = 0.0, | ||
representativeImageUrl = "http://example.com/image.jpg", | ||
viewCount = 0, | ||
discountContent = null, | ||
longitude = 0.0, | ||
latitude = 0.0, | ||
naverRatingAvg = 0.0, | ||
naverReviewCount = 0, | ||
menus = mutableListOf() | ||
) | ||
} | ||
context("should create a correct Restaurant instance") { | ||
it("should create a correct Restaurant instance") { | ||
restaurant.id shouldBe 1L | ||
restaurant.name shouldBe "Test Restaurant" | ||
restaurant.originalCategories shouldBe "Category1" | ||
restaurant.reviewCount shouldBe 0 | ||
restaurant.likeCount shouldBe 0 | ||
restaurant.address shouldBe "123 Test St" | ||
restaurant.contactNumber shouldBe "123-456-7890" | ||
restaurant.ratingAvg shouldBeExactly 0.0 | ||
restaurant.representativeImageUrl shouldBe "http://example.com/image.jpg" | ||
restaurant.viewCount shouldBe 0 | ||
restaurant.discountContent shouldBe null | ||
restaurant.longitude shouldBeExactly 0.0 | ||
restaurant.latitude shouldBeExactly 0.0 | ||
restaurant.naverRatingAvg shouldBeExactly 0.0 | ||
restaurant.naverReviewCount shouldBe 0 | ||
restaurant.menus shouldBe mutableListOf() | ||
} | ||
} | ||
|
||
context("createReview") { | ||
it("should update ratingAvg and reviewCount when a new review is added") { | ||
restaurant.createReview(4.0) | ||
restaurant.reviewCount shouldBe 1 | ||
restaurant.ratingAvg shouldBeExactly 4.0 | ||
|
||
restaurant.createReview(2.0) | ||
restaurant.reviewCount shouldBe 2 | ||
restaurant.ratingAvg shouldBeExactly 3.0 | ||
} | ||
} | ||
|
||
context("deleteReview") { | ||
it("should update ratingAvg and reviewCount when a review is deleted") { | ||
// Add initial reviews | ||
restaurant.createReview(4.0) | ||
restaurant.createReview(2.0) | ||
|
||
restaurant.deleteReview(4.0) | ||
restaurant.reviewCount shouldBe 1 | ||
restaurant.ratingAvg shouldBeExactly 2.0 | ||
|
||
restaurant.deleteReview(2.0) | ||
restaurant.reviewCount shouldBe 0 | ||
restaurant.ratingAvg shouldBeExactly 0.0 | ||
} | ||
} | ||
|
||
context("updateReview") { | ||
it("should update ratingAvg when a review is updated") { | ||
// Add initial reviews | ||
restaurant.createReview(4.0) | ||
restaurant.createReview(2.0) | ||
|
||
restaurant.updateReview(2.0, 5.0) | ||
restaurant.reviewCount shouldBe 2 | ||
restaurant.ratingAvg shouldBeExactly 4.5 | ||
|
||
restaurant.updateReview(4.0, 3.0) | ||
restaurant.reviewCount shouldBe 2 | ||
restaurant.ratingAvg shouldBeExactly 4.0 | ||
} | ||
} | ||
} | ||
}) |
63 changes: 63 additions & 0 deletions
63
...m/restaurant/be/restaurant/presentation/controller/dto/common/RestaurantEsDocumentTest.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,63 @@ | ||
package com.restaurant.be.restaurant.presentation.controller.dto.common | ||
|
||
import com.restaurant.be.restaurant.repository.dto.RestaurantEsDocument | ||
import io.kotest.core.spec.style.DescribeSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class RestaurantEsDocumentTest : DescribeSpec({ | ||
describe("MenuDto") { | ||
it("should create a correct RestaurantEsDocument instance") { | ||
// Given | ||
val restaurantEsDocument = RestaurantEsDocument( | ||
id = 1L, | ||
name = "Pizza", | ||
originalCategory = "Italian", | ||
naverReviewCount = 100, | ||
address = "Seoul", | ||
naverRatingAvg = 4.5, | ||
imageUrl = "http://example.com/pizza.jpg", | ||
category = "Italian", | ||
discountContent = "10% off", | ||
menus = mutableListOf(), | ||
reviewCount = 1L, | ||
ratingAvg = 4.5 | ||
) | ||
|
||
// When | ||
|
||
// Then | ||
restaurantEsDocument.id shouldBe 1L | ||
restaurantEsDocument.name shouldBe "Pizza" | ||
restaurantEsDocument.originalCategory shouldBe "Italian" | ||
restaurantEsDocument.naverReviewCount shouldBe 100 | ||
restaurantEsDocument.address shouldBe "Seoul" | ||
restaurantEsDocument.naverRatingAvg shouldBe 4.5 | ||
restaurantEsDocument.imageUrl shouldBe "http://example.com/pizza.jpg" | ||
restaurantEsDocument.category shouldBe "Italian" | ||
restaurantEsDocument.discountContent shouldBe "10% off" | ||
restaurantEsDocument.menus shouldBe mutableListOf() | ||
restaurantEsDocument.reviewCount shouldBe 1L | ||
restaurantEsDocument.ratingAvg shouldBe 4.5 | ||
} | ||
|
||
it("should create a correct MenuDto instance") { | ||
// Given | ||
val menuEsDocument = MenuDto( | ||
name = "Pasta", | ||
price = 15000, | ||
description = "Delicious pasta", | ||
isRepresentative = true, | ||
imageUrl = "http://example.com/pasta.jpg" | ||
) | ||
|
||
// When | ||
|
||
// Then | ||
menuEsDocument.name shouldBe "Pasta" | ||
menuEsDocument.price shouldBe 15000 | ||
menuEsDocument.description shouldBe "Delicious pasta" | ||
menuEsDocument.isRepresentative shouldBe true | ||
menuEsDocument.imageUrl shouldBe "http://example.com/pasta.jpg" | ||
} | ||
} | ||
}) |
Oops, something went wrong.