From 3ab484ff872da3d7fb74e6bf71acd19997bec6fe Mon Sep 17 00:00:00 2001 From: doji Date: Sun, 1 Oct 2023 17:23:39 +0900 Subject: [PATCH] =?UTF-8?q?store=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mjucow/eatda/common/vo/DayOfWeek.kt | 9 +- .../mjucow/eatda/domain/store/entity/Store.kt | 2 +- .../eatda/domain/store/entity/StoreTest.kt | 111 +++++++++++++++++- .../store/entity/objectmother/ObjectMother.kt | 4 +- .../entity/objectmother/StoreHoursMother.kt | 12 +- .../store/entity/objectmother/StoreMother.kt | 20 ++-- 6 files changed, 135 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/com/mjucow/eatda/common/vo/DayOfWeek.kt b/src/main/kotlin/com/mjucow/eatda/common/vo/DayOfWeek.kt index 59f8db6..af4017e 100644 --- a/src/main/kotlin/com/mjucow/eatda/common/vo/DayOfWeek.kt +++ b/src/main/kotlin/com/mjucow/eatda/common/vo/DayOfWeek.kt @@ -25,11 +25,18 @@ enum class DayOfWeek( /** * 객체가 인자의 전 요일인지 확인합니다 */ - fun isPrevtDayOf(dayOfWeek: DayOfWeek): Boolean { + fun isPrevDayOf(dayOfWeek: DayOfWeek): Boolean { return ((ordinal + 1) % VALUES.size) == dayOfWeek.ordinal } companion object { val VALUES = entries.toTypedArray() + + fun of(ordinal: Int): DayOfWeek { + if (ordinal + VALUES.size < 0) { + throw IllegalArgumentException() + } + return VALUES[(ordinal + VALUES.size) % VALUES.size] + } } } diff --git a/src/main/kotlin/com/mjucow/eatda/domain/store/entity/Store.kt b/src/main/kotlin/com/mjucow/eatda/domain/store/entity/Store.kt index 893d347..1263d16 100644 --- a/src/main/kotlin/com/mjucow/eatda/domain/store/entity/Store.kt +++ b/src/main/kotlin/com/mjucow/eatda/domain/store/entity/Store.kt @@ -86,7 +86,7 @@ class Store() : BaseEntity() { // 같은 날에 시간이 겹치는 경우, 날짜는 다르지만 새벽 영업(36시간 제도)으로 시간이 겹치는 경우 (it.dayOfWeek == newHours.dayOfWeek && (it.openAt <= newHours.closeAt || newHours.openAt <= it.closeAt)) || (it.dayOfWeek.isNextDayOf(newHours.dayOfWeek) && (newHours.openAt + StoreHours.ONE_DAY_MINUTE) <= it.closeAt) || - (it.dayOfWeek.isPrevtDayOf(newHours.dayOfWeek) && (it.openAt + StoreHours.ONE_DAY_MINUTE) <= newHours.closeAt) + (it.dayOfWeek.isPrevDayOf(newHours.dayOfWeek) && (it.openAt + StoreHours.ONE_DAY_MINUTE) <= newHours.closeAt) } if (result.isNotEmpty()) { throw IllegalArgumentException() diff --git a/src/test/kotlin/com/mjucow/eatda/domain/store/entity/StoreTest.kt b/src/test/kotlin/com/mjucow/eatda/domain/store/entity/StoreTest.kt index af1fb42..5415b8f 100644 --- a/src/test/kotlin/com/mjucow/eatda/domain/store/entity/StoreTest.kt +++ b/src/test/kotlin/com/mjucow/eatda/domain/store/entity/StoreTest.kt @@ -1,5 +1,6 @@ package com.mjucow.eatda.domain.store.entity +import com.mjucow.eatda.common.vo.DayOfWeek import com.mjucow.eatda.domain.store.entity.objectmother.StoreHoursMother import com.mjucow.eatda.domain.store.entity.objectmother.StoreMother import org.assertj.core.api.Assertions.assertThat @@ -210,9 +211,79 @@ class StoreTest { ).isTrue() } + @DisplayName("새로운 이미지 주소가 빈 값일 경우 예외를 던진다") + @ParameterizedTest + @EmptySource + fun throwExceptionWhenNewImageAddressIsEmpty(newImageAddress: String) { + // given + val store = StoreMother.create() + + // when + val throwable = catchThrowable { store.imageAddress = newImageAddress } + + // then + assertThat(throwable).isInstanceOf(RuntimeException::class.java) + } + + @DisplayName("새로운 주소가 최소 길이 이상일 경우 에외를 던진다") + @Test + fun throwExceptionWhenNewImageAddressLengthGreaterThanMaxLength() { + // given + val store = StoreMother.create() + val newImageAddress = "x".repeat(Store.MAX_IMAGE_ADDRESS_LENGTH + 1) + + // when + val throwable = catchThrowable { store.imageAddress = newImageAddress } + + // then + assertThat(throwable).isInstanceOf(RuntimeException::class.java) + } + + @DisplayName("새로운 연락처를 추가할 수 있다") + @Test + fun addNewPhoneNumber() { + // given + val store = StoreMother.createWithId() + val newPhoneNumber = StoreMother.PHONE_NUMBER + + // when + store.phoneNumber = newPhoneNumber + + // then + assertThat(store.phoneNumber).isEqualTo(newPhoneNumber) + } + + @DisplayName("새로운 이미지 주소를 추가할 수 있다") + @Test + fun addNewImageAddress() { + // given + val store = StoreMother.createWithId() + val newImageAddress = StoreMother.IMAGE_ADDRESS + + // when + store.imageAddress = newImageAddress + + // then + assertThat(store.imageAddress).isEqualTo(newImageAddress) + } + + @DisplayName("새로운 위치 정보를 추가할 수 있다") + @Test + fun addNewLocation() { + // given + val store = StoreMother.createWithId() + val newLocation = StoreMother.LOCATION + + // when + store.location = newLocation + + // then + assertThat(store.location).isEqualTo(newLocation) + } + @DisplayName("이미 존재하는 시간과 겹친다면 운영시간은 추가되지 않는다: 같은 날짜") @Test - fun throwExceptionWhenNewStoreHoursOverlapTime() { + fun throwExceptionWhenNewSameDayOfWeekStoreHoursOverlapTime() { // given val storeHours = StoreHoursMother.create() val store = StoreMother.create { it.addStoreHour(storeHours) } @@ -223,4 +294,42 @@ class StoreTest { // then assertThat(throwable).isNotNull() } + + @DisplayName("이미 존재하는 시간과 겹친다면 운영시간은 추가되지 않는다: 하루 전 새벽 운영") + @Test + fun throwExceptionWhenNewPrevDayOfWeekStoreHoursOverlapTime() { + // given + val currentStoreHours = StoreHoursMother.create() + val store = StoreMother.create(autoFill = true) { it.addStoreHour(currentStoreHours) } + val newStoreHours = StoreHours( + DayOfWeek.of(currentStoreHours.dayOfWeek.ordinal - 1), + openAt = StoreHours.MIN_TIME_MINUTE, + closeAt = currentStoreHours.openAt + StoreHours.ONE_DAY_MINUTE + 1 + ) + + // when + val throwable = catchThrowable { store.addStoreHour(newStoreHours) } + + // then + assertThat(throwable).isNotNull() + } + + @DisplayName("이미 존재하는 시간과 겹친다면 운영시간은 추가되지 않는다: 기존 시간이 새벽운영") + @Test + fun throwExceptionWhenNewNextDayOfWeekStoreHoursOverlapTime() { + // given + val currentStoreHours = StoreHoursMother.create { it.closeAt = StoreHours.MAX_TIME_MINUTE } + val store = StoreMother.create { it.addStoreHour(currentStoreHours) } + val newStoreHours = StoreHours( + DayOfWeek.of(currentStoreHours.dayOfWeek.ordinal + 1), + openAt = currentStoreHours.closeAt - StoreHours.ONE_DAY_MINUTE, + closeAt = StoreHours.MAX_TIME_MINUTE + ) + + // when + val throwable = catchThrowable { store.addStoreHour(newStoreHours) } + + // then + assertThat(throwable).isNotNull() + } } diff --git a/src/test/kotlin/com/mjucow/eatda/domain/store/entity/objectmother/ObjectMother.kt b/src/test/kotlin/com/mjucow/eatda/domain/store/entity/objectmother/ObjectMother.kt index 4aa5e41..ace4f85 100644 --- a/src/test/kotlin/com/mjucow/eatda/domain/store/entity/objectmother/ObjectMother.kt +++ b/src/test/kotlin/com/mjucow/eatda/domain/store/entity/objectmother/ObjectMother.kt @@ -6,6 +6,6 @@ abstract class ObjectMother { return instance.apply(apply) } - abstract fun createFillInstance(): T - abstract fun createDefaultInstance(): T + protected abstract fun createFillInstance(): T + protected abstract fun createDefaultInstance(): T } diff --git a/src/test/kotlin/com/mjucow/eatda/domain/store/entity/objectmother/StoreHoursMother.kt b/src/test/kotlin/com/mjucow/eatda/domain/store/entity/objectmother/StoreHoursMother.kt index ef5029e..120949f 100644 --- a/src/test/kotlin/com/mjucow/eatda/domain/store/entity/objectmother/StoreHoursMother.kt +++ b/src/test/kotlin/com/mjucow/eatda/domain/store/entity/objectmother/StoreHoursMother.kt @@ -5,14 +5,14 @@ import com.mjucow.eatda.domain.store.entity.StoreHours object StoreHoursMother : EntityMother() { override fun createDefaultInstance() = StoreHours( - dayOfWeek = DayOfWeek.MON, - openAt = StoreHours.MIN_TIME_MINUTE, - closeAt = StoreHours.ONE_DAY_MINUTE + DayOfWeek.MON, + StoreHours.MIN_TIME_MINUTE, + StoreHours.ONE_DAY_MINUTE ) override fun createFillInstance() = StoreHours( - dayOfWeek = DayOfWeek.MON, - openAt = StoreHours.MIN_TIME_MINUTE, - closeAt = StoreHours.MAX_TIME_MINUTE + DayOfWeek.MON, + StoreHours.MIN_TIME_MINUTE, + StoreHours.MAX_TIME_MINUTE ) } diff --git a/src/test/kotlin/com/mjucow/eatda/domain/store/entity/objectmother/StoreMother.kt b/src/test/kotlin/com/mjucow/eatda/domain/store/entity/objectmother/StoreMother.kt index b1c1a13..9e7a60e 100644 --- a/src/test/kotlin/com/mjucow/eatda/domain/store/entity/objectmother/StoreMother.kt +++ b/src/test/kotlin/com/mjucow/eatda/domain/store/entity/objectmother/StoreMother.kt @@ -8,22 +8,18 @@ object StoreMother : EntityMother() { const val NAME = "명지대학교" const val ADDRESS = "서울특별시 서대문구 거북골로 34" const val DISPLAY_NAME = "띵지대" + const val IMAGE_ADDRESS = "/eatda/public/store/232D8241-C6A9-4AD9-B0EA-56F6DD24BADF.jpg" val PHONE_NUMBER = PhoneNumber("02-300-1656") val LOCATION = Point(latitude = 37.5802219, longitude = 126.9226047) - override fun createDefaultInstance() = Store( - name = NAME, - address = ADDRESS, - displayName = null, - phoneNumber = null, - location = null - ) + override fun createDefaultInstance() = Store(NAME, ADDRESS) override fun createFillInstance() = Store( - name = NAME, - address = ADDRESS, - displayName = DISPLAY_NAME, - phoneNumber = PHONE_NUMBER, - location = LOCATION + NAME, + ADDRESS, + DISPLAY_NAME, + PHONE_NUMBER, + IMAGE_ADDRESS, + LOCATION ) }