Skip to content

Commit

Permalink
feat: 식단 이미지 업로드 알림 운영시간 검사 추가 (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
dradnats1012 authored Jul 31, 2024
1 parent ded92b7 commit fc5f2ec
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public void saveDiningImage(DiningImageRequest imageRequest) {
boolean isImageExist = diningRepository.existsByDateAndTypeAndImageUrlIsNotNull(dining.getDate(),
dining.getType());

if (!isImageExist) {
LocalDateTime now = LocalDateTime.now(clock);
boolean isOpened = coopShopService.getIsOpened(now, CoopShopType.CAFETERIA, dining.getType());

if (isOpened && !isImageExist) {
eventPublisher.publishEvent(new DiningImageUploadEvent(dining.getImageUrl()));
}

Expand Down
46 changes: 46 additions & 0 deletions src/test/java/in/koreatech/koin/acceptance/DiningApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,50 @@ void checkIsLikedFalse() {
]
""");
}

@Test
@DisplayName("이미지 업로드를 한다. - 품절 알림이 발송된다.")
void checkImageUploadNotification() {
String imageUrl = "https://stage.koreatech.in/image.jpg";
given()
.contentType(ContentType.JSON)
.header("Authorization", "Bearer " + token_준기)
.body(String.format("""
{
"menu_id": "%s",
"image_url": "%s"
}
""", A코너_점심.getId(), imageUrl))
.when()
.patch("/coop/dining/image")
.then()
.statusCode(HttpStatus.OK.value())
.extract();

verify(coopEventListener).onDiningImageUploadRequest(any());
}

@Test
@DisplayName("해당 식사시간 외에 이미지 업로드를 한다. - 품절 알림이 발송되지 않는다.")
void checkImageUploadNotificationAfterHours() {
Dining A코너_저녁 = diningFixture.A코스_저녁(LocalDate.parse("2024-01-15"));
String imageUrl = "https://stage.koreatech.in/image.jpg";

given()
.contentType(ContentType.JSON)
.header("Authorization", "Bearer " + token_준기)
.body(String.format("""
{
"menu_id": "%s",
"image_url": "%s"
}
""", A코너_저녁.getId(), imageUrl))
.when()
.patch("/coop/dining/image")
.then()
.statusCode(HttpStatus.OK.value())
.extract();

verify(coopEventListener, never()).onDiningImageUploadRequest(any());
}
}

0 comments on commit fc5f2ec

Please sign in to comment.