Skip to content

Commit

Permalink
postman pre-requisite script addition
Browse files Browse the repository at this point in the history
  • Loading branch information
BharathwajShankar committed May 31, 2024
1 parent 75246aa commit f54ec5d
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 26 deletions.
48 changes: 43 additions & 5 deletions api-tests/Collections/UserOrg_APIs Test.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"info": {
"_postman_id": "dbb9ef35-6501-41d3-aadf-96dd74f9b906",
"_postman_id": "3bec4286-bb4a-4a19-b81e-75b29644aeb5",
"name": "UserOrg_APIs Test",
"description": "The User ORG API is a collection of API's for creation and management of User and Org in sunbird platform.",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json",
"_exporter_id": "4875988",
"_collection_link": "https://dark-star-147860.postman.co/workspace/LernBBAPIs~32e17cc4-6806-407e-b8ef-485ad4d0b712/collection/4875988-dbb9ef35-6501-41d3-aadf-96dd74f9b906?action=share&source=collection_link&creator=4875988"
"_collection_link": "https://dark-star-147860.postman.co/workspace/LernBBAPIs~32e17cc4-6806-407e-b8ef-485ad4d0b712/collection/4875988-3bec4286-bb4a-4a19-b81e-75b29644aeb5?action=share&source=collection_link&creator=4875988"
},
"item": [
{
Expand Down Expand Up @@ -4014,7 +4014,8 @@
" pm.expect(jsonResponse.token_type).to.eql('bearer');",
"});"
],
"type": "text/javascript"
"type": "text/javascript",
"packages": {}
}
}
],
Expand Down Expand Up @@ -4046,12 +4047,12 @@
},
{
"key": "username",
"value": "{{username}}",
"value": "{{org_admin_username}}",
"type": "text"
},
{
"key": "password",
"value": "{{password}}",
"value": "{{org_admin_password}}",
"type": "text"
}
]
Expand Down Expand Up @@ -21973,6 +21974,43 @@
"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.');",
" }",
"} else {",
" console.log('Skipping header checks for this endpoint.');",
"}",
"",
"const getRandomName = () => {",
"const firstNames = [\"Aarav\", \"Aarya\", \"Advait\", \"Aishwarya\", \"Akshay\", \"Ananya\", \"Aaradhya\", \"Ayush\", \"Deepika\", \"Ishaan\"];",
"const lastNames = [\"Sharma\", \"Verma\", \"Singh\", \"Patel\", \"Gupta\", \"Kumar\", \"Joshi\", \"Shah\", \"Chopra\", \"Mehra\"];",
Expand Down
90 changes: 73 additions & 17 deletions api-tests/Collections/UserOrg_APIs.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"info": {
"_postman_id": "b3270121-69ca-422c-a273-17edf98135fd",
"_postman_id": "5ed5cbe6-8c1c-4638-a156-acb98d507d31",
"name": "UserOrg_APIs",
"description": "The User ORG API is a collection of API's for creation and management of User and Org in sunbird platform.",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json",
"_exporter_id": "4875988",
"_collection_link": "https://dark-star-147860.postman.co/workspace/LernBBAPIs~32e17cc4-6806-407e-b8ef-485ad4d0b712/collection/4875988-b3270121-69ca-422c-a273-17edf98135fd?action=share&source=collection_link&creator=4875988"
"_collection_link": "https://dark-star-147860.postman.co/workspace/LernBBAPIs~32e17cc4-6806-407e-b8ef-485ad4d0b712/collection/4875988-5ed5cbe6-8c1c-4638-a156-acb98d507d31?action=share&source=collection_link&creator=4875988"
},
"item": [
{
Expand Down Expand Up @@ -247,20 +247,33 @@
" pm.expect(jsonResponse.responseCode).to.eql(\"OK\");",
"});"
],
"type": "text/javascript"
"type": "text/javascript",
"packages": {}
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "{{kong_api_key}}"
"key": "Content-Type",
"value": "application/json",
"type": "text"
},
{
"key": "Content-Type",
"value": "application/json"
"key": "Authorization",
"value": "{{kong_api_key}}",
"type": "text"
}
],
"body": {
Expand Down Expand Up @@ -410,24 +423,28 @@
" pm.expect(jsonResponse.responseCode).to.eql(\"OK\");",
"});"
],
"type": "text/javascript"
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "{{kong_api_key}}"
},
{
"key": "X-Authenticated-User-token",
"value": "{{access_token}}"
"value": "{{keycloak_access_token}}",
"type": "text"
},
{
"key": "Content-Type",
"value": "application/json"
"value": "application/json",
"type": "text"
},
{
"key": "Authorization",
"value": "{{kong_api_key}}",
"type": "text"
}
],
"body": {
Expand Down Expand Up @@ -1951,15 +1968,18 @@
"header": [
{
"key": "Authorization",
"value": "{{kong_api_key}}"
"value": "{{kong_api_key}}",
"type": "text"
},
{
"key": "X-Authenticated-User-token",
"value": "{{keycloak_access_token}}"
"value": "{{keycloak_access_token}}",
"type": "text"
},
{
"key": "Content-Type",
"value": "application/json"
"value": "application/json",
"type": "text"
}
],
"body": {
Expand Down Expand Up @@ -4873,6 +4893,42 @@
"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.');",
" }",
"} else {",
" console.log('Skipping header checks for this endpoint.');",
"}",
"const getRandomName = () => {",
"const firstNames = [\"Aarav\", \"Aarya\", \"Advait\", \"Aishwarya\", \"Akshay\", \"Ananya\", \"Aaradhya\", \"Ayush\", \"Deepika\", \"Ishaan\"];",
"const lastNames = [\"Sharma\", \"Verma\", \"Singh\", \"Patel\", \"Gupta\", \"Kumar\", \"Joshi\", \"Shah\", \"Chopra\", \"Mehra\"];",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "8e9c6ddc-5534-4d67-b85e-67690cade87f",
"name": "Lern_Environment",
"id": "9cb09471-4154-48ca-8b63-1810101f42b6",
"name": "UserOrg_Environment",
"values": [
{
"key": "kong_api_key",
Expand Down Expand Up @@ -268,9 +268,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-08-22T11:20:43.606Z",
"_postman_exported_using": "Postman/10.17.2"
"_postman_exported_at": "2024-05-30T09:55:54.569Z",
"_postman_exported_using": "Postman/10.24.25"
}

0 comments on commit f54ec5d

Please sign in to comment.