webapp icon indicating copy to clipboard operation
webapp copied to clipboard

Enable validation constraints in controller tests

Open nya-elimu opened this issue 2 years ago • 6 comments

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

nya-elimu avatar Aug 06 '22 06:08 nya-elimu

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

rohanshankar avatar Aug 08 '22 14:08 rohanshankar

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

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

nya-elimu avatar Aug 09 '22 00:08 nya-elimu

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

nya-elimu avatar Aug 09 '22 10:08 nya-elimu

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

nya-elimu avatar Aug 10 '22 03:08 nya-elimu

@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

chojnackia avatar Aug 18 '22 16:08 chojnackia

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

nya-elimu avatar Aug 19 '22 08:08 nya-elimu