diff --git a/src/test/kotlin/pt/up/fe/ni/website/backend/controller/AccountControllerTest.kt b/src/test/kotlin/pt/up/fe/ni/website/backend/controller/AccountControllerTest.kt index 096dc259..771f6f9e 100644 --- a/src/test/kotlin/pt/up/fe/ni/website/backend/controller/AccountControllerTest.kt +++ b/src/test/kotlin/pt/up/fe/ni/website/backend/controller/AccountControllerTest.kt @@ -40,6 +40,7 @@ import pt.up.fe.ni.website.backend.utils.annotations.NestedTest import pt.up.fe.ni.website.backend.utils.documentation.payloadschemas.model.PayloadAccount import pt.up.fe.ni.website.backend.utils.documentation.utils.DocumentedJSONField import pt.up.fe.ni.website.backend.utils.documentation.utils.MockMVCExtension.Companion.andDocument +import pt.up.fe.ni.website.backend.utils.documentation.utils.MockMVCExtension.Companion.andDocumentCustomRequestSchema import pt.up.fe.ni.website.backend.utils.documentation.utils.MockMVCExtension.Companion.andDocumentCustomRequestSchemaEmptyResponse import pt.up.fe.ni.website.backend.utils.documentation.utils.MockMVCExtension.Companion.andDocumentCustomRequestSchemaErrorResponse import pt.up.fe.ni.website.backend.utils.documentation.utils.MockMVCExtension.Companion.andDocumentEmptyObjectResponse @@ -928,10 +929,10 @@ class AccountControllerTest @Autowired constructor( fun `should update the password`() { mockMvc.perform(post("/auth/recoverPassword/${testAccount.id}")) .andReturn().response.let { authResponse -> - val recoveryLink = objectMapper.readTree(authResponse.contentAsString)["recovery_url"].asText() - .removePrefix("localhost:8080") + val recoveryToken = objectMapper.readTree(authResponse.contentAsString)["recovery_url"].asText() + .removePrefix("localhost:8080/accounts/recoverPassword/") mockMvc.perform( - put(recoveryLink) + put("/accounts/recoverPassword/$recoveryToken") .contentType(MediaType.APPLICATION_JSON) .content( objectMapper.writeValueAsString( @@ -942,12 +943,12 @@ class AccountControllerTest @Autowired constructor( ) ).andExpectAll( status().isOk() - ).andDocumentCustomRequestSchemaEmptyResponse( + ).andDocumentCustomRequestSchema( documentation, passwordRecoveryPayload, "Recover password", "Update the password of an account using a recovery token.", - urlParameters = parameters, + // urlParameters = parameters, documentRequestPayload = true ) } diff --git a/src/test/kotlin/pt/up/fe/ni/website/backend/controller/AuthControllerTest.kt b/src/test/kotlin/pt/up/fe/ni/website/backend/controller/AuthControllerTest.kt index 34375725..e895cae0 100644 --- a/src/test/kotlin/pt/up/fe/ni/website/backend/controller/AuthControllerTest.kt +++ b/src/test/kotlin/pt/up/fe/ni/website/backend/controller/AuthControllerTest.kt @@ -198,7 +198,7 @@ class AuthControllerTest @Autowired constructor( status().isNotFound(), jsonPath("$.errors.length()").value(1), jsonPath("$.errors[0].message").value("account not found with id 1234") - ).andDocument( + ).andDocumentErrorResponse( documentation, "Recover password", "This endpoint operation allows the recovery of the password of an account, " + @@ -213,7 +213,13 @@ class AuthControllerTest @Autowired constructor( .andExpectAll( status().isOk(), jsonPath("$.recovery_url").exists() - ).andDocumentErrorResponse(documentation) + ).andDocument( + documentation, + "Recover password", + "This endpoint operation allows the recovery of the password of an account, " + + "sending an email with a link to reset the password.", + documentRequestPayload = false + ) } } diff --git a/src/test/kotlin/pt/up/fe/ni/website/backend/utils/documentation/payloadschemas/model/PayloadAuth.kt b/src/test/kotlin/pt/up/fe/ni/website/backend/utils/documentation/payloadschemas/model/PayloadAuth.kt index 4911f1e8..dff39edf 100644 --- a/src/test/kotlin/pt/up/fe/ni/website/backend/utils/documentation/payloadschemas/model/PayloadAuth.kt +++ b/src/test/kotlin/pt/up/fe/ni/website/backend/utils/documentation/payloadschemas/model/PayloadAuth.kt @@ -65,6 +65,12 @@ class PayloadRecoverPassword : ModelDocumentation( "Id of the account", JsonFieldType.NUMBER, isInResponse = false + ), + DocumentedJSONField( + "recovery_url", + "URL to recover the password", + JsonFieldType.STRING, + isInRequest = false ) ) )