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

Add Book and Category testing #16

Merged
merged 4 commits into from
Jun 7, 2024
Merged

Conversation

nklimovych
Copy link
Owner

@nklimovych nklimovych commented May 29, 2024

Screen Shot 2024-05-29 at 13 14 03 PM

…tory.

 - Added test methods for CategoryController, CategoryService, and CategoryRepository.
Copy link

@azzilian azzilian left a 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);

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

I believe there is an issue with GitHub as it does not display an empty line at the end.

Знімок екрана 2024-05-30 о 00 00 50

@@ -0,0 +1,3 @@
DELETE FROM books_categories;
DELETE FROM categories;
DELETE FROM books;

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

Same here

Знімок екрана 2024-05-30 о 00 01 26

categoryDto.setName(VALID_CATEGORY_NAME);
return categoryDto;
}
}

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

Знімок екрана 2024-05-30 о 00 03 20

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!

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

Знімок екрана 2024-05-30 о 00 02 39

Copy link

@andrii-hoienko andrii-hoienko left a 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));

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)

Copy link

Choose a reason for hiding this comment

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

not resolved

Copy link
Owner Author

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...

Comment on lines 56 to 57
assertEquals(VALID_BOOK_ID_KOBZAR, bookOptional.get().getId());
assertEquals(VALID_BOOK_ISBN_KOBZAR, bookOptional.get().getIsbn());

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

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
Copy link

@karma-o karma-o left a 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

Comment on lines 45 to 46
private static final String ADMIN_ROLE = "ADMIN";
private static final String USER_ROLE = "USER";
Copy link

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?

Copy link
Owner Author

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))

Copy link
Owner Author

Choose a reason for hiding this comment

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

Maybe I did something wrong, but it won't let me do it this way.
Знімок екрана 2024-06-06 о 21 34 01

Comment on lines +58 to +59
@MockBean
private BookService bookService;
Copy link

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));
Copy link

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 {
Copy link

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) {
Copy link

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

@nklimovych nklimovych merged commit 8463040 into main Jun 7, 2024
2 checks passed
@nklimovych nklimovych deleted the book-and-category-testing branch June 7, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants