Skip to content

Commit

Permalink
docs(#7): 에러 발생시 응답 문서화
Browse files Browse the repository at this point in the history
- FCM 토큰 저장 및 삭제에서 에러가 발생했을때 응답을 문서화했어요.
  • Loading branch information
jyj1289 committed Nov 22, 2024
1 parent 3f3afdf commit 6c18189
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/docs/asciidoc/fcm-token.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ include::{snippets}/fcm-token-controller-test/fcm_토큰을_저장한다/http-re
===== 정상 응답
include::{snippets}/fcm-token-controller-test/fcm_토큰을_저장한다/http-response.adoc[]

===== 해당 유저가 해당 토큰을 이미 가지고 있을 경우
include::{snippets}/fcm-token-controller-test/해당_유저가_해당_fcm_토큰을_저장할때_이미_fcm_토큰을_가지고_있다면_에러가_발생한다/http-response.adoc[]

=== FCM 토큰 삭제
사용자는 디바이스의 FCM 토큰을 삭제할 수 있습니다.

Expand All @@ -34,4 +37,7 @@ include::{snippets}/fcm-token-controller-test/fcm_토큰을_삭제한다/http-re

==== 응답
===== 정상 응답
include::{snippets}/fcm-token-controller-test/fcm_토큰을_삭제한다/http-response.adoc[]
include::{snippets}/fcm-token-controller-test/fcm_토큰을_삭제한다/http-response.adoc[]

===== 해당 유저가 해당 FCM 토큰을 가지고 있지 않을 경우
include::{snippets}/fcm-token-controller-test/해당_유저가_해당_fcm_토큰을_가지고있지_않다면_에러가_발생한다/http-response.adoc[]
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bamdoliro.sinabro.domain.fcm.token.domain;

import com.bamdoliro.sinabro.domain.user.domain.User;
import com.bamdoliro.sinabro.shared.entity.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
Expand All @@ -11,7 +12,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "tbl_fcm_token")
@Entity
public class FCMToken {
public class FCMToken extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.bamdoliro.sinabro.presentation.fcm.token;

import com.bamdoliro.sinabro.domain.fcm.token.exception.FCMTokenAlreadySavedException;
import com.bamdoliro.sinabro.domain.fcm.token.exception.FCMTokenNotFoundException;
import com.bamdoliro.sinabro.domain.user.domain.User;
import com.bamdoliro.sinabro.presentation.fcm.token.dto.request.DeleteFCMTokenRequest;
import com.bamdoliro.sinabro.presentation.fcm.token.dto.request.SaveFCMTokenRequest;
Expand Down Expand Up @@ -55,6 +57,29 @@ public class FCMTokenControllerTest extends RestDocsTestSupport {
verify(saveFCMTokenUseCase, times(1)).execute(any(User.class), any(SaveFCMTokenRequest.class));
}

@Test
void 해당_유저가_해당_FCM_토큰을_저장할때_이미_FCM_토큰을_가지고_있다면_에러가_발생한다() throws Exception {
User user = UserFixture.createUser();
SaveFCMTokenRequest request = new SaveFCMTokenRequest("fcm-token");

given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true);
given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user);
willThrow(new FCMTokenAlreadySavedException()).given(saveFCMTokenUseCase).execute(any(User.class), any(SaveFCMTokenRequest.class));

mockMvc.perform(post("/fcm-token")
.header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader())
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content(toJson(request))
)

.andExpect(status().isConflict())

.andDo(restDocs.document());

verify(saveFCMTokenUseCase, times(1)).execute(any(User.class), any(SaveFCMTokenRequest.class));
}

@Test
void FCM_토큰을_삭제한다() throws Exception {
User user = UserFixture.createUser();
Expand Down Expand Up @@ -86,4 +111,27 @@ public class FCMTokenControllerTest extends RestDocsTestSupport {

verify(deleteFCMTokenUseCase, times(1)).execute(any(User.class), any(DeleteFCMTokenRequest.class));
}

@Test
void 해당_유저가_해당_FCM_토큰을_가지고있지_않다면_에러가_발생한다() throws Exception {
User user = UserFixture.createUser();
DeleteFCMTokenRequest request = new DeleteFCMTokenRequest("fcm-token");

given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true);
given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user);
willThrow(new FCMTokenNotFoundException()).given(deleteFCMTokenUseCase).execute(any(User.class), any(DeleteFCMTokenRequest.class));

mockMvc.perform(delete("/fcm-token")
.header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader())
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content(toJson(request))
)

.andExpect(status().isNotFound())

.andDo(restDocs.document());

verify(deleteFCMTokenUseCase, times(1)).execute(any(User.class), any(DeleteFCMTokenRequest.class));
}
}

0 comments on commit 6c18189

Please sign in to comment.