Skip to content

Commit d6bae34

Browse files
author
“Rajat
committed
#20: 🔍 Tests updated for Schema Validation
1 parent fdd9655 commit d6bae34

14 files changed

+258
-5
lines changed

package-lock.json

Lines changed: 93 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"license": "ISC",
2121
"devDependencies": {
2222
"@playwright/test": "^1.52.0",
23-
"@types/node": "^22.15.2"
23+
"@types/node": "^22.15.2",
24+
"ajv": "^8.17.1"
2425
}
2526
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"token": {
5+
"type": "string"
6+
}
7+
},
8+
"required": [
9+
"token"
10+
]
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"error": {
5+
"type": "string"
6+
}
7+
},
8+
"required": [
9+
"error"
10+
]
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"id": {
5+
"type": "integer"
6+
},
7+
"token": {
8+
"type": "string"
9+
}
10+
},
11+
"required": [
12+
"id",
13+
"token"
14+
]
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"error": {
5+
"type": "string"
6+
}
7+
},
8+
"required": [
9+
"error"
10+
]
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"id": {
5+
"type": "integer"
6+
}
7+
},
8+
"required": [
9+
"id"
10+
]
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"name": {
5+
"type": "string"
6+
}
7+
},
8+
"required": [
9+
"name"
10+
]
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"name": {
5+
"type": "string"
6+
},
7+
"job": {
8+
"type": "string"
9+
}
10+
},
11+
"required": [
12+
"name",
13+
"job"
14+
]
15+
}

tests-reqres/login.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import RequestBodyUtils from '../utils/RequestBodyUtils';
44
import RequestUtils from '../utils/RequestUtils';
55
import ResponseUtils from '../utils/ResponseUtils';
66
import VerificationUtils from '../utils/VerificationUtils';
7+
import SchemaUtils from '../utils/SchemaUtils';
78

89
/**
910
* Test suite for API endpoints related to user login.
@@ -28,6 +29,7 @@ test.describe('Login', () => {
2829
// Assertions to validate the response
2930
VerificationUtils.assertResponseStatusCode(response, 200);
3031
VerificationUtils.assertResponseBodyKeyPresent(responseBody, "token");
32+
VerificationUtils.assertResponseSchema(responseBody, SchemaUtils.LOGIN_SUCCESSFUL)
3133

3234
});
3335

@@ -47,6 +49,8 @@ test.describe('Login', () => {
4749
VerificationUtils.assertResponseStatusCode(response, 400);
4850
VerificationUtils.assertResponseBodyKeyValue(responseBody, "error", "Missing password");
4951

52+
VerificationUtils.assertResponseSchema(responseBody, SchemaUtils.LOGIN_UNSUCCESSFUL)
53+
5054
});
5155

5256
});

0 commit comments

Comments
 (0)