Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions UserFront/src/test/java/com/userFront/AppointmentSmokeTest.java
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")))
Comment on lines +65 to +70

@devin-ai-integration devin-ai-integration Bot Sep 24, 2026 •

Copy link
Copy Markdown

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

MockMvc posts 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

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.js emits; client-side submission is out of scope here.

.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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Admin tests use synthetic authentication

user("admin").roles("ADMIN") bypasses database-backed admin login. The tests exercise endpoint authorization, but cannot detect broken admin account or role loading.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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;
}
}