Skip to content

Commit 3d9d7bd

Browse files
author
Lasim
committed
Add unit tests for roles route in Fastify application
- Implement tests for all CRUD operations on roles including: - GET /api/roles - GET /api/roles/:id - POST /api/roles - PUT /api/roles/:id - DELETE /api/roles/:id - GET /api/roles/permissions - Mock RoleService and middleware for isolated testing - Validate permissions for role creation and updates - Handle various error scenarios including service errors and validation errors - Ensure correct HTTP status codes and response structures
1 parent 1eb9e4a commit 3d9d7bd

File tree

10 files changed

+2355
-3
lines changed

10 files changed

+2355
-3
lines changed

services/backend/api-spec.json

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,34 @@
1616
"schemas": {}
1717
},
1818
"paths": {
19+
"/api/examples": {
20+
"get": {
21+
"responses": {
22+
"200": {
23+
"description": "Default Response"
24+
}
25+
}
26+
}
27+
},
28+
"/api/examples/{id}": {
29+
"get": {
30+
"parameters": [
31+
{
32+
"schema": {
33+
"type": "string"
34+
},
35+
"in": "path",
36+
"name": "id",
37+
"required": true
38+
}
39+
],
40+
"responses": {
41+
"200": {
42+
"description": "Default Response"
43+
}
44+
}
45+
}
46+
},
1947
"/": {
2048
"get": {
2149
"summary": "API health check",
@@ -6409,6 +6437,200 @@
64096437
}
64106438
}
64116439
},
6440+
"/api/auth/profile/update": {
6441+
"put": {
6442+
"summary": "Update user profile",
6443+
"tags": [
6444+
"Authentication"
6445+
],
6446+
"description": "Allows authenticated users to update their profile information including username, first name, and last name. Requires an active session. At least one field must be provided.",
6447+
"requestBody": {
6448+
"content": {
6449+
"application/json": {
6450+
"schema": {
6451+
"type": "object",
6452+
"properties": {
6453+
"username": {
6454+
"type": "string",
6455+
"minLength": 3,
6456+
"maxLength": 30,
6457+
"pattern": "^[a-zA-Z0-9_]+$"
6458+
},
6459+
"first_name": {
6460+
"type": "string",
6461+
"maxLength": 50
6462+
},
6463+
"last_name": {
6464+
"type": "string",
6465+
"maxLength": 50
6466+
}
6467+
},
6468+
"additionalProperties": false
6469+
}
6470+
}
6471+
}
6472+
},
6473+
"security": [
6474+
{
6475+
"cookieAuth": []
6476+
}
6477+
],
6478+
"responses": {
6479+
"200": {
6480+
"description": "Profile updated successfully",
6481+
"content": {
6482+
"application/json": {
6483+
"schema": {
6484+
"type": "object",
6485+
"properties": {
6486+
"success": {
6487+
"type": "boolean",
6488+
"description": "Indicates if the profile update was successful"
6489+
},
6490+
"message": {
6491+
"type": "string",
6492+
"description": "Success message"
6493+
},
6494+
"user": {
6495+
"type": "object",
6496+
"properties": {
6497+
"id": {
6498+
"type": "string",
6499+
"description": "User ID"
6500+
},
6501+
"username": {
6502+
"type": "string",
6503+
"description": "Updated username"
6504+
},
6505+
"email": {
6506+
"type": "string",
6507+
"description": "User email"
6508+
},
6509+
"first_name": {
6510+
"type": "string",
6511+
"nullable": true,
6512+
"description": "Updated first name"
6513+
},
6514+
"last_name": {
6515+
"type": "string",
6516+
"nullable": true,
6517+
"description": "Updated last name"
6518+
},
6519+
"auth_type": {
6520+
"type": "string",
6521+
"description": "Authentication type"
6522+
},
6523+
"role_id": {
6524+
"type": "string",
6525+
"nullable": true,
6526+
"description": "User role ID"
6527+
}
6528+
},
6529+
"required": [
6530+
"id",
6531+
"username",
6532+
"email",
6533+
"first_name",
6534+
"last_name",
6535+
"auth_type",
6536+
"role_id"
6537+
],
6538+
"additionalProperties": false,
6539+
"description": "Updated user information"
6540+
}
6541+
},
6542+
"required": [
6543+
"success",
6544+
"message",
6545+
"user"
6546+
],
6547+
"additionalProperties": false,
6548+
"description": "Profile updated successfully"
6549+
}
6550+
}
6551+
}
6552+
},
6553+
"400": {
6554+
"description": "Bad Request - Invalid input, no fields provided, or username already taken",
6555+
"content": {
6556+
"application/json": {
6557+
"schema": {
6558+
"type": "object",
6559+
"properties": {
6560+
"success": {
6561+
"type": "boolean",
6562+
"description": "Indicates if the operation was successful (false for errors)",
6563+
"default": false
6564+
},
6565+
"error": {
6566+
"type": "string",
6567+
"description": "Error message describing what went wrong"
6568+
}
6569+
},
6570+
"required": [
6571+
"error"
6572+
],
6573+
"additionalProperties": false,
6574+
"description": "Bad Request - Invalid input, no fields provided, or username already taken"
6575+
}
6576+
}
6577+
}
6578+
},
6579+
"401": {
6580+
"description": "Unauthorized - Authentication required",
6581+
"content": {
6582+
"application/json": {
6583+
"schema": {
6584+
"type": "object",
6585+
"properties": {
6586+
"success": {
6587+
"type": "boolean",
6588+
"description": "Indicates if the operation was successful (false for errors)",
6589+
"default": false
6590+
},
6591+
"error": {
6592+
"type": "string",
6593+
"description": "Error message describing what went wrong"
6594+
}
6595+
},
6596+
"required": [
6597+
"error"
6598+
],
6599+
"additionalProperties": false,
6600+
"description": "Unauthorized - Authentication required"
6601+
}
6602+
}
6603+
}
6604+
},
6605+
"500": {
6606+
"description": "Internal Server Error - Profile update failed",
6607+
"content": {
6608+
"application/json": {
6609+
"schema": {
6610+
"type": "object",
6611+
"properties": {
6612+
"success": {
6613+
"type": "boolean",
6614+
"description": "Indicates if the operation was successful (false for errors)",
6615+
"default": false
6616+
},
6617+
"error": {
6618+
"type": "string",
6619+
"description": "Error message describing what went wrong"
6620+
}
6621+
},
6622+
"required": [
6623+
"error"
6624+
],
6625+
"additionalProperties": false,
6626+
"description": "Internal Server Error - Profile update failed"
6627+
}
6628+
}
6629+
}
6630+
}
6631+
}
6632+
}
6633+
},
64126634
"/api/auth/github/login": {
64136635
"get": {
64146636
"summary": "Initiate GitHub OAuth login",

0 commit comments

Comments
 (0)