Skip to content

Commit

Permalink
test(AdminAcceptanceTest): 관리자의 공지 전송 인수테스트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
zbqmgldjfh committed May 19, 2024
1 parent 2871eea commit 376e58b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kustacks.kuring.acceptance;

import com.kustacks.kuring.admin.adapter.in.web.dto.RealNotificationRequest;
import com.kustacks.kuring.admin.adapter.in.web.dto.TestNotificationRequest;
import com.kustacks.kuring.support.IntegrationTestSupport;
import io.restassured.RestAssured;
import io.restassured.response.ExtractableResponse;
Expand All @@ -15,8 +16,6 @@
import static com.kustacks.kuring.acceptance.AuthStep.로그인_되어_있음;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;

@DisplayName("인수 : 관리자")
class AdminAcceptanceTest extends IntegrationTestSupport {
Expand Down Expand Up @@ -48,7 +47,6 @@ void role_root_admin_search_feedbacks() {
@Test
void role_root_admin_create_test_notification() {
// given
doNothing().when(firebaseNotificationService).sendNotificationByAdmin(any());
String accessToken = 로그인_되어_있음(ADMIN_LOGIN_ID, ADMIN_PASSWORD);

// when
Expand All @@ -57,7 +55,38 @@ void role_root_admin_create_test_notification() {
.header("Authorization", "Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.body(new RealNotificationRequest("테스트 공지", "테스트 공지입니다", "https://www.naver.com", ADMIN_PASSWORD))
.body(new TestNotificationRequest("bachelor", "테스트 공지입니다", "1234"))
.when().post("/api/v2/admin/notices/dev")
.then().log().all()
.extract();

// then
assertAll(
() -> assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()),
() -> assertThat(response.jsonPath().getInt("code")).isEqualTo(200),
() -> assertThat(response.jsonPath().getString("message")).isEqualTo("테스트 공지 생성에 성공하였습니다"),
() -> assertThat(response.jsonPath().getString("data")).isNull()
);
}

/**
* given : 사전에 등록된 어드민이 있다
* when : 실제 공지를 발송하면
* then : 성공적으로 발송된다.
*/
@DisplayName("[v2] 실제 공지 발송")
@Test
void role_root_admin_create_real_notification() {
// given
String accessToken = 로그인_되어_있음(ADMIN_LOGIN_ID, ADMIN_PASSWORD);

// when
var response = RestAssured
.given().log().all()
.header("Authorization", "Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.body(new RealNotificationRequest("real 공지", "real 공지입니다", "https://www.naver.com", ADMIN_PASSWORD))
.when().post("/api/v2/admin/notices/prod")
.then().log().all()
.extract();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.kustacks.kuring.admin.application.port.in.dto.TestNotificationCommand;
import com.kustacks.kuring.admin.application.service.AdminCommandService;
import com.kustacks.kuring.auth.context.Authentication;
import com.kustacks.kuring.message.application.port.in.dto.AdminNotificationCommand;
import com.kustacks.kuring.message.application.port.in.dto.AdminTestNotificationCommand;
import com.kustacks.kuring.notice.domain.CategoryName;
import com.kustacks.kuring.support.IntegrationTestSupport;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -18,7 +16,6 @@

import static com.kustacks.kuring.admin.domain.AdminRole.ROLE_ROOT;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;

@DisplayName("[단위] 어드민 이벤트 리스너 테스트")
class MessageAdminEventListenerTest extends IntegrationTestSupport {
Expand All @@ -33,8 +30,6 @@ class MessageAdminEventListenerTest extends IntegrationTestSupport {
@Test
void sendNotificationEvent() {
// given
doNothing().when(firebaseNotificationService).sendNotificationByAdmin(any(AdminNotificationCommand.class));

RealNotificationCommand command = new RealNotificationCommand(
"test title",
"test body",
Expand All @@ -54,8 +49,6 @@ void sendNotificationEvent() {
@Test
void sendTestNotificationEvent() {
// given
doNothing().when(firebaseNotificationService).sendTestNotificationByAdmin(any(AdminTestNotificationCommand.class));

TestNotificationCommand command = new TestNotificationCommand(
CategoryName.STUDENT.getName(),
"test body",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.kustacks.kuring.support;


import com.kustacks.kuring.message.application.service.FirebaseNotificationService;
import com.kustacks.kuring.message.application.service.FirebaseSubscribeService;
import io.restassured.RestAssured;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -21,9 +20,6 @@ public class IntegrationTestSupport {
@MockBean
protected FirebaseSubscribeService firebaseSubscribeService;

@MockBean
protected FirebaseNotificationService firebaseNotificationService;

@LocalServerPort
int port;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import static org.assertj.core.api.Assertions.tuple;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;


Expand Down Expand Up @@ -56,7 +54,6 @@ void notice_scrap_async_test() throws InterruptedException {
// given
doReturn(createNoticesFixture()).when(scrapperTemplate).scrap(any(), any());
doReturn(createLibraryFixture()).when(libraryNoticeApiClient).request(any());
doNothing().when(firebaseNotificationService).sendNotifications(anyList());

// when
kuisHomepageNoticeUpdater.update();
Expand Down

0 comments on commit 376e58b

Please sign in to comment.