Skip to content

Commit

Permalink
refactor: #303 경매가 종료되지 않았다면 판매자이더라도 채팅 가능한 유저인지 정보에 false를 반환하도록 수정 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonyj1022 authored Aug 16, 2023
1 parent a3b0967 commit d090042
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,14 @@ public ReadAuctionWithChatRoomIdDto readByAuctionId(final Long auctionId, final

return new ReadAuctionWithChatRoomIdDto(
ReadAuctionDto.from(findAuction),
new ReadChatRoomDto(nullableChatRoomId, findAuction.isSellerOrWinner(findUser, LocalDateTime.now()))
new ReadChatRoomDto(nullableChatRoomId, isChatParticipant(findAuction, findUser))
);
}

private boolean isChatParticipant(final Auction findAuction, final User findUser) {
return findAuction.isClosed(LocalDateTime.now()) && findAuction.isSellerOrWinner(findUser, LocalDateTime.now());
}

public ReadAuctionsDto readAllByLastAuctionId(final Long lastAuctionId, final int size) {
final Slice<Auction> auctions = auctionRepository.findAuctionsAllByLastAuctionId(lastAuctionId, size);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public record ChatRoomInAuctionResponse(Long id, boolean isChatParticipant) {

public static ChatRoomInAuctionResponse from(final ReadChatRoomDto readChatRoomDto) {

return new ChatRoomInAuctionResponse(readChatRoomDto.id(), readChatRoomDto.isChatParticipant());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,85 @@ class AuctionServiceTest {
}

@Test
void 채팅방이_없고_채팅_자격이_있는_사용자가_지정한_아이디에_해당하는_경매를_조회하면_채팅방_아이디_null과_채팅_가능을_반환한다() {
void 경매가_종료되지_않은_상태에서_지정한_아이디에_해당하는_경매를_조회하면_채팅방_아이디_null과_채팅_불가를_반환한다() {
// given
final StoreImageDto storeImageDto = new StoreImageDto("upload.png", "store.png");

given(imageProcessor.storeImageFiles(any())).willReturn(List.of(storeImageDto));

final Region firstRegion = new Region("first");
final Region secondRegion = new Region("second");
final Region thirdRegion = new Region("third");

firstRegion.addSecondRegion(secondRegion);
secondRegion.addThirdRegion(thirdRegion);

regionRepository.save(firstRegion);

final Category main = new Category("main");
final Category sub = new Category("sub");

main.addSubCategory(sub);
categoryRepository.save(main);

final User seller = User.builder()
.name("회원1")
.profileImage("profile.png")
.reliability(4.7d)
.oauthId("12345")
.build();
final User buyer = User.builder()
.name("회원2")
.profileImage("profile.png")
.reliability(4.7d)
.oauthId("12346")
.build();

userRepository.save(seller);
userRepository.save(buyer);

final MockMultipartFile auctionImage = new MockMultipartFile(
"image.png",
"image.png",
MediaType.IMAGE_PNG.toString(),
new byte[]{1});
final CreateAuctionDto createAuctionDto = new CreateAuctionDto(
"경매 상품 1",
"이것은 경매 상품 1 입니다.",
1_000,
1_000,
LocalDateTime.now().plusDays(3L),
List.of(thirdRegion.getId()),
sub.getId(),
List.of(auctionImage),
1L
);

final Auction auction = createAuctionDto.toEntity(seller, sub);
auctionRepository.save(auction);

// when
final ReadAuctionWithChatRoomIdDto actual =
auctionService.readByAuctionId(auction.getId(), new AuthenticationUserInfo(seller.getId()));

// then
SoftAssertions.assertSoftly(softAssertions -> {
softAssertions.assertThat(actual.auctionDto().id()).isPositive();
softAssertions.assertThat(actual.auctionDto().title()).isEqualTo(auction.getTitle());
softAssertions.assertThat(actual.auctionDto().description()).isEqualTo(auction.getDescription());
softAssertions.assertThat(actual.auctionDto().bidUnit()).isEqualTo(auction.getBidUnit().getValue());
softAssertions.assertThat(actual.auctionDto().startPrice()).isEqualTo(auction.getStartPrice().getValue());
softAssertions.assertThat(actual.auctionDto().lastBidPrice()).isNull();
softAssertions.assertThat(actual.auctionDto().deleted()).isFalse();
softAssertions.assertThat(actual.auctionDto().closingTime()).isEqualTo(auction.getClosingTime());
softAssertions.assertThat(actual.auctionDto().auctioneerCount()).isEqualTo(0);
softAssertions.assertThat(actual.chatRoomDto().id()).isEqualTo(null);
softAssertions.assertThat(actual.chatRoomDto().isChatParticipant()).isFalse();
});
}

@Test
void 경매가_종료되었지만_채팅방이_없는_상태에서_채팅_자격이_있는_사용자가_지정한_아이디에_해당하는_경매를_조회하면_채팅방_아이디_null과_채팅_가능을_반환한다() {
// given
final StoreImageDto storeImageDto = new StoreImageDto("upload.png", "store.png");

Expand Down

0 comments on commit d090042

Please sign in to comment.