{
	"info": {
		"_postman_id": "f9fd1d54-87f1-4e1d-b234-922228fd1ebd",
		"name": "juice-shop-run-multiple-test-cases",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
		"_exporter_id": "16137040",
		"_collection_link": "https://lively-spaceship-121921.postman.co/workspace/API-Testing-with-Test-Mentor~2f7087c2-3e72-4d37-9d46-c5791378642d/collection/16137040-f9fd1d54-87f1-4e1d-b234-922228fd1ebd?action=share&source=collection_link&creator=16137040"
	},
	"item": [
		{
			"name": "Register user",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							"// 1. Kiểm tra xem đã có lần chạy trước đó chưa\r",
							"let isFirstExecution = pm.environment.get(\"isFirstExecution\")\r",
							"if (!isFirstExecution) {\r",
							"      // 2. Nếu đây là lần chạy đầu tiên, gán isFirstExecution = true\r",
							"      isFirstExecution = true\r",
							"      // 3. Khai báo danh sách các bộ test data\r",
							"      let testData = [\r",
							"            {\r",
							"                  \"testCaseID\" : 1,\r",
							"                  \"testCaseName\" : \"Verify register user success\",\r",
							"                  \"email\" : \"apitesting111@testmentor.com\",\r",
							"                  \"password\" : \"123456\",\r",
							"                  \"httpStatusCode\" : 201\r",
							"            },\r",
							"            {\r",
							"                  \"testCaseID\" : 2,\r",
							"                  \"testCaseName\" : \"Verify register user fail\",\r",
							"                  \"email\" : \"apitesting111@testmentor.com\",\r",
							"                  \"password\" : \"123456\",\r",
							"                  \"httpStatusCode\" : 400\r",
							"            },\r",
							"            {\r",
							"                  \"testCaseID\" : 3,\r",
							"                  \"testCaseName\" : \"Verify register user fail\",\r",
							"                  \"email\" : null,\r",
							"                  \"password\" : \"123456\",\r",
							"                  \"httpStatusCode\" : 400\r",
							"            }\r",
							"      ]\r",
							"      // 4. Lưu các dữ liệu trên vào Environment\r",
							"      pm.environment.set(\"isFirstExecution\", isFirstExecution)\r",
							"      pm.environment.set(\"testData\", JSON.stringify(testData))\r",
							"}\r",
							"\r",
							"// 5. Lấy danh sách bộ dữ liệu kiểm thử từ Environment\r",
							"let testData = JSON.parse(pm.environment.get(\"testData\"))\r",
							"\r",
							"// 6. Trích xuất bộ test data đầu tiên từ danh sách trên\r",
							"let currentTestData = testData.shift()\r",
							"\r",
							"// 7. Lưu trữ bộ test data vừa trích xuất từ mảng testData vào Environment\r",
							"pm.environment.set(\"currentTestData\", JSON.stringify(currentTestData))\r",
							"pm.environment.set(\"currentEmail\", currentTestData.email)\r",
							"pm.environment.set(\"currentPassword\", currentTestData.password)\r",
							"\r",
							"// 8. Lưu trữ các bộ test data còn lại vào Environment sau khi đã lấy ra bộ kiểm thử đầu tiên\r",
							"pm.environment.set(\"testData\", JSON.stringify(testData))\r",
							""
						],
						"type": "text/javascript"
					}
				},
				{
					"listen": "test",
					"script": {
						"exec": [
							"// 9. Lấy danh sách bộ dữ liệu kiểm thử từ Environment",
							"let testData = JSON.parse(pm.environment.get(\"testData\"))",
							"",
							"// 10. Lấy bộ dữ liệu kiểm thử hiện tại từ Environment",
							"let currentTestData = JSON.parse(pm.environment.get(\"currentTestData\"))",
							"",
							"// 11. Trích xuất http status code ",
							"let resStatusCode = pm.response.code",
							"",
							"// 12. Viết bài kiểm tra Status Code",
							"pm.test(\"TC\" + currentTestData.testCaseID + \" : \" + currentTestData.testCaseName + \". Email = \" + currentTestData.email + \", Password = \" + currentTestData.password, function () {",
							"    pm.expect(resStatusCode).to.eql(currentTestData.httpStatusCode);",
							"});",
							"",
							"// 13. Kiểm tra nếu còn bộ dữ liệu kiểm thử chưa được thực thi, đặt request tiếp theo là \"Register user\"",
							"if(testData.length > 0) {",
							"      postman.setNextRequest(\"Register user\")",
							"} else {",
							"      // 14. Nếu đã kiểm thử toàn bộ test data, dừng send request",
							"      postman.setNextRequest(null)",
							"",
							"      // 15. Sau khi hoàn tất kiểm thử, tiến hành xóa các dữ liệu k môi trường không phải là biến common",
							"      let commonVariables = [\"base-url\"]",
							"      let environmentVariables = pm.environment.toObject()",
							"      for (let variable in environmentVariables) {",
							"            if (!commonVariables.includes(variable)) {",
							"                  pm.environment.unset(variable);",
							"            }",
							"      }",
							"}"
						],
						"type": "text/javascript"
					}
				}
			],
			"protocolProfileBehavior": {
				"disabledSystemHeaders": {}
			},
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"value": "application/json",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\r\n    \"email\": \"{{currentEmail}}\",\r\n    \"password\": \"{{currentPasswordl}}\",\r\n    \"passwordRepeat\": \"{{currentPassword}}\",\r\n    \"securityQuestion\": {\r\n        \"id\": 1,\r\n        \"question\": \"Your eldest siblings middle name?\",\r\n        \"createdAt\": \"2023-05-22T09:18:31.907Z\",\r\n        \"updatedAt\": \"2023-05-22T09:18:31.907Z\"\r\n    },\r\n    \"securityAnswer\": \"abc\"\r\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{base-url}}/api/Users/",
					"host": [
						"{{base-url}}"
					],
					"path": [
						"api",
						"Users",
						""
					]
				}
			},
			"response": []
		}
	]
}