-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
268 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 111 additions & 3 deletions
114
myconext-server/src/test/java/myconext/api/ServiceDeskControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,127 @@ | ||
package myconext.api; | ||
|
||
import io.restassured.filter.Filter; | ||
import io.restassured.filter.cookie.CookieFilter; | ||
import myconext.AbstractIntegrationTest; | ||
import myconext.model.ControlCode; | ||
import myconext.model.ExternalLinkedAccount; | ||
import myconext.model.User; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
|
||
import java.time.Instant; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeFormatterBuilder; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, | ||
properties = { | ||
"service_desk_role_auto_provisioning=True" | ||
}) | ||
class ServiceDeskControllerTest extends AbstractIntegrationTest { | ||
|
||
@Test | ||
void getUserControlCode() { | ||
ControlCode controlCode = given() | ||
.when() | ||
.pathParam("code", "12345") | ||
.get("/myconext/api/servicedesk/user/{code}") | ||
.as(ControlCode.class); | ||
assertEquals("12345", controlCode.getCode()); | ||
assertEquals("mdoe", controlCode.getUserUid()); | ||
} | ||
|
||
@Test | ||
void getUserControlCodeNotFound() { | ||
given() | ||
.when() | ||
.pathParam("code", "Nope") | ||
.get("/myconext/api/servicedesk/user/{code}") | ||
.then() | ||
.statusCode(404); | ||
} | ||
|
||
@Test | ||
void validateDate() { | ||
Boolean valid = given() | ||
.when() | ||
.queryParam("dayOfBirth", "16 Mar 1981") | ||
.get("/myconext/api/servicedesk/validate") | ||
.as(Boolean.class); | ||
assertTrue(valid); | ||
} | ||
|
||
@Test | ||
void validateInvalidDate() { | ||
Boolean valid = given() | ||
.when() | ||
.queryParam("dayOfBirth", "Nope") | ||
.get("/myconext/api/servicedesk/validate") | ||
.as(Boolean.class); | ||
assertFalse(valid); | ||
} | ||
|
||
|
||
@Test | ||
void convertUserControlCode() { | ||
ControlCode controlCode = given() | ||
.when() | ||
.pathParam("code", "12345") | ||
.get("/myconext/api/servicedesk/user/{code}") | ||
.as(ControlCode.class); | ||
|
||
given() | ||
.when() | ||
.body(controlCode) | ||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) | ||
.put("/myconext/api/servicedesk/approve") | ||
.then() | ||
.statusCode(201); | ||
|
||
User user = userRepository.findOneUserByEmail("[email protected]"); | ||
assertEquals(1, user.getExternalLinkedAccounts().size()); | ||
|
||
ExternalLinkedAccount externalLinkedAccount = user.getExternalLinkedAccounts().getFirst(); | ||
DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().appendPattern("dd-MM-yyyy").toFormatter(); | ||
ZonedDateTime dateOfBirth = externalLinkedAccount.getDateOfBirth().toInstant().atZone(ZoneId.systemDefault()); | ||
//See myconext-server/src/test/resources/users.json | ||
assertEquals("11-03-1987", dateTimeFormatter.format(dateOfBirth)); | ||
} | ||
|
||
@Test | ||
void convertUserControlCodeForbidden() { | ||
ControlCode controlCode = new ControlCode("firstName", "lastName", "dayOfBirth"); | ||
controlCode.setCode("12345"); | ||
controlCode.setUserUid("bogus"); | ||
|
||
given() | ||
.when() | ||
.body(controlCode) | ||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) | ||
.put("/myconext/api/servicedesk/approve") | ||
.then() | ||
.statusCode(403); | ||
} | ||
|
||
@Test | ||
void convertUserControlCodeLinkedAccountsPresent() { | ||
ControlCode controlCode = new ControlCode("firstName", "lastName", "dayOfBirth"); | ||
controlCode.setCode("54321"); | ||
|
||
User user = userRepository.findOneUserByEmail("[email protected]"); | ||
user.setControlCode(controlCode); | ||
userRepository.save(user); | ||
|
||
given() | ||
.when() | ||
.body(controlCode) | ||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) | ||
.put("/myconext/api/servicedesk/approve") | ||
.then() | ||
.statusCode(403); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.