Repository navigation
COG-1144: W0 smoke suite for appointment create/list/confirm #108
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
base: devin/cog-1141-w0-testcontainers-mysql-harness-for-springboottest-boot-154
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| package com.userFront; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
|
||
| import java.text.SimpleDateFormat; | ||
| import java.util.Date; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.test.web.servlet.ResultActions; | ||
|
|
||
| import com.userFront.domain.Appointment; | ||
| import com.userFront.domain.User; | ||
| import com.userFront.domain.security.Role; | ||
| import com.userFront.domain.security.UserRole; | ||
| import com.userFront.service.AppointmentService; | ||
| import com.userFront.service.UserService; | ||
|
|
||
| public class AppointmentSmokeTest extends AbstractIntegrationTest { | ||
|
|
||
| private static final String USERNAME = "apptsmoke-user"; | ||
|
|
||
| @Autowired | ||
| private UserService userService; | ||
|
|
||
| @Autowired | ||
| private AppointmentService appointmentService; | ||
|
|
||
| @Before | ||
| public void createUser() { | ||
| if (userService.findByUsername(USERNAME) != null) { | ||
| return; | ||
| } | ||
|
|
||
| User user = new User(); | ||
| user.setUsername(USERNAME); | ||
| user.setPassword("password"); | ||
| user.setFirstName("Appt"); | ||
| user.setLastName("Smoke"); | ||
| user.setEmail("apptsmoke-user@example.com"); | ||
| user.setPhone("555-0144"); | ||
|
|
||
| Role role = new Role(); | ||
| role.setRoleId(1); | ||
| role.setName("ROLE_USER"); | ||
|
|
||
| Set<UserRole> userRoles = new HashSet<>(); | ||
| userRoles.add(new UserRole(user, role)); | ||
|
|
||
| userService.createUser(user, userRoles); | ||
| } | ||
|
|
||
| @Test | ||
| public void createsAppointmentFromThymeleafForm() throws Exception { | ||
| mockMvc.perform(post("/appointment/create") | ||
| .param("dateString", "2016-10-21 15:25") | ||
| .param("location", "Boston") | ||
| .param("description", "Smoke test appointment") | ||
| .with(user(USERNAME).roles("USER"))) | ||
| .andExpect(status().is3xxRedirection()) | ||
| .andExpect(redirectedUrl("/userFront")); | ||
|
|
||
| Appointment appointment = latestAppointment(); | ||
| assertNotNull(appointment.getDate()); | ||
| assertEquals("Boston", appointment.getLocation()); | ||
| assertEquals("Smoke test appointment", appointment.getDescription()); | ||
| assertEquals(USERNAME, appointment.getUser().getUsername()); | ||
|
|
||
| assertEquals("2016-10-21 15:25", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(appointment.getDate())); | ||
| } | ||
|
|
||
| @Test | ||
| public void parsesNoonWithTwelveHourClockQuirk() throws Exception { | ||
| mockMvc.perform(post("/appointment/create") | ||
| .param("dateString", "2016-10-21 12:30") | ||
| .param("location", "San Francisco") | ||
| .param("description", "Noon appointment") | ||
| .with(user(USERNAME).roles("USER"))) | ||
| .andExpect(status().is3xxRedirection()); | ||
|
|
||
| // SimpleDateFormat("yyyy-MM-dd hh:mm") reads the hour in the 12-hour field, | ||
| // so the form's noon is stored as midnight. | ||
| assertEquals("2016-10-21 00:30", | ||
| new SimpleDateFormat("yyyy-MM-dd HH:mm").format(latestAppointment().getDate())); | ||
| } | ||
|
|
||
| @Test | ||
| public void listsAppointmentsForAdmin() throws Exception { | ||
| Appointment appointment = persistAppointment("New York", "Listed appointment"); | ||
|
|
||
| mockMvc.perform(get("/api/appointment/all").with(user("admin").roles("ADMIN"))) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$[?(@.id == " + appointment.getId() + ")].location").value("New York")); | ||
|
Comment on lines
+102
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deliberate: these tests are the migration regression contract for the appointment endpoints, so they assert route/verb/role behaviour, not admin account provisioning. A DB-backed admin login belongs in a separate auth smoke test. |
||
| } | ||
|
|
||
| @Test | ||
| public void confirmsAppointmentOverGet() throws Exception { | ||
| Appointment appointment = persistAppointment("Chicago", "Confirmed appointment"); | ||
|
|
||
| confirm(appointment.getId()) | ||
| .andExpect(status().isOk()); | ||
|
|
||
| assertTrue(appointmentService.findAppointment(appointment.getId()).isConfirmed()); | ||
| } | ||
|
|
||
| /** Admin confirm as mapped today: a method-less {@code @RequestMapping}, so GET is accepted. */ | ||
| private ResultActions confirm(Long appointmentId) throws Exception { | ||
| return mockMvc.perform(get("/api/appointment/" + appointmentId + "/confirm") | ||
| .with(user("admin").roles("ADMIN"))); | ||
| } | ||
|
|
||
| private Appointment persistAppointment(String location, String description) { | ||
| Appointment appointment = new Appointment(); | ||
| appointment.setDate(new Date()); | ||
| appointment.setLocation(location); | ||
| appointment.setDescription(description); | ||
| appointment.setUser(userService.findByUsername(USERNAME)); | ||
|
|
||
| return appointmentService.createAppointment(appointment); | ||
| } | ||
|
|
||
| private Appointment latestAppointment() { | ||
| Appointment latest = null; | ||
| for (Appointment appointment : appointmentService.findAll()) { | ||
| if (USERNAME.equals(appointment.getUser().getUsername()) | ||
| && (latest == null || appointment.getId() > latest.getId())) { | ||
| latest = appointment; | ||
| } | ||
| } | ||
| assertNotNull(latest); | ||
|
|
||
| return latest; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Form smoke test skips browser submission
MockMvcposts form fields directly, so it never exercises the date picker or confirmation callback that submits the browser form. A broken client-side submission can leave these tests green.Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentional — COG-1144 asks for server-side smoke coverage of the controller's date parsing. The picker format is pinned by sending exactly what
main.jsemits; client-side submission is out of scope here.