Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

익명 리소스의 경우 owner를 null이 아닌 member id만 포함하도록 변경한다. #222

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: 익명 표현 방식 변경 사항 테스트 케이스 추가
  • Loading branch information
le2sky committed Feb 18, 2025
commit f6ac66ee84befc640686b8f82de5825938d407db
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package maeilwiki.wiki.application;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.SoftAssertions.assertSoftly;

Expand All @@ -13,6 +12,7 @@
import maeilwiki.member.application.MemberIdentity;
import maeilwiki.member.domain.Member;
import maeilwiki.member.domain.MemberRepository;
import maeilwiki.member.dto.MemberThumbnail;
import maeilwiki.support.IntegrationTestSupport;
import maeilwiki.wiki.domain.Wiki;
import maeilwiki.wiki.domain.WikiRepository;
Expand Down Expand Up @@ -115,7 +115,7 @@ void getWikiById() {
}

@Test
@DisplayName("Wiki가 익명이면 Wiki 작성자를 null 처리한다.")
@DisplayName("Wiki가 익명이면 Wiki 작성자의 MemberID만 노출한다.")
void getAnonymousWikiById() {
// given
boolean isAnonymousWiki = true;
Expand All @@ -127,12 +127,40 @@ void getAnonymousWikiById() {
WikiResponse wikiResponse = wikiService.getWikiById(wiki.getId());

// then
assertThat(wikiResponse.owner()).isNull();
assertSoftly(softAssertions -> {
MemberThumbnail owner = wikiResponse.owner();
softAssertions.assertThat(owner.id()).isEqualTo(prin.getId());
softAssertions.assertThat(owner.name()).isEqualTo(null);
softAssertions.assertThat(owner.github()).isEqualTo(null);
softAssertions.assertThat(owner.profileImage()).isEqualTo(null);
});
}

@Test
@DisplayName("Wiki의 Comment가 익명이면 Comment 작성자를 null 처리한다.")
void getWikiWithAnonymousCommentById() {
@DisplayName("Wiki가 익명이 아니라면 Wiki 작성자의 Member 정보를 노출한다.")
void getNonAnonymousWikiById() {
// given
boolean isAnonymousWiki = false;
Member prin = createMember();
Wiki wiki = createWiki(prin, isAnonymousWiki);
createComment(prin, wiki);

// when
WikiResponse wikiResponse = wikiService.getWikiById(wiki.getId());

// then
assertSoftly(softAssertions -> {
MemberThumbnail owner = wikiResponse.owner();
softAssertions.assertThat(owner.id()).isEqualTo(prin.getId());
softAssertions.assertThat(owner.name()).isEqualTo(prin.getName());
softAssertions.assertThat(owner.github()).isEqualTo(prin.getGithubUrl());
softAssertions.assertThat(owner.profileImage()).isEqualTo(prin.getProfileImageUrl());
});
}

@Test
@DisplayName("Wiki의 Comment가 익명이면 Comment 작성자의 MemberID만 노출한다.")
void getWikiWithNonAnonymousCommentById() {
// given
boolean isAnonymousComment = true;
Member atom = createMember();
Expand All @@ -143,7 +171,35 @@ void getWikiWithAnonymousCommentById() {
WikiResponse wikiResponse = wikiService.getWikiById(wiki.getId());

// then
assertThat(wikiResponse.comments().get(0).owner()).isNull();
assertSoftly(softAssertions -> {
MemberThumbnail owner = wikiResponse.comments().get(0).owner();
softAssertions.assertThat(owner.id()).isEqualTo(atom.getId());
softAssertions.assertThat(owner.name()).isEqualTo(null);
softAssertions.assertThat(owner.github()).isEqualTo(null);
softAssertions.assertThat(owner.profileImage()).isEqualTo(null);
});
}

@Test
@DisplayName("Wiki의 Comment가 익명이 아니라면, Comment 작성자의 Member 정보를 노출한다.")
void getWikiWithAnonymousCommentById() {
// given
boolean isAnonymousComment = false;
Member atom = createMember();
Wiki wiki = createWiki(atom);
createComment(atom, wiki, isAnonymousComment);

// when
WikiResponse wikiResponse = wikiService.getWikiById(wiki.getId());

// then
assertSoftly(softAssertions -> {
MemberThumbnail owner = wikiResponse.comments().get(0).owner();
softAssertions.assertThat(owner.id()).isEqualTo(atom.getId());
softAssertions.assertThat(owner.name()).isEqualTo(atom.getName());
softAssertions.assertThat(owner.github()).isEqualTo(atom.getGithubUrl());
softAssertions.assertThat(owner.profileImage()).isEqualTo(atom.getProfileImageUrl());
});
}

@Test
Expand Down Expand Up @@ -176,7 +232,7 @@ void pageByCategory() {
}

@Test
@DisplayName("각각의 Wiki마다 익명 여부에 따라 Wiki 작성자를 null 처리한다.")
@DisplayName("각각의 Wiki마다 익명 여부에 따라 Wiki 작성자의 MemberID만 노출한다.")
void pageByCategoryWithAnonymousWiki() {
// given
Member prin = createMember();
Expand All @@ -189,9 +245,19 @@ void pageByCategoryWithAnonymousWiki() {
// then
assertSoftly(softAssertions -> {
softAssertions.assertThat(wikiResponses.data().get(0).id()).isEqualTo(nonanonymousWiki.getId());
softAssertions.assertThat(wikiResponses.data().get(0).owner()).isNotNull();

MemberThumbnail nonAnonymousOwner = wikiResponses.data().get(0).owner();
softAssertions.assertThat(nonAnonymousOwner.id()).isEqualTo(prin.getId());
softAssertions.assertThat(nonAnonymousOwner.name()).isEqualTo(prin.getName());
softAssertions.assertThat(nonAnonymousOwner.github()).isEqualTo(prin.getGithubUrl());
softAssertions.assertThat(nonAnonymousOwner.profileImage()).isEqualTo(prin.getProfileImageUrl());

MemberThumbnail anonymousOwner = wikiResponses.data().get(1).owner();
softAssertions.assertThat(wikiResponses.data().get(1).id()).isEqualTo(anonymousWiki.getId());
softAssertions.assertThat(wikiResponses.data().get(1).owner()).isNull();
softAssertions.assertThat(anonymousOwner.id()).isEqualTo(prin.getId());
softAssertions.assertThat(anonymousOwner.name()).isEqualTo(null);
softAssertions.assertThat(anonymousOwner.github()).isEqualTo(null);
softAssertions.assertThat(anonymousOwner.profileImage()).isEqualTo(null);
});
}

Expand Down