Skip to content

Commit

Permalink
tests now working, some doubt on documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jamcunha committed Jun 20, 2023
1 parent 6bfc6c1 commit 0c241bc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, " +
Expand All @@ -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
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
)
Expand Down

0 comments on commit 0c241bc

Please sign in to comment.