diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9ffe035..82eb82bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -147,6 +147,20 @@ jobs: - name: Env seen run: env + + - name: Run crAPI using built images + run: VERSION=${{ env.TAG_NAME }} docker-compose -f deploy/docker/docker-compose.yml --compatibility up -d + + - name: Install Node + uses: actions/setup-node@v3 + with: + node-version: 14 + + - name: Install newman + run: npm install -g newman + + - name: Run Postman Collection + run: (newman run "./postman_collections/crAPI Accepted.postman_collection.json" -e ./postman_collections/Crapi.postman_environment.json) || true - name: Build crapi-identity all platforms and conditionally push to Docker Hub uses: docker/build-push-action@v2 @@ -199,4 +213,3 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max - diff --git a/postman_collections/Crapi.postman_environment.json b/postman_collections/Crapi.postman_environment.json new file mode 100644 index 00000000..b86e755d --- /dev/null +++ b/postman_collections/Crapi.postman_environment.json @@ -0,0 +1,23 @@ +{ + "id": "d72c78a4-a99a-4413-88f6-0a3bb4cdbc1c", + "name": "Crapi", + "values": [{ + "key": "url", + "value": "http://127.0.0.1:8888", + "enabled": true + }, + { + "key": "url_mail", + "value": "http://127.0.0.1:8025", + "enabled": true + }, + { + "key": "video_file", + "value": "./postman_collections/car.mp4", + "enabled": true + } + ], + "_postman_variable_scope": "environment", + "_postman_exported_at": "2022-05-07T14:12:58.459Z", + "_postman_exported_using": "Postman/9.17.2" +} \ No newline at end of file diff --git a/postman_collections/car.mp4 b/postman_collections/car.mp4 new file mode 100644 index 00000000..43f62d21 Binary files /dev/null and b/postman_collections/car.mp4 differ diff --git a/postman_collections/crAPI Accepted.postman_collection.json b/postman_collections/crAPI Accepted.postman_collection.json new file mode 100644 index 00000000..586bb445 --- /dev/null +++ b/postman_collections/crAPI Accepted.postman_collection.json @@ -0,0 +1,2077 @@ +{ + "info": { + "_postman_id": "108b5557-e108-41ad-b9c9-28811eb81b1e", + "name": "crAPI Accepted", + "description": "crAPI Training Scripts", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Signup example.com", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "const {Property} = require('postman-collection');", + "", + "let name = Property.replaceSubstitutions('{{$randomFirstName}}.{{$randomLastName}}');", + "pm.globals.set(\"name\", name);", + "let newName = Property.replaceSubstitutions('{{$randomFirstName}}.{{$randomLastName}}');", + "pm.globals.set(\"new_name\", newName);", + "let email = name+\"@example.com\";", + "let newEmail = newName+\"@example.com\";", + "let pass = Property.replaceSubstitutions(\"{{$randomPassword}}\");", + "let phone = Property.replaceSubstitutions(\"{{$randomPhoneNumber}}\").replace(/-/g,'');", + "pm.globals.set(\"email\", email);", + "pm.globals.set(\"new_email\", newEmail);", + "pm.globals.set(\"password\", pass);", + "pm.globals.set(\"name\", name);", + "pm.globals.set(\"phone\", phone);", + "console.log(email, newEmail, pass, phone);", + "console.log(name );" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "noauth" + }, + "method": "POST", + "header": [ + { + "key": "User-Agent", + "value": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" + }, + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Accept", + "value": "*/*" + } + ], + "body": { + "mode": "raw", + "raw": "{\"name\":\"{{name}}\",\"email\":\"{{email}}\",\"number\":\"{{phone}}\",\"password\":\"{{password}}\"}" + }, + "url": { + "raw": "{{url}}/identity/api/auth/signup", + "host": [ + "{{url}}" + ], + "path": [ + "identity", + "api", + "auth", + "signup" + ] + } + }, + "response": [] + }, + { + "name": "Login", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + " var jsonData = JSON.parse(responseBody);", + " pm.globals.set(\"token\", jsonData.token);", + " var token = pm.globals.get(\"token\");", + " pm.test(\"Token is set\", function () {", + " pm.expect(jsonData.token).to.eql(token);", + " });", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "noauth" + }, + "method": "POST", + "header": [ + { + "key": "User-Agent", + "value": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" + }, + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Accept", + "value": "*/*" + } + ], + "body": { + "mode": "raw", + "raw": "{\"email\":\"{{email}}\",\"password\":\"{{password}}\"}" + }, + "url": { + "raw": "{{url}}/identity/api/auth/login", + "host": [ + "{{url}}" + ], + "path": [ + "identity", + "api", + "auth", + "login" + ] + } + }, + "response": [] + }, + { + "name": "Forgot Password", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + " var jsonData = JSON.parse(responseBody);", + " pm.test(\"Body matches string\", function () {", + " pm.expect(pm.response.text()).to.include(\"OTP Sent\");", + " });", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "noauth" + }, + "method": "POST", + "header": [ + { + "key": "User-Agent", + "value": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" + }, + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Accept", + "value": "*/*" + } + ], + "body": { + "mode": "raw", + "raw": "{\"email\":\"{{email}}\"}" + }, + "url": { + "raw": "{{url}}/identity/api/auth/forget-password", + "host": [ + "{{url}}" + ], + "path": [ + "identity", + "api", + "auth", + "forget-password" + ] + } + }, + "response": [] + }, + { + "name": "SearchMailOTP", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "", + "", + "function dynamicSort(property) {", + " var sortOrder = 1;", + " if(property[0] === \"-\") {", + " sortOrder = -1;", + " property = property.substr(1);", + " }", + " return function (a,b) {", + " /* next line works with strings and numbers, ", + " * and you may want to customize it to your needs", + " */", + " var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;", + " return result * sortOrder;", + " }", + "}", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + " var jsonData = JSON.parse(responseBody);", + " var mails = jsonData.items;", + "", + " pm.test(\"Your test name\", function () {", + " pm.expect(mails.length).to.be.gt(0);", + " var mail = mails[0];", + " console.log(mail);", + " //mails.sort(dynamicSort(\"Created\"));", + " var mail = mails[0];", + " var mbody = mail['Raw']['Data'].replace(/[^a-zA-Z0-9<>:]*\\n/g, \"\");", + " console.log(mail);", + " var otpmatch = mbody.match(/generated otp is: ([0-9]+)/);", + " console.log(otpmatch);", + " var otp = otpmatch[1]", + " console.log(\"OTP: \"+ otp);", + " pm.globals.set(\"OTP\", otp);", + " });", + " ", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "GET", + "header": [ + { + "key": "User-Agent", + "value": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" + }, + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Accept", + "value": "*/*" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "{{url_mail}}/api/v2/search?kind=to&query={{email}}&limit=10", + "host": [ + "{{url_mail}}" + ], + "path": [ + "api", + "v2", + "search" + ], + "query": [ + { + "key": "kind", + "value": "to" + }, + { + "key": "query", + "value": "{{email}}" + }, + { + "key": "limit", + "value": "10" + } + ] + } + }, + "response": [] + }, + { + "name": "Check OTP", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "noauth" + }, + "method": "POST", + "header": [ + { + "key": "User-Agent", + "value": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" + }, + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Accept", + "value": "*/*" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"email\": \"{{email}}\",\n \"otp\": \"{{OTP}}\",\n \"password\": \"{{password}}\"\n}" + }, + "url": { + "raw": "{{url}}/identity/api/auth/v3/check-otp", + "host": [ + "{{url}}" + ], + "path": [ + "identity", + "api", + "auth", + "v3", + "check-otp" + ] + } + }, + "response": [] + }, + { + "name": "Resend vehicle email", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "User-Agent", + "value": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" + }, + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Accept", + "value": "*/*" + } + ], + "url": { + "raw": "{{url}}/identity/api/v2/vehicle/resend_email", + "host": [ + "{{url}}" + ], + "path": [ + "identity", + "api", + "v2", + "vehicle", + "resend_email" + ] + } + }, + "response": [] + }, + { + "name": "SearchMailVehicle", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "", + "function dynamicSort(property) {", + " var sortOrder = 1;", + " if(property[0] === \"-\") {", + " sortOrder = -1;", + " property = property.substr(1);", + " }", + " return function (a,b) {", + " /* next line works with strings and numbers, ", + " * and you may want to customize it to your needs", + " */", + " var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;", + " return result * sortOrder;", + " }", + "}", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + " var jsonData = JSON.parse(responseBody);", + " var mails = jsonData.items;", + "", + " pm.test(\"Your test name\", function () {", + " pm.expect(mails.length).to.be.gt(0);", + " console.log(mails[0]);", + " //mails.sort(dynamicSort(\"Created\"));", + " console.log(mails[0]);", + " var mail = mails[0];", + " var mbody = mail['Raw']['Data'].replace(/[^a-zA-Z0-9<>:]*\\n/g, \"\");", + " var vintext = mbody.match(/VIN(.*)Pincode/i);", + " console.log(vintext);", + " var VIN = vintext[1].match(/>([A-Za-z0-9]+)([0-9]+) b[property]) ? 1 : 0;", + " return result * sortOrder;", + " }", + "}", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + " var jsonData = JSON.parse(responseBody);", + " var mails = jsonData.items;", + "", + " pm.test(\"Get Token\", function () {", + " pm.expect(mails.length).to.be.gt(0);", + " //mails.sort(dynamicSort(\"Created\"));", + " var mail = mails[0];", + " var mbody = mail['Raw']['Data'].replace(/[^a-zA-Z0-9<>:]*\\n/g, \"\");", + " console.log(mbody);", + " var tokentext = mbody.match(/token:\\s*[^\\s]+/i);", + " console.log(tokentext);", + " var email_token = tokentext[0].match(/>([A-Za-z0-9]+) b[property]) ? 1 : 0;", + " return result * sortOrder;", + " }", + "}", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + " var jsonData = JSON.parse(responseBody);", + " var mails = jsonData.items;", + "", + " pm.test(\"Get Token\", function () {", + " pm.expect(mails.length).to.be.gt(0);", + " //mails.sort(dynamicSort(\"Created\"));", + " var mail = mails[0];", + " var mbody = mail['Raw']['Data'].replace(/[^a-zA-Z0-9<>:]*\\n/g, \"\");", + " console.log(mbody);", + " var tokentext = mbody.match(/token:\\s*[^\\s]+/i);", + " console.log(tokentext);", + " var email_token = tokentext[0].match(/>([A-Za-z0-9]+)