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

모임과 맴버, 채팅에 대한Test Fixture 구현 #162

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions backend/src/main/java/mouda/backend/chat/domain/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import mouda.backend.member.domain.Member;
Expand All @@ -33,4 +34,13 @@ public class Chat {
private LocalDate date;

private LocalTime time;

@Builder
public Chat(String content, Moim moim, Member member, LocalDate date, LocalTime time) {
this.content = content;
this.moim = moim;
this.member = member;
this.date = date;
this.time = time;
}
}
39 changes: 39 additions & 0 deletions backend/src/test/java/mouda/backend/fixture/ChatFixture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package mouda.backend.fixture;

import java.time.LocalDate;
import java.time.LocalTime;

import mouda.backend.chat.domain.Chat;

public class ChatFixture {

public static Chat getChatWithHogeeAtBasketballMoim() {
return Chat.builder()
.time(LocalTime.now())
.date(LocalDate.now())
.content("ㅎㅇㅎㅇ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

픽스쳐 만들기 귀찮았나요? ㅎㅎ

.member(MemberFixture.getHogee())
.moim(MoimFixture.getBasketballMoim())
.build();
}

public static Chat getChatWithAnnaAtCoffeeMoim() {
return Chat.builder()
.time(LocalTime.now())
.date(LocalDate.now())
.content("반갑읍니다")
.member(MemberFixture.getAnna())
.moim(MoimFixture.getCoffeeMoim())
.build();
}

public static Chat getChatWithTebahAtSoccerMoim() {
return Chat.builder()
.time(LocalTime.now())
.date(LocalDate.now())
.content("ㅎㅇㅎㅇ")
.member(MemberFixture.getTebah())
.moim(MoimFixture.getSoccerMoim())
.build();
}
}
24 changes: 24 additions & 0 deletions backend/src/test/java/mouda/backend/fixture/MemberFixture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package mouda.backend.fixture;

import mouda.backend.member.domain.Member;

public class MemberFixture {

public static Member getHogee() {
return Member.builder()
.nickname("hogee")
.build();
}

public static Member getAnna() {
return Member.builder()
.nickname("anna")
.build();
}

public static Member getTebah() {
return Member.builder()
.nickname("tebah")
.build();
}
}
42 changes: 42 additions & 0 deletions backend/src/test/java/mouda/backend/fixture/MoimFixture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package mouda.backend.fixture;

import java.time.LocalDate;
import java.time.LocalTime;

import mouda.backend.moim.domain.Moim;

public class MoimFixture {

public static Moim getSoccerMoim() {
return Moim.builder()
.title("풋살할 사람?")
.time(LocalTime.now().plusHours(1))
.date(LocalDate.now().plusDays(1))
.place("잠실 종합운동장")
.description("잘하는 사람만 와라")
.maxPeople(22)
.build();
}

public static Moim getBasketballMoim() {
return Moim.builder()
.title("농구할 사람?")
.time(LocalTime.now().plusHours(1))
.date(LocalDate.now().plusDays(1))
.place("테바 집")
.description("파주로 와라")
.maxPeople(10)
.build();
}

public static Moim getCoffeeMoim() {
return Moim.builder()
.title("커피 마실 사람?")
.time(LocalTime.now().plusHours(1))
.date(LocalDate.now().plusDays(1))
.place("안나 집")
.description("커피 머신 들고와라")
.maxPeople(100)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import mouda.backend.fixture.MemberFixture;
import mouda.backend.moim.exception.MoimException;

class MemberTest {
private static final String NICNKAME = "안나";

@DisplayName("회원을 정상적으로 생성한다.")
@Test
void createMember() {
assertDoesNotThrow(() -> Member.builder()
.nickname(NICNKAME)
.build());
assertDoesNotThrow(MemberFixture::getAnna);
}

@DisplayName("닉네임을 입력하지 않아 회원 생성에 실패한다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package mouda.backend.member.repository;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;

import org.assertj.core.api.Assertions;
Expand All @@ -12,6 +10,8 @@
import org.springframework.boot.test.context.SpringBootTest;

import mouda.backend.config.DatabaseCleaner;
import mouda.backend.fixture.MemberFixture;
import mouda.backend.fixture.MoimFixture;
import mouda.backend.member.domain.Member;
import mouda.backend.moim.domain.Moim;
import mouda.backend.moim.repository.MoimRepository;
Expand All @@ -36,15 +36,8 @@ void cleanUp() {
@DisplayName("모임에 가입된 참여자의 수를 반환한다.")
@Test
void findNickNamesByMoimId() {
Member member = new Member("tehah");
Moim moim = Moim.builder()
.title("모임 제목")
.date(LocalDate.now().plusDays(1))
.time(LocalTime.now().minusHours(1))
.place("서울시 강북구 중앙로 2길 25")
.maxPeople(10)
.description("모임 설명입니다.")
.build();
Member member = MemberFixture.getHogee();
Moim moim = MoimFixture.getBasketballMoim();
Moim saveMoim = moimRepository.save(moim);
member.joinMoim(saveMoim);
memberRepository.save(member);
Expand Down
10 changes: 2 additions & 8 deletions backend/src/test/java/mouda/backend/moim/domain/MoimTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import mouda.backend.fixture.MoimFixture;
import mouda.backend.moim.exception.MoimException;

class MoimTest {
Expand All @@ -24,14 +25,7 @@ class MoimTest {
@DisplayName("모임 객체를 정상적으로 생성한다.")
@Test
void createMoim() {
Assertions.assertDoesNotThrow(() -> Moim.builder()
.title(TITLE)
.date(DATE)
.time(TIME)
.place(PLACE)
.maxPeople(MAX_PEOPLE)
.description(DESCRIPTION)
.build());
Assertions.assertDoesNotThrow(MoimFixture::getBasketballMoim);
}

@DisplayName("제목 길이가 제한을 초과하면 모임 객체 생성에 실패한다.")
Expand Down
51 changes: 25 additions & 26 deletions backend/src/test/java/mouda/backend/security/JwtProviderTest.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
package mouda.backend.security;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.*;

import mouda.backend.config.DatabaseCleaner;
import mouda.backend.member.domain.Member;
import mouda.backend.member.repository.MemberRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import mouda.backend.config.DatabaseCleaner;
import mouda.backend.fixture.MemberFixture;
import mouda.backend.member.domain.Member;
import mouda.backend.member.repository.MemberRepository;

@SpringBootTest
class JwtProviderTest {

@Autowired
JwtProvider jwtProvider;
@Autowired
JwtProvider jwtProvider;

@Autowired
MemberRepository memberRepository;
@Autowired
MemberRepository memberRepository;

@Autowired
private DatabaseCleaner databaseCleaner;
@Autowired
private DatabaseCleaner databaseCleaner;

@AfterEach
void cleanUp() {
databaseCleaner.cleanUp();
}
@AfterEach
void cleanUp() {
databaseCleaner.cleanUp();
}

@DisplayName("토큰을 발급한다.")
@Test
void createToken() {
String nickname = "테바";
Member member = Member.builder()
.nickname(nickname)
.build();
Member savedMember = memberRepository.save(member);
String token = jwtProvider.createToken(savedMember);
@DisplayName("토큰을 발급한다.")
@Test
void createToken() {
Member member = MemberFixture.getTebah();
Member savedMember = memberRepository.save(member);
String token = jwtProvider.createToken(savedMember);

String savedNickname = jwtProvider.extractNickname(token);
String savedNickname = jwtProvider.extractNickname(token);

assertThat(savedNickname).isEqualTo(nickname);
}
assertThat(savedNickname).isEqualTo(member.getNickname());
}
}