Skip to content

Commit 98a38cc

Browse files
author
“Rajat
committed
#22: Tests updated (Schema Validation)
1 parent b1326d6 commit 98a38cc

File tree

10 files changed

+109
-6
lines changed

10 files changed

+109
-6
lines changed

cypress/e2e/tests-reqres/login.cy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ describe('Login', () => {
4949
// Assertions to validate the response
5050
VerificationUtils.assertResponseStatusCode(response, 400)
5151
VerificationUtils.assertResponseBodyKeyValue(responseBody, "error", "Missing password")
52+
VerificationUtils.assertResponseSchema(responseBody, SchemaUtils.LOGIN_UNSUCCESSFUL)
5253

5354
});
5455
});

cypress/e2e/tests-reqres/register.cy.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import RequestBodyUtils from '../../support/utils/RequestBodyUtils';
33
import RequestUtils from '../../support/utils/RequestUtils';
44
import ResponseUtils from '../../support/utils/ResponseUtils';
55
import VerificationUtils from '../../support/utils/VerificationUtils';
6+
import SchemaUtils from '../../support/utils/SchemaUtils';
67

78
/**
89
* Test suite for API endpoints related to user registration.
@@ -27,7 +28,8 @@ describe('Register', () => {
2728
// Assertions to validate the response
2829
VerificationUtils.assertResponseStatusCode(response, 200)
2930
VerificationUtils.assertResponseBodyKeyPresent(responseBody, 'id')
30-
VerificationUtils.assertResponseBodyKeyPresent(responseBody, "token")
31+
VerificationUtils.assertResponseBodyKeyPresent(responseBody, "token")
32+
VerificationUtils.assertResponseSchema(responseBody, SchemaUtils.REGISTER_SUCCESSFUL)
3133

3234
});
3335
});
@@ -48,6 +50,7 @@ describe('Register', () => {
4850
VerificationUtils.assertResponseStatusCode(response, 400)
4951
VerificationUtils.assertResponseBodyKeyPresent(responseBody, "error")
5052
VerificationUtils.assertResponseBodyKeyValue(responseBody, "error", "Missing password")
53+
VerificationUtils.assertResponseSchema(responseBody, SchemaUtils.REGISTER_UNSUCCESSFUL)
5154

5255
});
5356
});

cypress/e2e/tests-reqres/users.cy.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import RequestBodyUtils from '../../support/utils/RequestBodyUtils';
33
import RequestUtils from '../../support/utils/RequestUtils';
44
import ResponseUtils from '../../support/utils/ResponseUtils';
55
import VerificationUtils from '../../support/utils/VerificationUtils';
6+
import SchemaUtils from '../../support/utils/SchemaUtils';
67

78
/**
89
* Test suite for API endpoints related to user management.
@@ -32,6 +33,7 @@ describe('Users', () => {
3233
VerificationUtils.assertResponseBodyKeyValue(responseBody.data, 'first_name', 'Janet')
3334
VerificationUtils.assertResponseBodyKeyValue(responseBody.data, 'last_name', 'Weaver')
3435
VerificationUtils.assertResponseBodyKeyPresent(responseBody.data, 'email')
36+
3537
});
3638
});
3739

@@ -51,6 +53,8 @@ describe('Users', () => {
5153
VerificationUtils.assertResponseStatusCode(response, 201)
5254
VerificationUtils.assertResponseBodyKeyValue(responseBody, 'id', 1111)
5355
VerificationUtils.assertResponseBodyKeyPresent(responseBody, 'createdAt')
56+
57+
VerificationUtils.assertResponseSchema(responseBody, SchemaUtils.USER_CREATE)
5458
});
5559
});
5660

@@ -71,6 +75,8 @@ describe('Users', () => {
7175
VerificationUtils.assertResponseBodyKeyValue(responseBody, 'name', 'test name - updated')
7276
VerificationUtils.assertResponseBodyKeyValue(responseBody, 'job', 'test job - updated')
7377
VerificationUtils.assertResponseBodyKeyPresent(responseBody, 'updatedAt');
78+
79+
VerificationUtils.assertResponseSchema(responseBody, SchemaUtils.USER_UPDATE_PUT)
7480

7581
});
7682
});
@@ -86,6 +92,7 @@ describe('Users', () => {
8692

8793
// Assertions to validate the response
8894
VerificationUtils.assertResponseStatusCode(response, 204)
95+
8996
});
9097
});
9198

@@ -126,8 +133,9 @@ describe('Users', () => {
126133
VerificationUtils.assertResponseBodyKeyPresent(responseBody.data[0], 'last_name');
127134
VerificationUtils.assertResponseBodyKeyPresent(responseBody.data[0], 'avatar');
128135

129-
VerificationUtils.assertResponseBodyKeyValue(responseBody.support, 'text', 'To keep ReqRes free, contributions towards server costs are appreciated!');
130-
136+
// VerificationUtils.assertResponseBodyKeyValue(responseBody.support, 'text', 'To keep ReqRes free, contributions towards server costs are appreciated!');
137+
VerificationUtils.assertResponseBodyKeyValue(responseBody.support, 'text', 'Tired of writing endless social media content? Let Content Caddy generate it for you.');
138+
131139
});
132140
});
133141

@@ -147,10 +155,9 @@ describe('Users', () => {
147155
VerificationUtils.assertResponseBodyKeyValue(responseBody, 'name', 'test name - updated using patch');
148156
VerificationUtils.assertResponseBodyKeyPresent(responseBody, 'updatedAt');
149157

158+
VerificationUtils.assertResponseSchema(responseBody, SchemaUtils.USER_UPDATE_PATCH)
159+
150160
});
151161
});
152162

153-
154-
155-
156163
})
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+
}

cypress/support/utils/SchemaUtils.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1+
import schemaRegisterSuccessful from '../../fixtures/schema/register/register-successful.json';
2+
import schemaRegisterUnsuccessful from '../../fixtures/schema/register/register-unsuccessful.json';
13

24
import schemaLoginSuccessful from '../../fixtures/schema/login/login-successful.json';
5+
import schemaLoginUnsuccessful from '../../fixtures/schema/login/login-unsuccessful.json';
6+
7+
import schemaUserCreate from '../../fixtures/schema/users/user_create.json';
8+
import schemaUserUpdatePut from '../../fixtures/schema/users/user_update_put.json';
9+
import schemaUserUpdatePatch from '../../fixtures/schema/users/user_update_patch.json';
10+
311

412
/**
513
* Utility class for managing and providing schema data for various scenarios.
614
*/
715
class SchemaUtils {
816

17+
// Register
18+
REGISTER_SUCCESSFUL = schemaRegisterSuccessful;
19+
REGISTER_UNSUCCESSFUL = schemaRegisterUnsuccessful;
20+
921
// Login
1022
LOGIN_SUCCESSFUL = schemaLoginSuccessful;
23+
LOGIN_UNSUCCESSFUL = schemaLoginUnsuccessful;
24+
25+
// Users
26+
USER_CREATE = schemaUserCreate;
27+
USER_UPDATE_PUT = schemaUserUpdatePut;
28+
USER_UPDATE_PATCH = schemaUserUpdatePatch;
1129

1230
}
1331

0 commit comments

Comments
 (0)