Skip to content

Commit

Permalink
fix format violation
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Vishwakarma committed Oct 21, 2024
1 parent e77c5f1 commit f85ac8b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
6 changes: 3 additions & 3 deletions skill-tree/src/main/resources/application-test.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cookieName=rds-session-v2-development

spring.datasource.url=jdbc:mysql://localhost:3306/skilltreetestdb
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:${MYSQL_PORT:3306}/skilltreetestdb
spring.datasource.username=${MYSQL_DB_USERNAME}
spring.datasource.password=${MYSQL_DB_PASSWORD}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
package com.RDS.skilltree.skills;

import com.RDS.skilltree.enums.SkillTypeEnum;
import com.RDS.skilltree.models.Skill;
import com.RDS.skilltree.repositories.SkillRepository;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.http.MediaType;
import com.RDS.skilltree.enums.SkillTypeEnum;
import com.RDS.skilltree.services.SkillService;
import jakarta.servlet.http.Cookie;
import java.util.Arrays;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

import java.util.Arrays;

@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("test")
public class GetAllSkillsIntegrationTest {

@Autowired
private SkillService skillService;
@Autowired private SkillService skillService;

@Autowired
private SkillRepository skillRepository;
@Autowired private SkillRepository skillRepository;

@Autowired
private MockMvc mockMvc;
@Autowired private MockMvc mockMvc;

private Cookie authCookie;

@BeforeEach
public void setUp() {
authCookie = new Cookie("rds-session-v2-development", "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJzOXpRVW00WGJWRXo3eHpSa2FadiIsInJvbGUiOiJzdXBlcl91c2VyIiwiaWF0IjoxNzI4NjY0NjA2LCJleHAiOjE3MzEyNTY2MDZ9.EyOFKrVcbleuTjUGic3GzOzYRDoLU4IShyoboe0MHlvWFOAfU2pchpXLE4NcyvdGUZ_tvoUecHd4kUkR8MkhxnkRNU3HE7N-1c1tFeYXZL0KfScJE9YzDXAl113Hx3eZVvYbhNjNUttbDlH4s_kR6YABC3sdbLGKEiLfmp9VeAs");
authCookie =
new Cookie(
"rds-session-v2-development",
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJzOXpRVW00WGJWRXo3eHpSa2FadiIsInJvbGUiOiJzdXBlcl91c2VyIiwiaWF0IjoxNzI4NjY0NjA2LCJleHAiOjE3MzEyNTY2MDZ9.EyOFKrVcbleuTjUGic3GzOzYRDoLU4IShyoboe0MHlvWFOAfU2pchpXLE4NcyvdGUZ_tvoUecHd4kUkR8MkhxnkRNU3HE7N-1c1tFeYXZL0KfScJE9YzDXAl113Hx3eZVvYbhNjNUttbDlH4s_kR6YABC3sdbLGKEiLfmp9VeAs");

skillRepository.deleteAll();
Skill skill1 = new Skill();
Expand All @@ -58,9 +57,11 @@ public void setUp() {
@DisplayName("happy flow - returns all skills that are in db")
public void getAllSkillsHappyFlow() throws Exception {

mockMvc.perform(MockMvcRequestBuilders.get("/v1/skills")
.cookie(authCookie)
.accept(MediaType.APPLICATION_JSON))
mockMvc
.perform(
MockMvcRequestBuilders.get("/v1/skills")
.cookie(authCookie)
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].name").value("Java"))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].name").value("Springboot"))
Expand All @@ -72,19 +73,23 @@ public void getAllSkillsHappyFlow() throws Exception {
public void noSkillsAvailable_shouldReturnEmptyList() throws Exception {
skillRepository.deleteAll();

mockMvc.perform(MockMvcRequestBuilders.get("/v1/skills")
.cookie(authCookie)
.accept(MediaType.APPLICATION_JSON))
mockMvc
.perform(
MockMvcRequestBuilders.get("/v1/skills")
.cookie(authCookie)
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$").isEmpty());
}

@Test
@DisplayName("if invalid cookie, return 401")
public void ifInvalidCoolie_returnUnauthorized() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/v1/skills")
.cookie(new Cookie("cookie1", "eyJhbGciOiJSUz.eyJhbGciOiJSUz.EyJhbGciOiJSUz"))
.accept(MediaType.APPLICATION_JSON))
mockMvc
.perform(
MockMvcRequestBuilders.get("/v1/skills")
.cookie(new Cookie("cookie1", "eyJhbGciOiJSUz.eyJhbGciOiJSUz.EyJhbGciOiJSUz"))
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isUnauthorized());
}
}

0 comments on commit f85ac8b

Please sign in to comment.