From 2a856a83e8ee216fae3cd686bbfc7a9a71ed0281 Mon Sep 17 00:00:00 2001 From: BharathwajShankar Date: Fri, 31 May 2024 16:37:35 +0530 Subject: [PATCH 1/2] postman pre-requisite script addition --- .../Lms_APIs Test.postman_collection.json | 118 +++++++++++++----- .../Lms_APIs.postman_collection.json | 61 +++++++-- .../Lms_Environment.postman_environment.json | 18 ++- 3 files changed, 151 insertions(+), 46 deletions(-) diff --git a/api-tests/Collection/Lms_APIs Test.postman_collection.json b/api-tests/Collection/Lms_APIs Test.postman_collection.json index 2ea14b4ba..71f04b03e 100644 --- a/api-tests/Collection/Lms_APIs Test.postman_collection.json +++ b/api-tests/Collection/Lms_APIs Test.postman_collection.json @@ -41,7 +41,8 @@ "// pm.collectionVariables.set(\"variable_key\", \"variable_value\");", "" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -77,12 +78,12 @@ }, { "key": "username", - "value": "{{username}}", + "value": "{{org_admin_username}}", "type": "text" }, { "key": "password", - "value": "{{password}}", + "value": "{{org_admin_password}}", "type": "text" } ] @@ -202,7 +203,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"name\": \"{{batch_name}}\",\n \"enrollmentType\": \"open\",\n \"startDate\": \"{{batch_start_date}}\"\n }\n}" + "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"userId\": \"{{user_id}}\",\n \"name\": \"{{batch_name}}\",\n \"enrollmentType\": \"open\",\n \"startDate\": \"{{batch_start_date}}\"\n }\n}" }, "url": "{{host}}/api/course/v1/batch/create" }, @@ -247,7 +248,8 @@ " pm.expect(jsonResponse.params.errmsg).to.eql(\"Mandatory parameter enrollmentType is missing.\");", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -275,7 +277,7 @@ "mode": "raw", "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"name\": \"{{batch_name}}\"\n }\n}" }, - "url": "https://dev.sunbirded.org/api/course/v1/batch/create" + "url": "{{host}}/api/course/v1/batch/create" }, "response": [] }, @@ -313,7 +315,8 @@ " pm.expect(jsonResponse.params.errmsg).to.eql(\"Mandatory parameter startDate is missing.\");", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -341,7 +344,7 @@ "mode": "raw", "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"name\": \"{{batch_name}}\",\n \"description\": \"{{batch_description}}\",\n \"enrollmentType\": \"open\",\n \"endDate\": \"{{batch_end_date}}\"\n }\n}" }, - "url": "https://dev.sunbirded.org/api/course/v1/batch/create" + "url": "{{host}}/api/course/v1/batch/create" }, "response": [] }, @@ -379,7 +382,8 @@ " pm.expect(jsonResponse.params.errmsg).to.eql(\"Mandatory parameter courseId/collectionId is missing.\");", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -407,7 +411,7 @@ "mode": "raw", "raw": "{\n \"request\": {\n \"name\": \"{{batch_name}}\",\n \"description\": \"{{batch_description}}\",\n \"enrollmentType\": \"open\",\n \"endDate\": \"{{batch_end_date}}\"\n }\n}" }, - "url": "https://dev.sunbirded.org/api/course/v1/batch/create" + "url": "{{host}}/api/course/v1/batch/create" }, "response": [] }, @@ -444,7 +448,8 @@ " pm.expect(jsonResponse.params.errmsg).to.eql(\"Mandatory parameter name is missing.\");", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -472,7 +477,7 @@ "mode": "raw", "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"description\": \"{{batch_description}}\",\n \"enrollmentType\": \"open\",\n \"startDate\": \"{{batch_start_date}}\",\n \"endDate\": \"{{batch_end_date}}\"\n }\n}" }, - "url": "https://dev.sunbirded.org/api/course/v1/batch/create" + "url": "{{host}}/api/course/v1/batch/create" }, "response": [] }, @@ -509,7 +514,8 @@ " pm.expect(jsonResponse.params.errmsg).to.eql(\"Date format error.\");", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -537,7 +543,7 @@ "mode": "raw", "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"name\": \"{{batch_name}}\",\n \"description\": \"{{batch_description}}\",\n \"enrollmentType\": \"open\",\n \"startDate\": \"05/09/2023\",\n \"endDate\": \"{{batch_end_date}}\"\n }\n}" }, - "url": "https://dev.sunbirded.org/api/course/v1/batch/create" + "url": "{{host}}/api/course/v1/batch/create" }, "response": [] }, @@ -574,7 +580,8 @@ " pm.expect(jsonResponse.params.errmsg).to.eql(\"Invalid value join for parameter enrollmentType. Please provide a valid value.\");", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -602,7 +609,7 @@ "mode": "raw", "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"name\": \"{{batch_name}}\",\n \"description\": \"{{batch_description}}\",\n \"enrollmentType\": \"join\",\n \"startDate\": \"{{batch_start_date}}\",\n \"endDate\": \"{{batch_end_date}}\"\n }\n}" }, - "url": "https://dev.sunbirded.org/api/course/v1/batch/create" + "url": "{{host}}/api/course/v1/batch/create" }, "response": [] }, @@ -639,7 +646,8 @@ " pm.expect(jsonResponse.params.errmsg).to.eql(\"End date should be greater than start date.\");", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -667,7 +675,7 @@ "mode": "raw", "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"name\": \"{{batch_name}}\",\n \"description\": \"{{batch_description}}\",\n \"enrollmentType\": \"open\",\n \"startDate\": \"{{batch_start_date}}\",\n \"endDate\": \"2023-04-01\"\n }\n}" }, - "url": "https://dev.sunbirded.org/api/course/v1/batch/create" + "url": "{{host}}/api/course/v1/batch/create" }, "response": [] }, @@ -705,7 +713,8 @@ " pm.expect(jsonResponse.params.errmsg).to.eql(\"Batch start date should be either today or future date.\");", "});" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -733,7 +742,7 @@ "mode": "raw", "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"name\": \"{{batch_name}}\",\n \"description\": \"{{batch_description}}\",\n \"enrollmentType\": \"open\",\n \"startDate\": \"2023-01-01\",\n \"endDate\": \"{{batch_end_date}}\"\n }\n}" }, - "url": "https://dev.sunbirded.org/api/course/v1/batch/create" + "url": "{{host}}/api/course/v1/batch/create" }, "response": [] } @@ -1317,7 +1326,8 @@ "});", "" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -1343,7 +1353,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"request\": {\n \"courseId\": \"do_113776650927300608138\",\n \"name\": \"{{batch_name}}\",\n \"description\": \"{{batch_description}}\",\n \"enrollmentType\": \"open\",\n \"startDate\": \"2023-01-01\",\n \"endDate\": \"{{batch_end_date}}\",\n \"id\": \"01377666464491929614\"\n }\n}" + "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"name\": \"{{batch_name}}\",\n \"description\": \"{{batch_description}}\",\n \"enrollmentType\": \"open\",\n \"startDate\": \"2023-01-01\",\n \"endDate\": \"{{batch_end_date}}\",\n \"id\": \"01377666260145766417\"\n }\n}" }, "url": "{{host}}/api/course/v1/batch/update" }, @@ -2333,16 +2343,13 @@ " pm.expect(jsonResponse.responseCode).to.eql(\"CLIENT_ERROR\");", "});", "", - "pm.test(\"err should be SERVER_ERROR\", function () {", - " pm.expect(jsonResponse.params.err).to.eql(\"SERVER_ERROR\");", - "});", - "", "pm.test(\"status should be SERVER_ERROR\", function () {", " pm.expect(jsonResponse.params.status).to.eql(\"SERVER_ERROR\");", "});", "" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -5787,14 +5794,14 @@ ], "body": { "mode": "raw", - "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"batchId\": \"{{batch_id}}\"\n }\n}", + "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"batchId\": \"{{batch_id}}\",\n \"userId\": \"{{user_id}}\"\n }\n}", "options": { "raw": { "language": "json" } } }, - "url": "{{host}}/api/course/v1/enroll" + "url": "{{host}}/api/course/v1/enrol" }, "response": [] }, @@ -5826,14 +5833,14 @@ ], "body": { "mode": "raw", - "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"batchId\": \"{{batch_id}}\"\n }\n}", + "raw": "{\n \"request\": {\n \"courseId\": \"{{course_id}}\",\n \"batchId\": \"{{batch_id}}\",\n \"userId\": \"{{user_id}}\"\n }\n}", "options": { "raw": { "language": "json" } } }, - "url": "{{host}}/api/course/v1/unenroll" + "url": "{{host}}/api/course/v1/unenrol" }, "response": [] }, @@ -6479,6 +6486,49 @@ "script": { "type": "text/javascript", "exec": [ + " const requiresHeaders = () => {", + " const requestUrl = pm.request.url.toString();", + "", + " // List of paths to ignore", + " const ignoredPaths = [", + " '/health',", + " '/auth/realms/sunbird/protocol/openid-connect/token',", + " '/auth/v1/refresh/token'", + " ];", + "", + " // Check if the request URL contains any of the ignored paths", + " return !ignoredPaths.some(path => requestUrl.includes(path));", + "};", + "", + "// Function to check if a specific header is present and not empty", + "const isHeaderProvided = (headerName) => {", + " const headers = pm.request.headers;", + " if (!headers) return false; // Check if headers exist", + "", + " // Find the specified header", + " const header = headers.find(h => h.key.toLowerCase() === headerName.toLowerCase());", + "", + " // Check if the header exists and is not disabled and its value is not empty", + " return header && !header.disabled && header.value.trim() !== '';", + "};", + "", + "// Check if the current endpoint requires headers", + "if (requiresHeaders()) {", + " // Check if Authorization header is provided", + " if (!isHeaderProvided('Authorization')) {", + " // If Authorization header is missing or empty, throw an error", + " throw new Error('Authorization header is missing or empty. Please provide a valid Authorization header.');", + " }", + "", + " // Check if X-Authenticated-User-Token header is provided", + " if (!isHeaderProvided('X-Authenticated-User-Token')) {", + " // If X-Authenticated-User-Token header is missing or empty, throw an error", + " throw new Error('X-Authenticated-User-Token header is missing or empty. Please provide a valid X-Authenticated-User-Token header.');", + " }", + "} else {", + " console.log('Skipping header checks for this endpoint.');", + "}", + "", " function generateRandomBatchName() {", " const adjectives = ['Advanced', 'Beginner', 'Intermediate', 'Expert', 'Pro', 'Novice', 'Skilled', 'Enthusiastic'];", " const subjects = ['Math', 'Science', 'History', 'Literature', 'Programming', 'Languages', 'Art', 'Music'];", @@ -6551,5 +6601,11 @@ ] } } + ], + "variable": [ + { + "key": "refresh_token", + "value": "" + } ] } \ No newline at end of file diff --git a/api-tests/Collection/Lms_APIs.postman_collection.json b/api-tests/Collection/Lms_APIs.postman_collection.json index b43993966..36027f435 100644 --- a/api-tests/Collection/Lms_APIs.postman_collection.json +++ b/api-tests/Collection/Lms_APIs.postman_collection.json @@ -41,7 +41,8 @@ "// pm.collectionVariables.set(\"variable_key\", \"variable_value\");", "" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -77,12 +78,12 @@ }, { "key": "username", - "value": "{{username}}", + "value": "{{org_admin_username}}", "type": "text" }, { "key": "password", - "value": "{{password}}", + "value": "{{org_admin_password}}", "type": "text" } ] @@ -388,7 +389,8 @@ "});", "" ], - "type": "text/javascript" + "type": "text/javascript", + "packages": {} } } ], @@ -422,7 +424,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"request\": {\n \"enrollmentType\": \"open\",\n \"startDate\": \"2023-09-08\",\n \"enrollmentEndDate\": \"{{batch_end_date}}\",\n \"status\": 1,\n \"courseId\": \"{{course_id}}\",\n \"id\": \"{{batch_id}}\"\n }\n}" + "raw": "{\n \"request\": {\n \"enrollmentType\": \"open\",\n \"startDate\": \"{{batch_start_date}}\",\n \"enrollmentEndDate\": \"{{batch_end_date}}\",\n \"status\": 1,\n \"courseId\": \"{{course_id}}\",\n \"id\": \"{{batch_id}}\"\n }\n}" }, "url": "{{host}}/api/course/v1/batch/update" }, @@ -1727,7 +1729,7 @@ } } }, - "url": "{{host}}/api/course/v1/enroll" + "url": "{{host}}/api/v1/course/enroll" }, "response": [] }, @@ -2121,14 +2123,49 @@ "script": { "type": "text/javascript", "exec": [ - " if (pm.environment.get(\"environment\") === \"local\") {", - " var baseURL = pm.environment.get(\"host\")", - " pm.variables.set(\"baseURL\", baseURL);", - " } else {", - " var baseURL = pm.environment.get(\"host\") + pm.variables.get(\"basePath\");", - " pm.variables.set(\"baseURL\", baseURL);", + " const requiresHeaders = () => {", + " const requestUrl = pm.request.url.toString();", + "", + " // List of paths to ignore", + " const ignoredPaths = [", + " '/health',", + " '/auth/realms/sunbird/protocol/openid-connect/token',", + " '/auth/v1/refresh/token'", + " ];", + "", + " // Check if the request URL contains any of the ignored paths", + " return !ignoredPaths.some(path => requestUrl.includes(path));", + "};", + "", + "// Function to check if a specific header is present and not empty", + "const isHeaderProvided = (headerName) => {", + " const headers = pm.request.headers;", + " if (!headers) return false; // Check if headers exist", + "", + " // Find the specified header", + " const header = headers.find(h => h.key.toLowerCase() === headerName.toLowerCase());", + "", + " // Check if the header exists and is not disabled and its value is not empty", + " return header && !header.disabled && header.value.trim() !== '';", + "};", + "", + "// Check if the current endpoint requires headers", + "if (requiresHeaders()) {", + " // Check if Authorization header is provided", + " if (!isHeaderProvided('Authorization')) {", + " // If Authorization header is missing or empty, throw an error", + " throw new Error('Authorization header is missing or empty. Please provide a valid Authorization header.');", " }", "", + " // Check if X-Authenticated-User-Token header is provided", + " if (!isHeaderProvided('X-Authenticated-User-Token')) {", + " // If X-Authenticated-User-Token header is missing or empty, throw an error", + " throw new Error('X-Authenticated-User-Token header is missing or empty. Please provide a valid X-Authenticated-User-Token header.');", + " }", + "} else {", + " console.log('Skipping header checks for this endpoint.');", + "}", + "", " function generateRandomBatchName() {", " const adjectives = ['Advanced', 'Beginner', 'Intermediate', 'Expert', 'Pro', 'Novice', 'Skilled', 'Enthusiastic'];", " const subjects = ['Math', 'Science', 'History', 'Literature', 'Programming', 'Languages', 'Art', 'Music'];", diff --git a/api-tests/Collection/Lms_Environment.postman_environment.json b/api-tests/Collection/Lms_Environment.postman_environment.json index c726ea44a..628add4c7 100644 --- a/api-tests/Collection/Lms_Environment.postman_environment.json +++ b/api-tests/Collection/Lms_Environment.postman_environment.json @@ -1,5 +1,5 @@ { - "id": "16f7dd4a-cd4d-4e5f-b665-36b3c4af11e3", + "id": "84f7c492-436b-4a03-8485-0c4e4db5bd0c", "name": "Lms_Environment", "values": [ { @@ -101,9 +101,21 @@ "value": "", "type": "default", "enabled": true + }, + { + "key": "org_admin_username", + "value": "", + "type": "default", + "enabled": true + }, + { + "key": "org_admin_password", + "value": "", + "type": "default", + "enabled": true } ], "_postman_variable_scope": "environment", - "_postman_exported_at": "2023-09-21T11:19:38.145Z", - "_postman_exported_using": "Postman/10.18.3" + "_postman_exported_at": "2024-05-30T09:58:06.700Z", + "_postman_exported_using": "Postman/10.24.25" } \ No newline at end of file From 92c45f66e3f5396bbba99f3c243070bbb0108316 Mon Sep 17 00:00:00 2001 From: BharathwajShankar Date: Fri, 31 May 2024 16:41:34 +0530 Subject: [PATCH 2/2] postman pre-requisite script addition --- api-tests/Collection/Lms_APIs Test.postman_collection.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api-tests/Collection/Lms_APIs Test.postman_collection.json b/api-tests/Collection/Lms_APIs Test.postman_collection.json index 71f04b03e..7efa29bdb 100644 --- a/api-tests/Collection/Lms_APIs Test.postman_collection.json +++ b/api-tests/Collection/Lms_APIs Test.postman_collection.json @@ -5801,7 +5801,7 @@ } } }, - "url": "{{host}}/api/course/v1/enrol" + "url": "{{host}}/api/course/v1/enroll" }, "response": [] }, @@ -5840,7 +5840,7 @@ } } }, - "url": "{{host}}/api/course/v1/unenrol" + "url": "{{host}}/api/course/v1/unenroll" }, "response": [] },