-
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 Book and Category testing #16
Conversation
nklimovych
commented
May 29, 2024
•
edited
Loading
edited
…tory. - Added test methods for CategoryController, CategoryService, and CategoryRepository.
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.
Awesome! Just add empty line in the end of some files
(2, 2), | ||
(3, 2), | ||
(4, 2), | ||
(5, 3); |
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.
Imho add - empty line in the eof
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.
@@ -0,0 +1,3 @@ | |||
DELETE FROM books_categories; | |||
DELETE FROM categories; | |||
DELETE FROM books; |
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.
IMHO add - empty line in the eof
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.
categoryDto.setName(VALID_CATEGORY_NAME); | ||
return categoryDto; | ||
} | ||
} |
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.
empty line in the end of file
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.
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect | ||
spring.datasource.url=jdbc:tc:mysql:8:///book_store | ||
spring.datasource.username=test | ||
spring.datasource.password=test | ||
|
||
jwt.expiration=300000 | ||
jwt.secret=JustAnotherSuperSecretString1234! |
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.
empty line in the end of file
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.
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.
Nice, left minor comments
|
||
mockMvc.perform(get(BASE_URL)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath(TITLE_0_EXPRESSION).value(VALID_BOOK_TITLE)); |
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.
Better to check full response object (check other cases as well)
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.
not resolved
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.
I don't understand how I missed that...
assertEquals(VALID_BOOK_ID_KOBZAR, bookOptional.get().getId()); | ||
assertEquals(VALID_BOOK_ISBN_KOBZAR, bookOptional.get().getIsbn()); |
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.
CHeck full object ignoring id
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.
CHeck other methods and classes as well
…ct variables using assertEquals. Organize and format TestConstants.java for better readability
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.
Looks good! Left a few suggestions myself
private static final String ADMIN_ROLE = "ADMIN"; | ||
private static final String USER_ROLE = "USER"; |
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.
why don't you use enum values with name()
method instead?
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.
It's hard to say))
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.
@MockBean | ||
private BookService bookService; |
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.
I think our api interation tests should not use mocked services, but rather a real service and a testcontainer DB. Same for the category controller test
|
||
mockMvc.perform(get(BASE_URL)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath(TITLE_0_EXPRESSION).value(VALID_BOOK_TITLE)); |
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.
not resolved
import org.springframework.web.context.WebApplicationContext; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class BookControllerTest { |
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.
we can add some invalid cases, like non existent book, same for category test and services
return bookDto; | ||
} | ||
|
||
private BookDto getBookDto(CreateBookRequestDto dto) { |
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.
it is not just the getter, it also has some parameter, and it essentially maps something to something