Skip to content

Commit

Permalink
adjusted test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jans510 committed Dec 10, 2024
1 parent 6cdf296 commit 8874066
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/test/java/net/dancier/dancer/dancers/DancerControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,39 @@
import org.springframework.security.test.context.support.WithUserDetails;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.util.MultiValueMap;

import java.util.UUID;
import java.util.List;

import static net.dancier.dancer.core.model.Gender.FEMALE;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.isA;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class DancerControllerTest extends AbstractPostgreSQLEnabledTest {


UUID userId = UUID.fromString("55bbf334-6649-11ed-8f65-5b299f0e161f");

@Test
@WithUserDetails("[email protected]")
void getDancersShouldNotReturnOwnProfile() throws Exception {
@Sql(value = {"/dancers/data.sql"})
void getDancersShouldReturnFilteredProfiles() throws Exception {

ResultActions result = mockMvc
mockMvc
.perform(get("/dancers")
.param("range", "20")
.param("gender", "MALE")
.param("gender", "FEMALE")
)
.andExpect(status().isOk());
.andExpect(status().isOk())
.andExpect(jsonPath("$.*", isA(List.class)))
.andExpect(jsonPath("$.*", hasSize(1)))
.andExpect(jsonPath("$[0].id").value("503ffad4-148b-4af1-8365-62315ff89b9f"))
.andExpect(jsonPath("$[0].gender").value("FEMALE"))
.andExpect(jsonPath("$[0].dancerName").value("perfect_dancer"))
.andExpect(jsonPath("$[0].aboutMe").value("Hi"))
.andExpect(jsonPath("$[0].age").isNotEmpty())
.andExpect(jsonPath("$[0].size").value("178"))
.andExpect(jsonPath("$[0].city").value("Dortmund"))
.andExpect(jsonPath("$[0].country").value("GER"));

}
}
116 changes: 116 additions & 0 deletions src/test/resources/dancers/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
-- 5 test users are added
-- [email protected]
-- -> the user that initiates the query
-- [email protected]
-- -> a user that matches all query parameters and is returned by GET /dancers request
-- [email protected]
-- -> a user that matches all query parameters except gender and is returned by GET /dancers request
-- [email protected]
-- -> valid user with a profile but not matching the latitude
-- [email protected]
-- -> valid user with a profile but not matching the longitude

-- user who initiates the query
INSERT
INTO users (id, email, password, email_validated )
VALUES (
'55bbf334-6649-11ed-8f65-5b299f0e161f',
'[email protected]',
'$2a$10$GOChyBEqco9m3wZwkh0RqOTwyWq4HmocguPPfEraSgnbmlrM4.Fey',
true
);

INSERT
INTO user_roles (user_id, role_id)
SELECT '55bbf334-6649-11ed-8f65-5b299f0e161f',
id
FROM roles
WHERE name IN ('ROLE_USER', 'ROLE_HUMAN');

INSERT
INTO dancer(user_id, id, dancer_name, size, birth_date, gender, country, city, longitude, latitude, about_me)
VALUES ('55bbf334-6649-11ed-8f65-5b299f0e161f', '11065e54-664a-11ed-872e-1b1eb88b44b6', 'good_dancer', '178', '2000-11-11', 'MALE', 'GER', 'Dortmund', '7.1075023', '51.4429498', 'Hi');

-- one ordinary user with matching profile
INSERT
INTO users (id, email, password, email_validated )
VALUES (
'b8300af3-a27b-41ed-b35b-3735b25a04df',
'[email protected]',
'$2a$10$GOChyh6tco9m3wZwkh0RqOTwyWq4HmocguPPfEraSgnbmlrM4.Fax',
true
);

INSERT
INTO user_roles (user_id, role_id)
SELECT 'b8300af3-a27b-41ed-b35b-3735b25a04df',
id
FROM roles
WHERE name IN ('ROLE_USER', 'ROLE_HUMAN');

INSERT
INTO dancer(user_id, id, dancer_name, size, birth_date, gender, country, city, longitude, latitude, about_me)
VALUES ('b8300af3-a27b-41ed-b35b-3735b25a04df', '503ffad4-148b-4af1-8365-62315ff89b9f', 'perfect_dancer', '178', '1998-11-11', 'FEMALE', 'GER', 'Dortmund', '7.0075023', '51.3429498', 'Hi');

-- one ordinary user with not matching gender
INSERT
INTO users (id, email, password, email_validated )
VALUES (
'b90e6478-19d9-492e-97a8-df1f8f7c3901',
'[email protected]',
'$2a$10$GOChyh6tco9zu6Zwkh0RqOTwyWq4HmocguPPfEraSgnbmlrM4.Fax',
true
);

INSERT
INTO user_roles (user_id, role_id)
SELECT 'b90e6478-19d9-492e-97a8-df1f8f7c3901',
id
FROM roles
WHERE name IN ('ROLE_USER', 'ROLE_HUMAN');

INSERT
INTO dancer(user_id, id, dancer_name, size, birth_date, gender, country, city, longitude, latitude, about_me)
VALUES ('b90e6478-19d9-492e-97a8-df1f8f7c3901', '0948c9ba-75a9-4821-8701-0cd3e564f10e', 'Horst', '178', '1980-11-11', 'MALE', 'GER', 'Dortmund', '7.0075023', '51.3429498', 'Hi');

-- one ordinary user with not matching latitude
INSERT
INTO users (id, email, password, email_validated )
VALUES (
'6cd96820-ce61-4f72-9fa4-6f8900bb7494',
'[email protected]',
'$2a$10$GOChyh6tco9m3wZwkk8tqOTwyWq4HmocguPPfEraSgnbmlrM4.Fax',
true
);

INSERT
INTO user_roles (user_id, role_id)
SELECT '6cd96820-ce61-4f72-9fa4-6f8900bb7494',
id
FROM roles
WHERE name IN ('ROLE_USER', 'ROLE_HUMAN');

INSERT
INTO dancer(user_id, id, dancer_name, size, birth_date, gender, country, city, longitude, latitude, about_me)
VALUES ('6cd96820-ce61-4f72-9fa4-6f8900bb7494', '9593cd4c-bff4-41b5-b7d8-a632a526721a', 'dancer', '178', '1997-11-11', 'FEMALE', 'GER', 'Bremen', '7.0075023', '54.3429498', 'Hi');

-- one ordinary user with not matching longitude
INSERT
INTO users (id, email, password, email_validated )
VALUES (
'e177c7f1-1082-4bd1-ad72-fd88de5b19b2',
'[email protected]',
'$2a$10$GOChyh6tco9m3wZwkk8tqOTwyWq4HmocguPPfEraSgnbmlrM4.Fax',
true
);

INSERT
INTO user_roles (user_id, role_id)
SELECT 'e177c7f1-1082-4bd1-ad72-fd88de5b19b2',
id
FROM roles
WHERE name IN ('ROLE_USER', 'ROLE_HUMAN');

INSERT
INTO dancer(user_id, id, dancer_name, size, birth_date, gender, country, city, longitude, latitude, about_me)
VALUES ('e177c7f1-1082-4bd1-ad72-fd88de5b19b2', 'f140bc96-5d65-4e6b-8727-f89f2afef03d', 'dancing_queen', '178', '1995-11-11', 'FEMALE', 'GER', 'Essen', '6.0075023', '51.3429498', 'Hi');

0 comments on commit 8874066

Please sign in to comment.