Skip to content
Snippets Groups Projects
Commit 8262e536 authored by Joshua Gill's avatar Joshua Gill
Browse files

All Tests now pass, Issue complete

parent 3b7f4d0c
No related branches found
No related tags found
5 merge requests!56tags will be saved to userFavTags table (needs user ID of current logged in user),!30merge,!24All Acceptance Criteria Met, password fields on "script.sql" and...,!23IssueSix complete,!21IssueSix Complete, merging branch
package com.example.clientproject.web.controllers;
import com.example.clientproject.web.forms.LoginForm;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.web.servlet.MockMvc;
import static com.example.clientproject.web.controllers.SignInController.loggedIn;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
* Tests for the "SignInController" and all login related routes
*/
@Sql(scripts={"/schema-test-h2.sql","/script-test-h2.sql"})
@ActiveProfiles("h2")
@DirtiesContext
@SpringBootTest
@AutoConfigureMockMvc
public class LoginTests {
@Autowired
MockMvc mockMvc;
/**
* Parameterised Test to test "/login" route given a valid LoginForm object
* 2nd should provide valid loggedIn response, others should provide error messages
* @param email - email
* @param password - password
*/
@ParameterizedTest
@CsvSource({"WoodrowRAZER@email.com,helloWorld", "WoodrowRAZER@email.com,password123", "Testing123@email.com,helloworld123"})
public void correctResponseFromLoginRoute(String email, String password) throws Exception {
if (email.equals("WoodrowRAZER@email.com") && password.equals("password123")) {
mockMvc.perform(post("/login")
.param("loginEmail", email)
.param("loginPassword", password)
)
.andDo(print())
.andExpect(status().is3xxRedirection());
} else {
mockMvc.perform(post("/login")
.param("loginEmail", email)
.param("loginPassword", password)
)
.andDo(print())
.andExpect(status().is(403));
}
}
}
......@@ -5,7 +5,7 @@ SET IGNORECASE=TRUE;
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `mydb`;
DROP SCHEMA IF EXISTS `mydb` CASCADE;
CREATE SCHEMA IF NOT EXISTS `mydb`;
USE `mydb`;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment