elimu-ai / webapp

🖥 Web application for hosting Android applications and educational content
https://hin.elimu.ai
MIT License
30 stars 55 forks source link

Enable validation constraints in controller tests #1607

Open nya-elimu opened 2 years ago

nya-elimu commented 2 years ago

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 https://github.com/elimu-ai/webapp/issues/1286

rohanshankar commented 2 years ago

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

nya-elimu commented 2 years ago

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

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

nya-elimu commented 2 years ago

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

nya-elimu commented 2 years ago

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

chojnackia commented 2 years ago

@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 commented 2 years ago

@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 🙂