itemengine-cypress-automation 1.0.331 → 1.0.332

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,246 @@
1
+ import { questionAndResourceReferenceIds } from '../../support/helpers/createItem'
2
+ import utilities from "../../support/helpers/utilities";
3
+ var sessionData = {};
4
+ var questionReferenceIds = [];
5
+ var timestamp;
6
+ let itemReferenceIdNew;
7
+
8
+ describe('Fetch Templates API cases', () => {
9
+ before(() => {
10
+ cy.loginAs('admin');
11
+ cy.createItem('fetchTemplatesAPI');
12
+ cy.visit(`${Cypress.env('itemEngineHomePage')}`);
13
+ });
14
+
15
+ after(() => {
16
+ cy.deleteItems();
17
+ cy.logout();
18
+ });
19
+
20
+ it('fetch question reference id from the api', () => {
21
+ cy.contains('Item Bank')
22
+ .click();
23
+ cy.contains('Fetch Questions')
24
+ .click();
25
+ cy.contains('Fetch Questions')
26
+ .parent()
27
+ .parent()
28
+ .should('have.class', 'Mui-selected');
29
+ cy.url()
30
+ .should('eq', Cypress.config().baseUrl + '/item-engine/data-api/item-bank/fetch-questions');
31
+ cy.get('.try-out__btn')
32
+ .click();
33
+ cy.get('textarea[class="body-param__text"]')
34
+ .clear()
35
+ .fill(`{\n "item_references": ["fetchTemplatesAPI"],\n "references": [],\n "types": [],\n "limit": 50,\n "sort_field": "created",\n "sort": "desc"\n}\n`);
36
+ cy.get('.execute')
37
+ .click();
38
+ cy.wait(2000);
39
+ cy.get('.loading-container')
40
+ .should('not.exist');
41
+ cy.get('pre[class="microlight"]')
42
+ .eq(1)
43
+ .invoke('text')
44
+ .then((text) => {
45
+ // Parse the JSON from the DOM
46
+ const actualResponse = JSON.parse(text);
47
+ // Extract dynamic values from the parsed object
48
+ const test1Data = actualResponse.data.fetchTemplatesAPI[0];
49
+ const { reference: ref1 } = test1Data;
50
+ itemReferenceIdNew = ref1;
51
+ });
52
+ });
53
+
54
+ it('No responses should be set for an item unless Save Sessions API is run', () => {
55
+ cy.interceptGraphql('createOrUpdateUserSession');
56
+ cy.interceptGraphql('fetchActivity');
57
+ cy.visit(`/item-engine/demo/render-item/student-view/${utilities.base64Encoding(itemReferenceIdNew)}`)
58
+ cy.wait('@createOrUpdateUserSession');
59
+ cy.get('[data-testid="question-instruction-element"]')
60
+ .eq(2)
61
+ .scrollIntoView()
62
+ //mcq question 1
63
+ var checkboxes = ["ChoiceA", "ChoiceB", "ChoiceC", "ChoiceD"];
64
+ cy.get('div[class*="SinglePageAssessmentQuestionsstyles__QuestionPartContainer"]')
65
+ .eq(0)
66
+ .within(() => {
67
+ checkboxes.forEach((i) => {
68
+ cy.get(`input[value="${i}"]`)
69
+ .should('not.be.checked');
70
+ });
71
+ });
72
+ //Extracting session data
73
+ cy.get('@createOrUpdateUserSession').then((data) => {
74
+ const activityMap = data.request.body.variables.input.sessionData.itemActivityMap[0];
75
+ // Assign values to sessionData
76
+ sessionData["activity_id"] = activityMap.activityId;
77
+ sessionData["user_id"] = activityMap.userId;
78
+ sessionData["session_id"] = activityMap.sessionId;
79
+ });
80
+
81
+ //Extracting question reference ids
82
+ cy.get('@fetchActivity').then((resp) => {
83
+ sessionData["activity_template_id"] = resp.response.body.data.fetchActivity.activityTemplateId;
84
+ for (var i = 0; i < resp.response.body.data.fetchActivity.playerData.questions[0].questionParts.length; i++) {
85
+ questionReferenceIds.push(resp.response.body.data.fetchActivity.playerData.questions[0].questionParts[i].referenceId);
86
+ };
87
+ });
88
+ });
89
+
90
+ it('If the user clicks on the Fetch Templates option from the menu bar, user should be navigated to the Fetch Templates API page', () => {
91
+ cy.contains('Sessions')
92
+ .click();
93
+ cy.contains('Fetch Templates')
94
+ .click();
95
+ cy.contains('Fetch Templates')
96
+ .parent()
97
+ .parent()
98
+ .should('have.class', 'Mui-selected');
99
+ cy.url()
100
+ .should('eq', Cypress.config().baseUrl + '/item-engine/data-api/sessions/fetch-templates');
101
+ });
102
+
103
+ it('Example Request should be displayed', () => {
104
+ cy.get('pre[class="body-param__example microlight"]')
105
+ .eq(0)
106
+ .should('have.text', "{\n \"activity_template_id\": \"7f4f28-30a4-3a54-b3e2-5176a2f5c1d\",\n \"items\": [\n \"7f4f28-30a4-3a54-b3e2-5176a2f5c1d\"\n ],\n \"organisation_id\": \"eb7d4a20-c96c-4852-9b34-7e3231016315\"\n}\n");
107
+ });
108
+
109
+ it('Example Response for status code 200 should be displayed', () => {
110
+ cy.get('td[class="response-col_status"]')
111
+ .eq(0)
112
+ .should('have.text', '200');
113
+ cy.get('.response-col_description__inner')
114
+ .eq(0)
115
+ .should('have.text', 'OK');
116
+ cy.get('pre[class="example microlight"]')
117
+ .eq(0)
118
+ .should('have.text', '{\n "meta": {\n "status": "true",\n "timestamp": 1654518860108,\n "records": 1\n },\n "data": {\n "items": [\n {\n "reference": "7f4f28-30a4-3a54-b3e2-5176a2f5c1d",\n "feature_ids": [\n "7257f47-248-87e0-72b4-6f4777aeac"\n ],\n "question_ids": [\n "5004d4b-0d08-46e8-3bd4-73745b758e25",\n "26e03a0-4bd-304f-4b61-8b321be514"\n ]\n }\n ],\n "metadata": {\n "activity_template_id": "7f4f28-30a4-3a54-b3e2-5176a2f5c1d"\n },\n "questions": [\n {\n "id": "5004d4b-0d08-46e8-3bd4-73745b758e25",\n "stimulus": "who is king ?",\n "type": "Multiple Selection"\n },\n {\n "id": "26e03a0-4bd-304f-4b61-8b321be514",\n "stimulus": "fav. season",\n "type": "Essay Response"\n }\n ]\n }\n}\n');
119
+ });
120
+
121
+ it('Example Response for status code 401 should be displayed', () => {
122
+ cy.get('td[class="response-col_status"]')
123
+ .eq(1)
124
+ .should('have.text', '401');
125
+ cy.get('.response-col_description__inner')
126
+ .eq(1)
127
+ .should('have.text', 'Unauthorized');
128
+ cy.get('pre[class="example microlight"]')
129
+ .eq(1)
130
+ .should('have.text', "{\n \"meta\": {\n \"status\": false,\n \"message\": \"Invalid Signature\",\n \"timestamp\": 1653650826764\n },\n \"data\": {}\n}\n");
131
+ });
132
+
133
+ it('Example Response for status code 422 should be displayed', () => {
134
+ cy.get('td[class="response-col_status"]')
135
+ .eq(2)
136
+ .should('have.text', '422');
137
+ cy.get('.response-col_description__inner')
138
+ .eq(2)
139
+ .should('have.text', 'Unprocessable Entity (WebDAV)');
140
+ cy.get('pre[class="example microlight"]')
141
+ .eq(2)
142
+ .should('have.text', "{\n \"meta\": {\n \"status\": false,\n \"message\": \"Invalid OrganisationId\",\n \"timestamp\": 1653650826764\n },\n \"data\": {}\n}\n");
143
+ });
144
+
145
+ it('Example Response for status code 500 should be displayed', () => {
146
+ cy.get('td[class="response-col_status"]')
147
+ .eq(3)
148
+ .should('have.text', '500');
149
+ cy.get('.response-col_description__inner')
150
+ .eq(3)
151
+ .should('have.text', 'Internal Server Error');
152
+ cy.get('pre[class="example microlight"]')
153
+ .eq(3)
154
+ .should('have.text', "{\n \"meta\": {\n \"status\": false,\n \"message\": \"Invalid request\",\n \"timestamp\": 1653650826764\n },\n \"data\": {}\n}\n");
155
+ });
156
+
157
+ it('Entering request without item reference ID and activity template ID', () => {
158
+ cy.get('.try-out__btn')
159
+ .click();
160
+ cy.get('textarea[class="body-param__text"]')
161
+ .clear()
162
+ .fill('{\n "activity_template_id": "",\n "items": [\n ]\n}');
163
+ cy.get('.execute')
164
+ .click();
165
+ cy.wait(2000);
166
+ cy.get('.loading-container')
167
+ .should('not.exist');
168
+ cy.get('pre[class="microlight"]')
169
+ .eq(1)
170
+ .within(() => {
171
+ cy.contains('timestamp')
172
+ .next().next().then((currTimestamp) => {
173
+ timestamp = currTimestamp[0].innerText
174
+ });
175
+ });
176
+ });
177
+
178
+ it('\"invalid request\" error message should be received in the response, with a status code 422', () => {
179
+ cy.get('td[class="response-col_status"]')
180
+ .eq(0)
181
+ .should('have.text', '200');
182
+ cy.get('pre[class="microlight"]')
183
+ .eq(1)
184
+ .should('have.text', `{\n \"meta\": {\n \"message\": \"Invalid request\",\n \"timestamp\": ${timestamp},\n \"status\": false\n },\n \"data\": {}\n}\n`);
185
+ });
186
+
187
+ it('Entering request with a non existing item reference ID and activity template id', () => {
188
+ cy.get('textarea[class="body-param__text"]')
189
+ .clear()
190
+ .fill('{\n "activity_template_id": "dummy activity template id",\n "items": [\n "non existing item reference ID"\n ]\n}');
191
+ cy.get('.execute')
192
+ .click();
193
+ cy.wait(2000);
194
+ cy.get('.loading-container')
195
+ .should('not.exist');
196
+
197
+ //Storing the unknown values from the response for assertion
198
+ cy.get('pre[class="microlight"]')
199
+ .eq(1)
200
+ .within(() => {
201
+ cy.contains('timestamp')
202
+ .next().next().then((currTimestamp) => {
203
+ timestamp = currTimestamp[0].innerText
204
+ });
205
+ });
206
+ });
207
+
208
+ it('Blank questions and items array should be received in the response, with a status code 200', () => {
209
+ cy.get('td[class="response-col_status"]')
210
+ .eq(0)
211
+ .should('have.text', '200');
212
+ cy.get('pre[class="microlight"]')
213
+ .eq(1)
214
+ .should('have.text', `{\n "meta": {\n "records": 0,\n "status": true,\n "timestamp": ${timestamp}\n },\n "data": {\n "metadata": {\n "activity_template_id": "dummy activity template id"\n },\n "questions": [],\n "items": []\n }\n}\n`);
215
+ });
216
+
217
+ it('Entering request with an existing item reference ID', () => {
218
+ cy.get('textarea[class="body-param__text"]')
219
+ .clear()
220
+ .fill(`{\n \"items\": [\n \"${itemReferenceIdNew}\"\n ]\n}`);
221
+ cy.get('.execute')
222
+ .click();
223
+ cy.wait(2000);
224
+ cy.get('.loading-container')
225
+ .should('not.exist');
226
+
227
+ //Storing the unknown values from the response for assertion
228
+ cy.get('pre[class="microlight"]')
229
+ .eq(1)
230
+ .within(() => {
231
+ cy.contains('timestamp')
232
+ .next().next().then((currTimestamp) => {
233
+ timestamp = currTimestamp[0].innerText
234
+ });
235
+ });
236
+ });
237
+
238
+ it('JSON session template of the entered item should be received in the response, with a status code 200', () => {
239
+ cy.get('td[class="response-col_status"]')
240
+ .eq(0)
241
+ .should('have.text', '200');
242
+ cy.get('pre[class="microlight"]')
243
+ .eq(1)
244
+ .should('have.text', `{\n \"meta\": {\n \"records\": 1,\n \"status\": true,\n \"timestamp\": ${timestamp}\n },\n \"data\": {\n \"metadata\": {},\n \"questions\": [\n {\n \"id\": \"b0a1-1b71-2e1-4d8e-677a07687eb\",\n \"stimulus\": \"Which most stable element\",\n \"type\": \"Multiple Selection\"\n },\n {\n \"id\": \"e1e06-58f-532d-1385-ed4cf3ff4f3e\",\n \"stimulus\": \"Which one is most reactive element?\",\n \"type\": \"Multiple Selection\"\n }\n ],\n \"items\": [\n {\n \"reference\": \"f72bdb8-e6ad-64f-617b-fe40d2b0a7\",\n \"feature_ids\": [],\n \"question_ids\": [\n \"b0a1-1b71-2e1-4d8e-677a07687eb\",\n \"e1e06-58f-532d-1385-ed4cf3ff4f3e\"\n ]\n }\n ]\n }\n}\n`);
245
+ });
246
+ });
@@ -0,0 +1,218 @@
1
+ import { questionAndResourceReferenceIds } from '../../support/helpers/createItem'
2
+ import utilities from "../../support/helpers/utilities";
3
+
4
+ var sessionID;
5
+ var timestamp;
6
+ let itemReferenceIdNew;
7
+
8
+ describe('Modify Items API cases', () => {
9
+
10
+ before(() => {
11
+ cy.loginAs('admin');
12
+ cy.createItem('modifyItemAPI');
13
+ cy.visit(`${Cypress.env('itemEngineHomePage')}`);
14
+ });
15
+
16
+ after(() => {
17
+ cy.deleteItems();
18
+ cy.logout();
19
+ });
20
+
21
+ it('If the user clicks on the Modify Items option from the menu bar, user should be navigated to the Modify Items API page', () => {
22
+ cy.contains('Sessions')
23
+ .click();
24
+ cy.contains('Modify Items')
25
+ .click();
26
+ cy.contains('Modify Items')
27
+ .parent()
28
+ .parent()
29
+ .should('have.class', 'Mui-selected');
30
+ cy.url()
31
+ .should('eq', Cypress.config().baseUrl + '/item-engine/data-api/sessions/modify-items');
32
+ });
33
+
34
+ it('Example Request should be displayed', () => {
35
+ cy.get('pre[class="body-param__example microlight"]')
36
+ .eq(0)
37
+ .should('have.text', "{\n \"item_reference_ids\": [\n \"Math problem item\"\n ],\n \"session_ids\": [\n \"27ead214-4435-4e99-aa01-569ff6ccb99d\"\n ],\n \"response_ids\": [],\n \"should_update_time\": false,\n \"organisation_id\": \"eb7d4a20-c96c-4852-9b34-7e3231016315\"\n}\n");
38
+ });
39
+
40
+ it('Example Response for status code 200 should be displayed', () => {
41
+ cy.get('td[class="response-col_status"]')
42
+ .eq(0)
43
+ .should('have.text', '200');
44
+ cy.get('.response-col_description__inner')
45
+ .eq(0)
46
+ .should('have.text', 'OK');
47
+ cy.get('pre[class="example microlight"]')
48
+ .eq(0)
49
+ .should('have.text', "{\n \"meta\": {\n \"status\": true,\n \"timestamp\": 1653650826764\n }\n}\n");
50
+ });
51
+
52
+ it('Example Response for status code 401 should be displayed', () => {
53
+ cy.get('td[class="response-col_status"]')
54
+ .eq(1)
55
+ .should('have.text', '401');
56
+ cy.get('.response-col_description__inner')
57
+ .eq(1)
58
+ .should('have.text', 'Unauthorized');
59
+ cy.get('pre[class="example microlight"]')
60
+ .eq(1)
61
+ .should('have.text', "{\n \"meta\": {\n \"status\": false,\n \"message\": \"Invalid Signature\",\n \"timestamp\": 1653650826764\n }\n}\n");
62
+ });
63
+
64
+ it('Example Response for status code 422 should be displayed', () => {
65
+ cy.get('td[class="response-col_status"]')
66
+ .eq(2)
67
+ .should('have.text', '422');
68
+ cy.get('.response-col_description__inner')
69
+ .eq(2)
70
+ .should('have.text', 'Unprocessable Entity (WebDAV)');
71
+ cy.get('pre[class="example microlight"]')
72
+ .eq(2)
73
+ .should('have.text', "{\n \"meta\": {\n \"status\": false,\n \"message\": \"Invalid OrganisationId\",\n \"timestamp\": 1653650826764\n }\n}\n");
74
+ });
75
+
76
+ it('Example Response for status code 500 should be displayed', () => {
77
+ cy.get('td[class="response-col_status"]')
78
+ .eq(3)
79
+ .should('have.text', '500');
80
+ cy.get('.response-col_description__inner')
81
+ .eq(3)
82
+ .should('have.text', 'Internal Server Error');
83
+ cy.get('pre[class="example microlight"]')
84
+ .eq(3)
85
+ .should('have.text', "{\n \"meta\": {\n \"status\": false,\n \"message\": \"Error occurred while saving data\",\n \"timestamp\": 1653650826764\n }\n}\n");
86
+ });
87
+
88
+ it('Entering request without item reference ID ', () => {
89
+ cy.get('.try-out__btn')
90
+ .click();
91
+ cy.get('textarea[class="body-param__text"]')
92
+ .clear()
93
+ .fill('{\n "item_reference_ids": [\n ""\n ]\n}');
94
+ cy.get('.execute')
95
+ .click();
96
+ cy.wait(2000);
97
+ cy.get('.loading-container')
98
+ .should('not.exist');
99
+ cy.get('pre[class="microlight"]')
100
+ .eq(1)
101
+ .within(() => {
102
+ cy.contains('timestamp')
103
+ .next().next().then((currTimestamp) => {
104
+ timestamp = currTimestamp[0].innerText
105
+ });
106
+ });
107
+ });
108
+
109
+ it('\"item_reference_ids[0]\" is not allowed to be empty" error message should be received in the response, with a status code 422', () => {
110
+ cy.get('td[class="response-col_status"]')
111
+ .eq(0)
112
+ .should('have.text', '200');
113
+ cy.get('pre[class="microlight"]')
114
+ .eq(1)
115
+ .should('have.text', `{\n \"meta\": {\n \"message\": \"\\\"item_reference_ids[0]\\\" is not allowed to be empty\",\n \"timestamp\": ${timestamp},\n \"status\": false\n }\n}\n`);
116
+ });
117
+
118
+ it('Entering request with a non existing item reference ID', () => {
119
+ cy.get('textarea[class="body-param__text"]')
120
+ .clear()
121
+ .fill('{\n "item_reference_ids": [\n "non existing item reference ID"\n ]\n}');
122
+ cy.get('.execute')
123
+ .click();
124
+ cy.wait(2000);
125
+ cy.get('.loading-container')
126
+ .should('not.exist');
127
+ cy.get('pre[class="microlight"]')
128
+ .eq(1)
129
+ .within(() => {
130
+ cy.contains('timestamp')
131
+ .next().next().then((currTimestamp) => {
132
+ timestamp = currTimestamp[0].innerText
133
+ });
134
+ });
135
+ });
136
+
137
+ it('\'item_reference_ids does not exist\' error message should be received in the response, with a status code 400', () => {
138
+ cy.get('td[class="response-col_status"]')
139
+ .eq(0)
140
+ .should('have.text', '200');
141
+ cy.get('pre[class="microlight"]')
142
+ .eq(1)
143
+ .should('have.text', `{\n \"meta\": {\n \"message\": \"\\\"session_ids\\\" is required\",\n \"timestamp\": ${timestamp},\n \"status\": false\n }\n}\n`);
144
+ });
145
+
146
+ it('fetch question reference id from the api', () => {
147
+ cy.contains('Item Bank')
148
+ .click();
149
+ cy.contains('Fetch Questions')
150
+ .click();
151
+ cy.contains('Fetch Questions')
152
+ .parent()
153
+ .parent()
154
+ .should('have.class', 'Mui-selected');
155
+ cy.url()
156
+ .should('eq', Cypress.config().baseUrl + '/item-engine/data-api/item-bank/fetch-questions');
157
+ cy.get('.try-out__btn')
158
+ .click();
159
+ cy.get('textarea[class="body-param__text"]')
160
+ .clear()
161
+ .fill(`{\n "item_references": ["modifyItemAPI"],\n "references": [],\n "types": [],\n "limit": 50,\n "sort_field": "created",\n "sort": "desc"\n}\n`);
162
+ cy.get('.execute')
163
+ .click();
164
+ cy.wait(2000);
165
+ cy.get('.loading-container')
166
+ .should('not.exist');
167
+ cy.get('pre[class="microlight"]')
168
+ .eq(1)
169
+ .invoke('text')
170
+ .then((text) => {
171
+ // Parse the JSON from the DOM
172
+ const actualResponse = JSON.parse(text);
173
+ // Extract dynamic values from the parsed object
174
+ const test1Data = actualResponse.data.modifyItemAPI[0];
175
+ const { reference: ref1 } = test1Data;
176
+ itemReferenceIdNew = ref1;
177
+ });
178
+ });
179
+
180
+ it('Entering request with an existing item reference ID', () => {
181
+ //Extracting session ID
182
+ cy.interceptGraphql('createOrUpdateUserSession');
183
+ cy.visit(`/item-engine/demo/render-item/student-view/${utilities.base64Encoding(itemReferenceIdNew)}`)
184
+ cy.wait('@createOrUpdateUserSession');
185
+ cy.get('@createOrUpdateUserSession').then((data) => {
186
+ sessionID = data.request.body.variables.input.sessionData.itemActivityMap[0].sessionId;
187
+ }).then(() => {
188
+ cy.visit('/item-engine/data-api/sessions/modify-items');
189
+ cy.get('.try-out__btn')
190
+ .click();
191
+ cy.get('textarea[class="body-param__text"]')
192
+ .clear()
193
+ .fill(`{\n "item_reference_ids": [\n "${itemReferenceIdNew}"\n ],\n "session_ids": ["${sessionID}"] \n}`);
194
+ cy.get('.execute')
195
+ .click();
196
+ cy.wait(2000);
197
+ cy.get('.loading-container')
198
+ .should('not.exist');
199
+ });
200
+ cy.get('pre[class="microlight"]')
201
+ .eq(1)
202
+ .within(() => {
203
+ cy.contains('timestamp')
204
+ .next().next().then((currTimestamp) => {
205
+ timestamp = currTimestamp[0].innerText
206
+ });
207
+ });
208
+ });
209
+
210
+ it('Status:true should be received in the response, with a status code 200', () => {
211
+ cy.get('td[class="response-col_status"]')
212
+ .eq(0)
213
+ .should('have.text', '200');
214
+ cy.get('pre[class="microlight"]')
215
+ .eq(1)
216
+ .should('have.text', `{\n \"meta\": {\n \"status\": true,\n \"timestamp\": ${timestamp}\n }\n}\n`);
217
+ });
218
+ });