Using dev profile for running locally, and all integration tests now passing.
This commit is contained in:
parent
d98101b8a4
commit
467a69460d
@ -1,12 +1,17 @@
|
|||||||
package app.mealsmadeeasy.api.auth;
|
package app.mealsmadeeasy.api.auth;
|
||||||
|
|
||||||
|
import app.mealsmadeeasy.api.user.User;
|
||||||
|
import app.mealsmadeeasy.api.user.UserCreateException;
|
||||||
|
import app.mealsmadeeasy.api.user.UserService;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import jakarta.servlet.http.Cookie;
|
import jakarta.servlet.http.Cookie;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
@ -30,6 +35,17 @@ public class AuthControllerTests {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
private User createTestUser() {
|
||||||
|
try {
|
||||||
|
return this.userService.createUser("test", "test@test.com", "test");
|
||||||
|
} catch (UserCreateException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private MockHttpServletRequestBuilder getLoginRequest() throws Exception {
|
private MockHttpServletRequestBuilder getLoginRequest() throws Exception {
|
||||||
final Map<String, ?> body = Map.of(
|
final Map<String, ?> body = Map.of(
|
||||||
"username", "test",
|
"username", "test",
|
||||||
@ -41,7 +57,14 @@ public class AuthControllerTests {
|
|||||||
.with(user("test").password("test"));
|
.with(user("test").password("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setup() {
|
||||||
|
final User testUser = this.createTestUser();
|
||||||
|
System.out.println("Created testUser: " + testUser);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
public void simpleLogin() throws Exception {
|
public void simpleLogin() throws Exception {
|
||||||
this.mockMvc.perform(this.getLoginRequest())
|
this.mockMvc.perform(this.getLoginRequest())
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
@ -60,6 +83,7 @@ public class AuthControllerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
public void simpleLogout() throws Exception {
|
public void simpleLogout() throws Exception {
|
||||||
final MockHttpServletRequestBuilder req = post("/auth/logout")
|
final MockHttpServletRequestBuilder req = post("/auth/logout")
|
||||||
.cookie(this.getRefreshTokenCookie());
|
.cookie(this.getRefreshTokenCookie());
|
||||||
@ -69,6 +93,7 @@ public class AuthControllerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DirtiesContext
|
||||||
public void simpleRefresh() throws Exception {
|
public void simpleRefresh() throws Exception {
|
||||||
final Cookie firstRefreshTokenCookie = this.getRefreshTokenCookie();
|
final Cookie firstRefreshTokenCookie = this.getRefreshTokenCookie();
|
||||||
final MockHttpServletRequestBuilder req = post("/auth/refresh")
|
final MockHttpServletRequestBuilder req = post("/auth/refresh")
|
||||||
|
39
src/main/java/app/mealsmadeeasy/api/DevConfiguration.java
Normal file
39
src/main/java/app/mealsmadeeasy/api/DevConfiguration.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package app.mealsmadeeasy.api;
|
||||||
|
|
||||||
|
import app.mealsmadeeasy.api.recipe.Recipe;
|
||||||
|
import app.mealsmadeeasy.api.recipe.RecipeService;
|
||||||
|
import app.mealsmadeeasy.api.user.User;
|
||||||
|
import app.mealsmadeeasy.api.user.UserService;
|
||||||
|
import org.springframework.boot.CommandLineRunner;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Profile("dev")
|
||||||
|
public class DevConfiguration {
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
private final RecipeService recipeService;
|
||||||
|
|
||||||
|
public DevConfiguration(UserService userService, RecipeService recipeService) {
|
||||||
|
this.userService = userService;
|
||||||
|
this.recipeService = recipeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CommandLineRunner addTestData() {
|
||||||
|
return args -> {
|
||||||
|
final User testUser = this.userService.createUser(
|
||||||
|
"test", "test@test.com", "test", Set.of()
|
||||||
|
);
|
||||||
|
final Recipe recipe = this.recipeService.create(testUser, "Test Recipe", "Hello, World!");
|
||||||
|
this.recipeService.setPublic(recipe, testUser, true);
|
||||||
|
System.out.println("Created " + testUser);
|
||||||
|
System.out.println("Created " + recipe);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,15 +1,7 @@
|
|||||||
package app.mealsmadeeasy.api;
|
package app.mealsmadeeasy.api;
|
||||||
|
|
||||||
import app.mealsmadeeasy.api.recipe.Recipe;
|
|
||||||
import app.mealsmadeeasy.api.recipe.RecipeService;
|
|
||||||
import app.mealsmadeeasy.api.user.User;
|
|
||||||
import app.mealsmadeeasy.api.user.UserService;
|
|
||||||
import org.springframework.boot.CommandLineRunner;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class MealsMadeEasyApiApplication {
|
public class MealsMadeEasyApiApplication {
|
||||||
@ -18,25 +10,4 @@ public class MealsMadeEasyApiApplication {
|
|||||||
SpringApplication.run(MealsMadeEasyApiApplication.class, args);
|
SpringApplication.run(MealsMadeEasyApiApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final UserService userService;
|
|
||||||
private final RecipeService recipeService;
|
|
||||||
|
|
||||||
public MealsMadeEasyApiApplication(UserService userService, RecipeService recipeService) {
|
|
||||||
this.userService = userService;
|
|
||||||
this.recipeService = recipeService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public CommandLineRunner addTestData() {
|
|
||||||
return args -> {
|
|
||||||
final User testUser = this.userService.createUser(
|
|
||||||
"test", "test@test.com", "test", Set.of()
|
|
||||||
);
|
|
||||||
final Recipe recipe = this.recipeService.create(testUser, "Test Recipe", "Hello, World!");
|
|
||||||
this.recipeService.setPublic(recipe, testUser, true);
|
|
||||||
System.out.println("Created " + testUser);
|
|
||||||
System.out.println("Created " + recipe);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user