-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add subscription data to book details #31
base: main
Are you sure you want to change the base?
Changes from 10 commits
228e23a
cf8864a
570a5f7
711d28e
a74f95a
a67169a
b66fb78
fde2401
a414d29
60a3321
ada44f5
605e1f1
7b425f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.productdock.library.gateway.book; | ||
|
||
import java.util.List; | ||
|
||
public record BookDetailsDto(Object bookData, List<Object> rentalRecords, Integer availableBookCount, | ||
Boolean bookSubscription) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.productdock.library.gateway.book; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.Date; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class BookSubscriptionDto { | ||
private String bookId; | ||
private String userId; | ||
private Date createdDate; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this DTO? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.mock; | ||
|
||
|
@@ -28,13 +29,16 @@ class BookServiceShould { | |
private static final String BOOK_ID = "1"; | ||
private static final String BOOK_TITLE = "::title::"; | ||
private static final String BOOK_AUTHOR = "::author::"; | ||
private static final String JWT_TOKEN = ""; | ||
private static final String JWT_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImVtYWlsIn0.9_82fPfiHdHoOkyx8WQY8FsgPivtguil3QL5a3bDE7g"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be avoided to store any secrets in Git, even if it's used for testing. |
||
private static final String USER_ID = "email"; | ||
private static final int AVAILABLE_BOOK_COUNT = 1; | ||
private static final boolean BOOK_SUBSCRIPTION = false; | ||
private static final Object CATALOG_RESPONSE = Mockito.mock(Object.class); | ||
private static final List<Object> RENTAL_RESPONSE = List.of(mock(Object.class)); | ||
private static final Mono<Object> CATALOG_MONO = Mono.just(CATALOG_RESPONSE); | ||
private static final Mono<List<Object>> RENTAL_MONO = Mono.just(RENTAL_RESPONSE); | ||
private static final Mono<Integer> AVAILABLE_BOOK_COUNT_MONO = Mono.just(AVAILABLE_BOOK_COUNT); | ||
private static final Mono<Boolean> BOOK_SUBSCRIPTION_MONO = Mono.just(BOOK_SUBSCRIPTION); | ||
private static final JsonNode BOOK_DETAILS_JSON = Mockito.mock(JsonNode.class); | ||
|
||
@InjectMocks | ||
|
@@ -57,7 +61,8 @@ void generateBookDetailsDtoByBookId() { | |
given(catalogClient.getBookData(BOOK_ID, JWT_TOKEN)).willReturn(CATALOG_MONO); | ||
given(rentalClient.getBookRentalRecords(BOOK_ID, JWT_TOKEN)).willReturn(RENTAL_MONO); | ||
given(inventoryClient.getAvailableBookCopiesCount(BOOK_ID, JWT_TOKEN)).willReturn(AVAILABLE_BOOK_COUNT_MONO); | ||
given(bookDetailsResponseCombiner.generateBookDetailsDto(CATALOG_RESPONSE, RENTAL_RESPONSE, AVAILABLE_BOOK_COUNT)).willReturn(BOOK_DETAILS_JSON); | ||
given(inventoryClient.isUserSubscribedToBook(BOOK_ID, JWT_TOKEN, USER_ID)).willReturn(BOOK_SUBSCRIPTION_MONO); | ||
given(bookDetailsResponseCombiner.generateBookDetailsDto(any())).willReturn(BOOK_DETAILS_JSON); | ||
|
||
var bookDetails = bookService.getBookDetailsById(BOOK_ID, JWT_TOKEN); | ||
|
||
|
@@ -73,7 +78,8 @@ void generateBookDetailsDtoByBookTitleAndAuthor() { | |
given(catalogClient.getBookDataByTitleAndAuthor(BOOK_TITLE, BOOK_AUTHOR, JWT_TOKEN)).willReturn(catalogMono); | ||
given(rentalClient.getBookRentalRecords(BOOK_ID, JWT_TOKEN)).willReturn(RENTAL_MONO); | ||
given(inventoryClient.getAvailableBookCopiesCount(BOOK_ID, JWT_TOKEN)).willReturn(AVAILABLE_BOOK_COUNT_MONO); | ||
given(bookDetailsResponseCombiner.generateBookDetailsDto(catalogResponse, RENTAL_RESPONSE, AVAILABLE_BOOK_COUNT)) | ||
given(inventoryClient.isUserSubscribedToBook(BOOK_ID, JWT_TOKEN, USER_ID)).willReturn(BOOK_SUBSCRIPTION_MONO); | ||
given(bookDetailsResponseCombiner.generateBookDetailsDto(any())) | ||
.willReturn(BOOK_DETAILS_JSON); | ||
|
||
var bookDetails = bookService.getBookDetailsByTitleAndAuthor(BOOK_TITLE, BOOK_AUTHOR, JWT_TOKEN); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename
getClaimEmail
toextractUserId
or similar, becauseuserId
is what you get