Skip to content

Commit f4ed5f1

Browse files
author
“Rajat
committed
#24: 🔍 Tests updated for Schema Validation
1 parent 4326646 commit f4ed5f1

14 files changed

+218
-9
lines changed

package-lock.json

Lines changed: 55 additions & 1 deletion
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
@@ -21,6 +21,7 @@
2121
"license": "ISC",
2222
"devDependencies": {
2323
"@playwright/test": "^1.41.2",
24-
"@types/node": "^20.11.16"
24+
"@types/node": "^20.11.16",
25+
"ajv": "^8.17.1"
2526
}
2627
}
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.js

Lines changed: 5 additions & 1 deletion
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,7 +29,8 @@ test.describe('Login', () => {
2829
// Assertions to validate the response
2930
VerificationUtils.assertResponseStatusCode(response, 200)
3031
VerificationUtils.assertResponseBodyKeyPresent(responseBody, "token")
31-
32+
VerificationUtils.assertResponseSchema(responseBody, SchemaUtils.LOGIN_SUCCESSFUL)
33+
3234
})
3335

3436
/**
@@ -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)