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

Enable validation constraints in controller tests #1607

Open
nya-elimu opened this issue Aug 6, 2022 · 6 comments
Open

Enable validation constraints in controller tests #1607

nya-elimu opened this issue Aug 6, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@nya-elimu
Copy link
Member

nya-elimu commented Aug 6, 2022

When running unit tests for controllers, the validation constraints are not triggering.

For example, a validation error is expected when trying to store a word in the database that contains no text: https://github.com/elimu-ai/webapp/blob/main/src/test/java/ai/elimu/web/content/word/WordCreateControllerTest.java#L51

RequestBuilder requestBuilder = MockMvcRequestBuilders
                .post("/content/word/create")
                .param("timeStart", String.valueOf(System.currentTimeMillis()))
                .param("text", "")
                .contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
        MvcResult mvcResult = mockMvc.perform(requestBuilder).andReturn();

In this case, the controller should return a validation error message because @Valid Word word is used in the WordCreateController. Instead, the word gets incorrectly stored in the database. So we need to figure out why the @NotNull validation annotations are not working in these JUnit tests.


Relates to #1286

@nya-elimu nya-elimu added bug Something isn't working good first issue Good for newcomers labels Aug 6, 2022
@rohanshankar
Copy link

I can work on this if this is still an issue!

@nya-elimu
Copy link
Member Author

I can work on this if this is still an issue!

@rohanshankar Yes, please do, thank you very much 🙂

@nya-elimu
Copy link
Member Author

@rohanshankar I added you to our GitHub organization, so now you should have access to assign yourself to this GitHub issue 👍🏽

@nya-elimu
Copy link
Member Author

@rohanshankar You are also welcome to join our Discord at https://discord.gg/9rz4XYJJDE 🙂

@chojnackia
Copy link

@rohanshankar If you would not be able or change your mind about doing this please let me know so i can work on that ;)
@nya-elimuai

@nya-elimu
Copy link
Member Author

@chojnackia Please give it a try if you would like. Will invite you to the GitHub organization so that you get access to create a new branch 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants