From 8a9a34d2521a4a7ddc6a84374d8f2801d8f8a87f Mon Sep 17 00:00:00 2001 From: Okke Harsta Date: Mon, 17 Jun 2024 13:34:26 +0200 Subject: [PATCH] Email is optional and return status 201 for POST and PUT --- .../remotecreation/ExternalEduID.java | 1 - .../RemoteCreationController.java | 4 ++-- .../RemoteCreationControllerTest.java | 20 ++++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/myconext-server/src/main/java/myconext/remotecreation/ExternalEduID.java b/myconext-server/src/main/java/myconext/remotecreation/ExternalEduID.java index b3b7078f..612c5a11 100644 --- a/myconext-server/src/main/java/myconext/remotecreation/ExternalEduID.java +++ b/myconext-server/src/main/java/myconext/remotecreation/ExternalEduID.java @@ -22,7 +22,6 @@ @Setter public class ExternalEduID implements Serializable { - @NotBlank private String email; @Schema(description = "Will be generated by the eduID API") diff --git a/myconext-server/src/main/java/myconext/remotecreation/RemoteCreationController.java b/myconext-server/src/main/java/myconext/remotecreation/RemoteCreationController.java index 45f544e0..8a8f0b33 100644 --- a/myconext-server/src/main/java/myconext/remotecreation/RemoteCreationController.java +++ b/myconext-server/src/main/java/myconext/remotecreation/RemoteCreationController.java @@ -201,7 +201,7 @@ public ResponseEntity createEduID(@Parameter(hidden = true) @Auth userRepository.save(user); mailBox.sendAccountConfirmation(user); - return ResponseEntity.ok(externalEduID); + return ResponseEntity.status(HttpStatus.CREATED).body(externalEduID); } @PutMapping(value = {"/eduid-update"}) @@ -269,7 +269,7 @@ public ResponseEntity updateEduID(@Parameter(hidden = true) @Auth userRepository.save(user); - return ResponseEntity.ok(externalEduID); + return ResponseEntity.status(HttpStatus.CREATED).body(externalEduID); } } diff --git a/myconext-server/src/test/java/myconext/remotecreation/RemoteCreationControllerTest.java b/myconext-server/src/test/java/myconext/remotecreation/RemoteCreationControllerTest.java index 8bed1cd1..a3860602 100644 --- a/myconext-server/src/test/java/myconext/remotecreation/RemoteCreationControllerTest.java +++ b/myconext-server/src/test/java/myconext/remotecreation/RemoteCreationControllerTest.java @@ -221,7 +221,7 @@ void createEduIDBadRequest() { .extract() .as(new TypeRef<>() { }); - assertEquals(Stream.of("chosenName", "email", "identifier", "lastName", "verification").sorted().collect(Collectors.toList()), + assertEquals(Stream.of("chosenName", "identifier", "lastName", "verification").sorted().collect(Collectors.toList()), ((List>) errorResult.get("errors")).stream().map(m -> m.get("field")).sorted().collect(Collectors.toList())); } @@ -273,6 +273,9 @@ void updateEduIDHappyFlowWithNewUser() { .contentType(ContentType.JSON) .body(externalEduID) .post("/api/remote-creation/eduid-create") + .then() + .statusCode(201) + .extract() .as(new TypeRef<>() { }); externalEduIDResult.setBrinCode("QWER"); @@ -283,6 +286,9 @@ void updateEduIDHappyFlowWithNewUser() { .contentType(ContentType.JSON) .body(externalEduIDResult) .put("/api/remote-creation/eduid-update") + .then() + .statusCode(HttpStatus.CREATED.value()) + .extract() .as(new TypeRef<>() { }); String eduIDValue = externalEduIDResult.getEduIDValue(); @@ -314,6 +320,9 @@ void updateEduIDHappyFlowWithExistingUser() { .contentType(ContentType.JSON) .body(externalEduID) .put("/api/remote-creation/eduid-update") + .then() + .statusCode(HttpStatus.CREATED.value()) + .extract() .as(new TypeRef<>() { }); String eduIDValue = updatedExternalEduID.getEduIDValue(); @@ -358,6 +367,9 @@ void updateEduIDNotFound() { .contentType(ContentType.JSON) .body(externalEduID) .post("/api/remote-creation/eduid-create") + .then() + .statusCode(HttpStatus.CREATED.value()) + .extract() .as(new TypeRef<>() { }); externalEduIDResult.setEduIDValue(UUID.randomUUID().toString()); @@ -392,6 +404,9 @@ void updateEduIDExternalAccountGone() { .contentType(ContentType.JSON) .body(externalEduID) .post("/api/remote-creation/eduid-create") + .then() + .statusCode(HttpStatus.CREATED.value()) + .extract() .as(new TypeRef<>() { }); //Now delete the externalAccount @@ -430,6 +445,9 @@ void updateEduIDExternalAccountUpdateIdemPotent() { .contentType(ContentType.JSON) .body(externalEduID) .post("/api/remote-creation/eduid-create") + .then() + .statusCode(HttpStatus.CREATED.value()) + .extract() .as(new TypeRef<>() { }); String eduIDValue = externalEduIDResult.getEduIDValue();