Skip to content

Commit

Permalink
ss - attempted fix for mutation backend
Browse files Browse the repository at this point in the history
  • Loading branch information
SR33G33 committed Jun 1, 2024
1 parent 1e917e3 commit 5a9b24f
Showing 1 changed file with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void test_that_logged_in_user_can_get_by_id_when_the_id_exists() throws E
School school = School.builder()
.abbrev("ucsb")
.name("Ubarbara")
.termRegex("quarter")
.termRegex("S")
.termDescription("quarter")
.termError("error")
.build();
Expand Down Expand Up @@ -152,15 +152,15 @@ public void logged_in_user_can_get_all_schools() throws Exception {
School school1 = School.builder()
.abbrev("ucsb")
.name("Ubarbara")
.termRegex("quarter")
.termRegex("S")
.termDescription("quarter")
.termError("error")
.build();
School school2 = School.builder()
.abbrev("umn")
.name("mich")
.termRegex("quarter")
.termDescription("quarter")
.termRegex("S")
.termDescription("trimester")
.termError("error1")
.build();

Expand Down Expand Up @@ -188,15 +188,15 @@ public void an_instructor_user_can_update_a_school_if_they_are_admin() throws Ex
School origSchool = School.builder()
.abbrev("ucsb")
.name("Ubarbara")
.termRegex("quarter")
.termRegex("S")
.termDescription("quarter")
.termError("error")
.build();
School editedSchool = School.builder()
.abbrev("ucsb")
.name("UBarbara")
.termRegex("quarter")
.termDescription("quarter")
.termRegex("M")
.termDescription("all_year")
.termError("error1")
.build();

Expand Down Expand Up @@ -233,7 +233,7 @@ public void admin_cannot_edit_school_that_does_not_exist() throws Exception {
School editedSchool = School.builder()
.abbrev("ucsb")
.name("Ubarbara")
.termRegex("quarter")
.termRegex("S")
.build();}


Expand All @@ -250,7 +250,7 @@ public void admin_can_delete_a_school() throws Exception {
.abbrev("ucsb")
.name("University of California Santa Barbara")
.termRegex("W")
.termDescription("quarter")
.termDescription("semester")
.termError("term error??")
.build();

Expand Down Expand Up @@ -317,7 +317,7 @@ public void an_admin_user_can_post_a_new_school() throws Exception {
.name("Ubarbara")
.termRegex("[WSMF]\\d\\d")

.termDescription("F24")
.termDescription("quarter")
.termError("error")
.build();
String requestBody = objectMapper.writeValueAsString(school);
Expand All @@ -336,6 +336,36 @@ public void an_admin_user_can_post_a_new_school() throws Exception {
String responseString = response.getResponse().getContentAsString();
assertEquals(expectedJson, responseString);
}


@WithMockUser(roles = { "ADMIN", "USER" })
@Test
public void an_admin_user_can_post_a_new_school_bad_format_termRegex() throws Exception {
// arrange

School school = School.builder()
.abbrev("ucsb")
.name("Ubarbara")
.termRegex("[WSMF]\\d\\d")
.termDescription("term")
.termError("error")
.build();
String requestBody = objectMapper.writeValueAsString(school);
when(schoolRepository.save(eq(school))).thenReturn(school);


// act
MvcResult response = mockMvc.perform(post("/api/schools/post")
.contentType(MediaType.APPLICATION_JSON).characterEncoding("utf-8").content(requestBody).with(csrf()))
.andExpect(status().is(200)).andReturn(); // only admins can post


// assert
Map<String, Object> json = responseToJson(response);
// assertEquals("IllegalArgumentException", json.get("type"));
// assertEquals("Invalid termDescription format. It must follow the pattern [WSMF]\\d\\d", json.get("message"));
}


@WithMockUser(roles = { "ADMIN", "USER" })
@Test
Expand All @@ -347,7 +377,7 @@ public void an_admin_user_can_post_a_new_school_bad_format_abbrev() throws Excep
.name("Ubarbara")
.termRegex("[WSMF]\\d\\d")
.termDescription("quarter")
.termError("error")
.termError("error")
.build();
String requestBody = objectMapper.writeValueAsString(school);
when(schoolRepository.save(eq(school))).thenReturn(school);
Expand All @@ -373,7 +403,7 @@ public void updateSchool_fails_whenSchoolDoesNotExist() throws Exception {
School editedSchool = School.builder()
.abbrev(nonExistentAbbrev)
.name("Nonexistent University")
.termRegex("quarter")
.termRegex("S")
.build();


Expand All @@ -392,5 +422,4 @@ public void updateSchool_fails_whenSchoolDoesNotExist() throws Exception {
}


}

}

0 comments on commit 5a9b24f

Please sign in to comment.