Last active
March 12, 2025 05:05
-
-
Save piharpi/c1b0b4d2f651624494548ddf880e7a99 to your computer and use it in GitHub Desktop.
testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"info": { | |
"_postman_id": "2bd6819b-7315-4be0-99ce-1b8a42f80427", | |
"name": "Forum API Copy", | |
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", | |
"_exporter_id": "26241780" | |
}, | |
"item": [ | |
{ | |
"name": "Users", | |
"item": [ | |
{ | |
"name": "Add User with Valid Payload", | |
"event": [ | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('should response 201 status code', () => {\r", | |
" pm.response.to.have.status(201);\r", | |
"});\r", | |
"\r", | |
"pm.test('should response with correct property and message', () => {\r", | |
" const responseJson = pm.response.json();\r", | |
" pm.expect(responseJson).to.be.an('object');\r", | |
" pm.expect(responseJson.status).to.equal('success');\r", | |
" pm.expect(responseJson.data).to.be.an('object');\r", | |
" pm.expect(responseJson.data.addedUser).to.be.an('object');\r", | |
" pm.expect(responseJson.data.addedUser.id).to.be.a('string');\r", | |
" pm.expect(responseJson.data.addedUser.username).to.be.a('string');\r", | |
" pm.expect(responseJson.data.addedUser.fullname).to.be.a('string');\r", | |
"});\r", | |
"" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "POST", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\r\n \"username\": \"{{newUsername}}_{{$timestamp}}\",\r\n \"password\": \"{{newPassword}}\",\r\n \"fullname\": \"{{newFullname}}\"\r\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/users", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"users" | |
] | |
} | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "Add User with Bad Payload", | |
"event": [ | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('response status code should have 400 value', () => {\r", | |
" pm.response.to.have.status(400);\r", | |
"}); \r", | |
"\r", | |
"pm.test('response body should have correct property and value', () => {\r", | |
" const responseJson = pm.response.json();\r", | |
" pm.expect(responseJson).to.be.an('object');\r", | |
" pm.expect(responseJson.status).to.equals('fail');\r", | |
" pm.expect(responseJson.message).to.be.a('string');\r", | |
" pm.expect(responseJson.message).to.not.equals('');\r", | |
" pm.expect(responseJson.message).to.not.equals(null);\r", | |
"});\r", | |
"\r", | |
"const repeatRequestUntilDatasetEmpty = () => {\r", | |
" const badAuthenticationPayloads = pm.environment.get('badAuthenticationPayloads');\r", | |
" \r", | |
" if(badAuthenticationPayloads && badAuthenticationPayloads.length > 0) {\r", | |
" pm.execution.setNextRequest('Add User with Bad Payload');\r", | |
" }\r", | |
"}\r", | |
" \r", | |
"repeatRequestUntilDatasetEmpty();" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
}, | |
{ | |
"listen": "prerequest", | |
"script": { | |
"exec": [ | |
"let badAuthenticationPayloads = pm.environment.get('badAuthenticationPayloads');\r", | |
"\r", | |
"if (!badAuthenticationPayloads || badAuthenticationPayloads.length === 0) {\r", | |
" badAuthenticationPayloads = [\r", | |
" {},\r", | |
" { password: 'secret', fullname: 'Mahendrata Harpi' },\r", | |
" { username: 123, password: 'secret', fullname: 'Mahendrata Harpi' },\r", | |
" { username: 'harpi', fullname: 'Mahendrata Harpi' },\r", | |
" { username: 'harpi', password: true, fullname: 'Mahendrata Harpi' },\r", | |
" { username: 'harpi', password: 'secret' },\r", | |
" { username: 'harpi', password: 'secret', fullname: [] },\r", | |
" ];\r", | |
"}\r", | |
"\r", | |
"const currentBadAuthenticationPayload = badAuthenticationPayloads.shift();\r", | |
"pm.environment.set('currentBadAuthenticationPayload', JSON.stringify(currentBadAuthenticationPayload));\r", | |
"pm.environment.set('badAuthenticationPayloads', badAuthenticationPayloads);" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "POST", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{{currentBadAuthenticationPayload}}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/users", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"users" | |
] | |
} | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "Add User with Exist Username", | |
"event": [ | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('should response 400 status code', () => {\r", | |
" pm.response.to.have.status(400);\r", | |
"});\r", | |
"\r", | |
"pm.test('should response with correct property and message', () => {\r", | |
" const responseJson = pm.response.json();\r", | |
" pm.expect(responseJson).to.be.an('object');\r", | |
" pm.expect(responseJson.status).to.equal('fail');\r", | |
" pm.expect(responseJson.message).to.equal('username tidak tersedia');\r", | |
"});\r", | |
"" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
}, | |
{ | |
"listen": "prerequest", | |
"script": { | |
"exec": [ | |
"const domain = pm.environment.get('domain');\r", | |
"\r", | |
"const postRequest = {\r", | |
" url: `${domain}/users`,\r", | |
" method: 'POST',\r", | |
" header: {\r", | |
" 'Content-Type': 'application/json',\r", | |
" },\r", | |
" body: {\r", | |
" mode: 'raw',\r", | |
" raw: JSON.stringify({\r", | |
" username: pm.environment.get('newUsername'),\r", | |
" password: pm.environment.get('newPassword'),\r", | |
" fullname: pm.environment.get('newFullname')\r", | |
" }),\r", | |
" },\r", | |
"};\r", | |
"\r", | |
"pm.sendRequest(postRequest, (error, response) => {\r", | |
" console.log(error ? error : response.json());\r", | |
"});" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "POST", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\r\n \"username\": \"{{newUsername}}\",\r\n \"password\": \"{{newPassword}}\",\r\n \"fullname\": \"{{newFullname}}\"\r\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/users", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"users" | |
] | |
} | |
}, | |
"response": [] | |
} | |
] | |
}, | |
{ | |
"name": "Authentications", | |
"item": [ | |
{ | |
"name": "[No Test] Prerequiresite", | |
"item": [ | |
{ | |
"name": "Add User", | |
"event": [ | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "POST", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\r\n \"username\": \"{{newUsername}}\",\r\n \"password\": \"{{newPassword}}\",\r\n \"fullname\": \"{{newFullname}}\"\r\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/users", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"users" | |
] | |
} | |
}, | |
"response": [] | |
} | |
] | |
}, | |
{ | |
"name": "Login with Invalid Password", | |
"event": [ | |
{ | |
"listen": "prerequest", | |
"script": { | |
"exec": [ | |
"const domain = pm.environment.get('domain');\r", | |
"\r", | |
"const postRequest = {\r", | |
" url: `${domain}/users`,\r", | |
" method: 'POST',\r", | |
" header: {\r", | |
" 'Content-Type': 'application/json',\r", | |
" },\r", | |
" body: {\r", | |
" mode: 'raw',\r", | |
" raw: JSON.stringify({\r", | |
" username: pm.environment.get('newUsername'),\r", | |
" password: pm.environment.get('newPassword'),\r", | |
" fullname: pm.environment.get('newFullname')\r", | |
" }),\r", | |
" },\r", | |
"};\r", | |
"\r", | |
"pm.sendRequest(postRequest, (error, response) => {\r", | |
" console.log(error ? error : response.json());\r", | |
"});" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
}, | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('should response 401 status code', () => {\r", | |
" pm.response.to.have.status(401);\r", | |
"});\r", | |
"\r", | |
"pm.test('should respose with correct property and message', () => {\r", | |
" const responseJson = pm.response.json();\r", | |
"\r", | |
" pm.expect(responseJson).to.be.an('object');\r", | |
" pm.expect(responseJson.status).to.equal('fail');\r", | |
" pm.expect(responseJson.message).to.be.an('string');\r", | |
"});" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "POST", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\r\n \"username\": \"{{newUsername}}\",\r\n \"password\": \"xxx\"\r\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/authentications", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"authentications" | |
] | |
} | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "Login with Invalid Username", | |
"event": [ | |
{ | |
"listen": "prerequest", | |
"script": { | |
"exec": [ | |
"const domain = pm.environment.get('domain');\r", | |
"\r", | |
"const postRequest = {\r", | |
" url: `${domain}/users`,\r", | |
" method: 'POST',\r", | |
" header: {\r", | |
" 'Content-Type': 'application/json',\r", | |
" },\r", | |
" body: {\r", | |
" mode: 'raw',\r", | |
" raw: JSON.stringify({\r", | |
" username: pm.environment.get('newUsername'),\r", | |
" password: pm.environment.get('newPassword'),\r", | |
" fullname: pm.environment.get('newFullname')\r", | |
" }),\r", | |
" },\r", | |
"};\r", | |
"\r", | |
"pm.sendRequest(postRequest, (error, response) => {\r", | |
" console.log(error ? error : response.json());\r", | |
"});" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
}, | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('should response 400 status code', () => {\r", | |
" pm.response.to.have.status(400);\r", | |
"});\r", | |
"\r", | |
"pm.test('should respose with correct property and message', () => {\r", | |
" const responseJson = pm.response.json();\r", | |
"\r", | |
" pm.expect(responseJson).to.be.an('object');\r", | |
" pm.expect(responseJson.status).to.equal('fail');\r", | |
" pm.expect(responseJson.message).to.be.an('string');\r", | |
"});" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "POST", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\r\n \"username\": \"xxxx\",\r\n \"password\": \"{{newPassword}}\"\r\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/authentications", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"authentications" | |
] | |
} | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "Login with Valid Credential", | |
"event": [ | |
{ | |
"listen": "prerequest", | |
"script": { | |
"exec": [ | |
"const domain = pm.environment.get('domain');\r", | |
"\r", | |
"const postRequest = {\r", | |
" url: `${domain}/users`,\r", | |
" method: 'POST',\r", | |
" header: {\r", | |
" 'Content-Type': 'application/json',\r", | |
" },\r", | |
" body: {\r", | |
" mode: 'raw',\r", | |
" raw: JSON.stringify({\r", | |
" username: pm.environment.get('newUsername'),\r", | |
" password: pm.environment.get('newPassword'),\r", | |
" fullname: pm.environment.get('newFullname')\r", | |
" }),\r", | |
" },\r", | |
"};\r", | |
"\r", | |
"pm.sendRequest(postRequest, (error, response) => {\r", | |
" console.log(error ? error : response.json());\r", | |
"});" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
}, | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('should response 201 status code', () => {\r", | |
" pm.response.to.have.status(201);\r", | |
"});\r", | |
"\r", | |
"pm.test('should respose with correct property and message', () => {\r", | |
" const responseJson = pm.response.json();\r", | |
"\r", | |
" pm.expect(responseJson).to.be.an('object');\r", | |
" pm.expect(responseJson.status).to.equal('success');\r", | |
" pm.expect(responseJson.data).to.be.an('object');\r", | |
" pm.expect(responseJson.data.accessToken).to.be.a('string');\r", | |
" pm.expect(responseJson.data.refreshToken).to.be.a('string');\r", | |
"\r", | |
" pm.environment.set('accessToken', responseJson.data.accessToken);\r", | |
" pm.environment.set('refreshToken', responseJson.data.refreshToken);\r", | |
"});" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "POST", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\r\n \"username\": \"{{newUsername}}\",\r\n \"password\": \"{{newPassword}}\"\r\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/authentications", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"authentications" | |
] | |
} | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "Refresh Access Token with Valid Refresh Token", | |
"event": [ | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('should response 200 status code', () => {\r", | |
" pm.response.to.have.status(200);\r", | |
"});\r", | |
"\r", | |
"pm.test('should response with corrent message and property', () => {\r", | |
" const responseJson = pm.response.json();\r", | |
"\r", | |
" pm.expect(responseJson).to.be.an('object');\r", | |
" pm.expect(responseJson.status).to.equal('success');\r", | |
" pm.expect(responseJson.data).to.be.an('object');\r", | |
" pm.expect(responseJson.data.accessToken).to.be.a('string');\r", | |
" pm.expect(responseJson.data.accessToken).to.not.equals('');\r", | |
"});" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "PUT", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\r\n \"refreshToken\": \"{{refreshToken}}\"\r\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/authentications", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"authentications" | |
] | |
} | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "Refresh Access Token with invalid Refresh Token", | |
"event": [ | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('should response 400 status code', () => {\r", | |
" pm.response.to.have.status(400);\r", | |
"});\r", | |
"\r", | |
"pm.test('should response with corrent message and property', () => {\r", | |
" const responseJson = pm.response.json();\r", | |
"\r", | |
" pm.expect(responseJson).to.be.an('object');\r", | |
" pm.expect(responseJson.status).to.equal('fail');\r", | |
" pm.expect(responseJson.message).to.equal('refresh token tidak valid');\r", | |
"});" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "PUT", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\r\n \"refreshToken\": \"xxx\"\r\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/authentications", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"authentications" | |
] | |
} | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "Logout with Valid Refresh Token", | |
"event": [ | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('should response with 200 status code', () => {\r", | |
" pm.response.to.have.status(200);\r", | |
"});\r", | |
"\r", | |
"pm.test('response should contain status with success value', () => {\r", | |
" const responseJson = pm.response.json();\r", | |
"\r", | |
" pm.expect(responseJson).to.be.an('object');\r", | |
" pm.expect(responseJson.status).to.equal('success');\r", | |
"});\r", | |
"\r", | |
"pm.test('when refreshing access token with the deleted refresh token', () => {\r", | |
" const domain = pm.environment.get('domain');\r", | |
" const refreshToken = pm.environment.get('refreshToken');\r", | |
"\r", | |
" const putRequest = {\r", | |
" url: `${domain}/authentications`,\r", | |
" method: 'PUT',\r", | |
" header: {\r", | |
" 'Content-Type': 'application/json',\r", | |
" },\r", | |
" body: {\r", | |
" mode: 'raw',\r", | |
" raw: JSON.stringify({ refreshToken }),\r", | |
" },\r", | |
" };\r", | |
"\r", | |
" pm.sendRequest(putRequest, (error, response) => {\r", | |
" if (!error) {\r", | |
" pm.test('the response code should be 400', () => {\r", | |
" pm.expect(response.code).to.equals(400);\r", | |
" });\r", | |
" }\r", | |
" });\r", | |
"})" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "DELETE", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\r\n \"refreshToken\": \"{{refreshToken}}\"\r\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/authentications", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"authentications" | |
] | |
} | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "Logout with Invalid Refresh Token", | |
"event": [ | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('should response with 400 status code', () => {\r", | |
" pm.response.to.have.status(400);\r", | |
"});\r", | |
"\r", | |
"pm.test('response should contain correct status and message', () => {\r", | |
" const responseJson = pm.response.json();\r", | |
" \r", | |
" pm.expect(responseJson).to.be.an('object');\r", | |
" pm.expect(responseJson.status).to.equal('fail');\r", | |
" pm.expect(responseJson.message).to.equal('refresh token tidak ditemukan di database');\r", | |
"})\r", | |
"" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "DELETE", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\r\n \"refreshToken\": \"xxx\"\r\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/authentications", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"authentications" | |
] | |
} | |
}, | |
"response": [] | |
} | |
] | |
}, | |
{ | |
"name": "Threads", | |
"item": [ | |
{ | |
"name": "[No Test] Prerequiresite", | |
"item": [ | |
{ | |
"name": "[No Test] Add User", | |
"event": [ | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "POST", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\r\n \"username\": \"{{newUsername}}\",\r\n \"password\": \"{{newPassword}}\",\r\n \"fullname\": \"{{newFullname}}\"\r\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/users", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"users" | |
] | |
} | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "[No Test] Login", | |
"event": [ | |
{ | |
"listen": "prerequest", | |
"script": { | |
"exec": [ | |
"const domain = pm.environment.get('domain');\r", | |
"\r", | |
"const postRequest = {\r", | |
" url: `${domain}/users`,\r", | |
" method: 'POST',\r", | |
" header: {\r", | |
" 'Content-Type': 'application/json',\r", | |
" },\r", | |
" body: {\r", | |
" mode: 'raw',\r", | |
" raw: JSON.stringify({\r", | |
" username: pm.environment.get('newUsername'),\r", | |
" password: pm.environment.get('newPassword'),\r", | |
" fullname: pm.environment.get('newFullname')\r", | |
" }),\r", | |
" },\r", | |
"};\r", | |
"\r", | |
"pm.sendRequest(postRequest, (error, response) => {\r", | |
" console.log(error ? error : response.json());\r", | |
"});" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
}, | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"const responseJson = pm.response.json();\r", | |
"\r", | |
"pm.environment.set('accessToken', responseJson.data.accessToken);\r", | |
"pm.environment.set('refreshToken', responseJson.data.refreshToken);" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "POST", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\r\n \"username\": \"{{newUsername}}\",\r\n \"password\": \"{{newPassword}}\"\r\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/authentications", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"authentications" | |
] | |
} | |
}, | |
"response": [] | |
} | |
] | |
}, | |
{ | |
"name": "Add Thread with No Authentication", | |
"event": [ | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('should response 401 status code', () => {\r", | |
" pm.response.to.have.status(401);\r", | |
"});\r", | |
"\r", | |
"pm.test('should show Missing Authentication message', () => {\r", | |
" const responseJson = pm.response.json();\r", | |
"\r", | |
" pm.expect(responseJson).to.be.an('object');\r", | |
" pm.expect(responseJson.message).to.equal('Missing authentication');\r", | |
"});" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"method": "POST", | |
"header": [], | |
"url": { | |
"raw": "{{domain}}/threads", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"threads" | |
] | |
} | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "Add Thread with Bad Payload", | |
"event": [ | |
{ | |
"listen": "prerequest", | |
"script": { | |
"exec": [ | |
"let badThreadPayloads = pm.environment.get('badThreadPayloads');\r", | |
"\r", | |
"if (!badThreadPayloads || badThreadPayloads.length === 0) {\r", | |
" badThreadPayloads = [\r", | |
" {},\r", | |
" { body: 'A Body' },\r", | |
" { title: 123, body: 'A Body' },\r", | |
" { title: 'A Thread' },\r", | |
" { title: 'A Thread', body: true },\r", | |
" ];\r", | |
"}\r", | |
"\r", | |
"const currentBadThreadPayload = badThreadPayloads.shift();\r", | |
"pm.environment.set('currentBadThreadPayload', JSON.stringify(currentBadThreadPayload));\r", | |
"pm.environment.set('badThreadPayloads', badThreadPayloads);" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
}, | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('should response 400 status code', () => {\r", | |
" pm.response.to.have.status(400);\r", | |
"});\r", | |
"\r", | |
"pm.test('should show fail status and message', () => {\r", | |
" const responseJson = pm.response.json();\r", | |
"\r", | |
" pm.expect(responseJson).to.be.an('object');\r", | |
" pm.expect(responseJson.status).to.equal('fail');\r", | |
" pm.expect(responseJson.message).to.be.a('string');\r", | |
" pm.expect(responseJson.message).to.not.equal('');\r", | |
"});\r", | |
"\r", | |
"const repeatRequestUntilDatasetEmpty = () => {\r", | |
" const badThreadPayloads = pm.environment.get('badThreadPayloads');\r", | |
" \r", | |
" if(badThreadPayloads && badThreadPayloads.length > 0) {\r", | |
" pm.execution.setNextRequest('Add Thread with Bad Payload');\r", | |
" }\r", | |
"}\r", | |
" \r", | |
"repeatRequestUntilDatasetEmpty();" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"auth": { | |
"type": "bearer", | |
"bearer": [ | |
{ | |
"key": "token", | |
"value": "{{accessToken}}", | |
"type": "string" | |
} | |
] | |
}, | |
"method": "POST", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{{currentBadThreadPayload}}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/threads", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"threads" | |
] | |
} | |
}, | |
"response": [] | |
}, | |
{ | |
"name": "Add Thread with Valid Payload", | |
"event": [ | |
{ | |
"listen": "test", | |
"script": { | |
"exec": [ | |
"pm.test('should response 201 status code', () => {\r", | |
" pm.response.to.have.status(201);\r", | |
"});\r", | |
"\r", | |
"pm.test('should response with valid property and value', () => {\r", | |
" const responseJson = pm.response.json();\r", | |
"\r", | |
" pm.expect(responseJson).to.be.an('object');\r", | |
" pm.expect(responseJson.status).to.equal('success');\r", | |
" pm.expect(responseJson.data).to.be.an('object');\r", | |
" pm.expect(responseJson.data.addedThread).to.be.an('object');\r", | |
" pm.expect(responseJson.data.addedThread.id).to.be.a('string');\r", | |
" pm.expect(responseJson.data.addedThread.id).to.not.equal('');\r", | |
" pm.expect(responseJson.data.addedThread.title).to.be.a('string');\r", | |
" pm.expect(responseJson.data.addedThread.title).to.not.equal('');\r", | |
" pm.expect(responseJson.data.addedThread.owner).to.be.a('string');\r", | |
" pm.expect(responseJson.data.addedThread.owner).to.not.equal('');\r", | |
"});" | |
], | |
"type": "text/javascript", | |
"packages": {} | |
} | |
} | |
], | |
"request": { | |
"auth": { | |
"type": "bearer", | |
"bearer": [ | |
{ | |
"key": "token", | |
"value": "{{accessToken}}", | |
"type": "string" | |
} | |
] | |
}, | |
"method": "POST", | |
"header": [], | |
"body": { | |
"mode": "raw", | |
"raw": "{\r\n \"title\": \"{{newThreadTitle}}\",\r\n \"body\": \"{{newThreadBody}}\"\r\n}", | |
"options": { | |
"raw": { | |
"language": "json" | |
} | |
} | |
}, | |
"url": { | |
"raw": "{{domain}}/threads", | |
"host": [ | |
"{{domain}}" | |
], | |
"path": [ | |
"threads" | |
] | |
} | |
}, | |
"response": [] | |
} | |
] | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": "005cbbbd-cd30-458c-9599-527414cc7853", | |
"name": "Forum API Env", | |
"values": [ | |
{ | |
"key": "host", | |
"value": "0.0.0.0", | |
"enabled": true | |
}, | |
{ | |
"key": "port", | |
"value": "5000", | |
"enabled": true | |
}, | |
{ | |
"key": "protocol", | |
"value": "http", | |
"enabled": true | |
}, | |
{ | |
"key": "newUsername", | |
"value": "harpi", | |
"enabled": true | |
}, | |
{ | |
"key": "newPassword", | |
"value": "secret", | |
"enabled": true | |
}, | |
{ | |
"key": "newFullname", | |
"value": "Mahendrata Harpi", | |
"enabled": true | |
}, | |
{ | |
"key": "accessToken", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "refreshToken", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "badAuthenticationPayloads", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "currentBadAuthenticationPayload", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "badThreadPayloads", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "currentBadThreadPayload", | |
"value": "{\"title\":\"A Thread\",\"body\":true}", | |
"enabled": true | |
}, | |
{ | |
"key": "newThreadTitle", | |
"value": "sebuah thread", | |
"enabled": true | |
}, | |
{ | |
"key": "newThreadBody", | |
"value": "sebuah body thread", | |
"enabled": true | |
}, | |
{ | |
"key": "newUsername2", | |
"value": "johndoe", | |
"enabled": true | |
}, | |
{ | |
"key": "newPassword2", | |
"value": "secret", | |
"enabled": true | |
}, | |
{ | |
"key": "newFullname2", | |
"value": "John Doe", | |
"enabled": true | |
}, | |
{ | |
"key": "accessToken2", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "refreshToken2", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "threadId", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "newCommentContent", | |
"value": "sebuah comment", | |
"enabled": true | |
}, | |
{ | |
"key": "badAddCommentPayloads", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "currentBadAddCommentPayload", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "commentId", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "newReplyContent", | |
"value": "sebuah balasan", | |
"enabled": true | |
}, | |
{ | |
"key": "badAddReplyPayloads", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "currentBadAddReplyPayload", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "replyId", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "commentId2", | |
"value": "", | |
"enabled": true | |
}, | |
{ | |
"key": "domain", | |
"value": "https://2f1f-182-253-58-81.ngrok-free.app", | |
"type": "default", | |
"enabled": true | |
} | |
], | |
"_postman_variable_scope": "environment", | |
"_postman_exported_at": "2025-03-12T04:41:40.788Z", | |
"_postman_exported_using": "Postman/11.13.3" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment