Skip to content

Commit

Permalink
feat: 내가 올린 추억 조회 repository test
Browse files Browse the repository at this point in the history
  • Loading branch information
funnysunny08 committed Jun 14, 2024
1 parent 263b773 commit 3df553e
Showing 1 changed file with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.lovemarker.domain.memory.repository;

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

import com.lovemarker.base.BaseRepositoryTest;
import com.lovemarker.domain.couple.Couple;
Expand All @@ -10,7 +10,6 @@
import com.lovemarker.domain.user.User;
import com.lovemarker.domain.user.fixture.UserFixture;
import java.util.List;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -46,7 +45,39 @@ void findByCouple_CoupleIdOrderByCreatedAtDesc() {
.findByCouple_CoupleIdOrderByCreatedAtDesc(couple.getCoupleId(), pageRequest);

//then
Assertions.assertThat(result.getTotalElements()).isEqualTo(expected.getTotalElements());
assertThat(result.getTotalElements()).isEqualTo(expected.getTotalElements());
}
}

@Nested
@DisplayName("findByUser_UserIdOrderByCreatedAtDesc 메서드 실행 시")
class FindByUser_UserIdOrderByCreatedAtDescTest {

User user = UserFixture.user();
Couple couple = CoupleFixture.couple();
Memory memory;

@Test
@DisplayName("성공")
void findByUser_UserIdOrderByCreatedAtDesc() {
//given
user.connectCouple(couple);
memory = MemoryFixture.memory(user);

userRepository.save(user);
coupleRepository.save(couple);
memoryRepository.save(memory);

PageRequest pageRequest = PageRequest.of(0, 10);
List<Memory> memoryList = List.of(memory);
Page<Memory> expected = new PageImpl<>(memoryList);

//when
Page<Memory> result = memoryRepository
.findByUser_UserIdOrderByCreatedAtDesc(user.getUserId(), pageRequest);

//then
assertThat(result.getTotalElements()).isEqualTo(expected.getTotalElements());
}
}

Expand Down

0 comments on commit 3df553e

Please sign in to comment.