hngprojects / hng_boilerplate_python_fastapi_web

Apache License 2.0
153 stars 136 forks source link

[FEAT] User Deactivation #40

Open joboy-dev opened 3 months ago

joboy-dev commented 3 months ago

Description

This endpoint allows an authenticated user to deactivate their account.

Acceptance Criteria

AUTHENTICATION

{
    "Authorization": "Bearer <jwt_token>"
}

HTTP METHOD AND URL

EMAIL

REQUEST BODY

Purpose

The purpose of the user deactivation endpoint is to allow users to deactivate their accounts, enhancing user control and data privacy.

Requirements

Expected Outcome

A user should be deactivated and should receive an email confirming that the account has been successfully deactivated.

Example

[PATCH] /api/v1/accounts/deactivate

Success

Request Body

{
    "reason": "No longer need the account",
    "confirmation": true
}

Response

{
    "status_code": 200,
    "message": "Account Deactivated Successfully" 
}

Errors

Request Body

Missing data

{
    "reason": "No longer need the account",
}

Response

{
    "status_code": 422, 
    "error": "Invalid input",
    "detail": [
        {
            "confirmation": "Deactivation confirmation is required"
        }   
    ] 
}

Request Body

Confirmation set to false

{
    "reason": "No longer need the account",
    "confirmation": "false"
}

Response

{
    "status_code": 400 ,
    "error":  "Confirmation needs to be true for deactivation"
}

Request Body

If the user has already been deactivated and they try to deactivate their account again.

{
    "reason": "No longer need the account",
    "confirmation": "true"
}

Response

{
    "status_code": 400 ,
    "error":  "User has been deactivated"
}

Request Body

Invalid or expired access token.

{
    "reason": "No longer need the account",
    "confirmation": "true"
}

Response

{
    "status_code":  401,
    "error":  "Could not validate user credentials"
}

Request Body

Unexpected error or server error

{
    "reason": "No longer need the account",
    "confirmation": "true"
}

Response

{
    "status_code":  500,
    "error":  "An unexpected error occured"
}

TEST

Unit Test

End To End Test

joboy-dev commented 3 months ago

This issue is linked to the approved issue here

joboy-dev commented 3 months ago

Slack id: @joboy-dev