diff --git a/backend/petshop-api.postman_collection.json b/backend/petshop-api.postman_collection.json index 4ba7b5c6..37b5245f 100644 --- a/backend/petshop-api.postman_collection.json +++ b/backend/petshop-api.postman_collection.json @@ -1053,8 +1053,11 @@ "script": { "type": "text/javascript", "exec": [ - "pm.test('Status code is 403', function () {", - " pm.response.to.have.status(403);", + "pm.test('Status code is 200', function () {", + " pm.response.to.have.status(200);", + "});", + "pm.test('Pet image response is an image', function () {", + " pm.expect(pm.response.headers.get('Content-Type')).to.include('image/');", "});" ] } @@ -1112,7 +1115,15 @@ "exec": [ "pm.test('Status code is 200', function () {", " pm.response.to.have.status(200);", - "});" + "});", + "var jsonData = pm.response.json();", + "var items = jsonData.items || [];", + "var productId = Number(pm.collectionVariables.get('productId'));", + "var cartItem = items.find(function (item) { return item.prodId === productId; }) || items[0];", + "pm.test('cart item is returned', function () {", + " pm.expect(cartItem).to.exist;", + "});", + "if (cartItem && cartItem.cartItemId !== undefined) pm.collectionVariables.set('cartItemId', cartItem.cartItemId);" ] } } @@ -1816,7 +1827,15 @@ "exec": [ "pm.test('Status code is 200', function () {", " pm.response.to.have.status(200);", - "});" + "});", + "var jsonData = pm.response.json();", + "var items = jsonData.items || [];", + "var productId = Number(pm.collectionVariables.get('productId'));", + "var cartItem = items.find(function (item) { return item.prodId === productId; }) || items[0];", + "pm.test('cart item is returned', function () {", + " pm.expect(cartItem).to.exist;", + "});", + "if (cartItem && cartItem.cartItemId !== undefined) pm.collectionVariables.set('cartItemId', cartItem.cartItemId);" ] } } @@ -1924,6 +1943,54 @@ } ] }, + { + "name": "Add Cart Item For Checkout", + "request": { + "method": "POST", + "url": "{{baseUrl}}/api/v1/cart/add", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Authorization", + "value": "Bearer {{customerToken}}", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"prodId\": {{productId}},\n \"storeId\": {{storeId}},\n \"quantity\": 2\n}", + "options": { + "raw": { + "language": "json" + } + } + } + }, + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "pm.test('Status code is 200', function () {", + " pm.response.to.have.status(200);", + "});", + "var jsonData = pm.response.json();", + "var items = jsonData.items || [];", + "var productId = Number(pm.collectionVariables.get('productId'));", + "var cartItem = items.find(function (item) { return item.prodId === productId; }) || items[0];", + "pm.test('cart item is returned', function () {", + " pm.expect(cartItem).to.exist;", + "});", + "if (cartItem && cartItem.cartItemId !== undefined) pm.collectionVariables.set('cartItemId', cartItem.cartItemId);" + ] + } + } + ] + }, { "name": "Apply Coupon", "request": { @@ -1942,7 +2009,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"couponCode\": \"SAVE10\"\n}", + "raw": "{\n \"couponCode\": \"TREAT5\"\n}", "options": { "raw": { "language": "json" @@ -1958,6 +2025,10 @@ "exec": [ "pm.test('Status code is 200', function () {", " pm.response.to.have.status(200);", + "});", + "var jsonData = pm.response.json();", + "pm.test('coupon was applied', function () {", + " pm.expect(jsonData.couponCode).to.equal('TREAT5');", "});" ] } @@ -1996,9 +2067,19 @@ "script": { "type": "text/javascript", "exec": [ - "pm.test('Status code is 200', function () {", - " pm.response.to.have.status(200);", - "});" + "pm.test('Status code is 200 or 400', function () {", + " pm.expect([200, 400]).to.include(pm.response.code);", + "});", + "var jsonData = pm.response.json();", + "if (pm.response.code === 200) {", + " pm.expect(jsonData.clientSecret).to.be.a('string');", + " pm.expect(jsonData.totalAmount).to.exist;", + " var paymentIntentId = jsonData.clientSecret.split('_secret_')[0];", + " if (paymentIntentId) pm.collectionVariables.set('paymentIntentId', paymentIntentId);", + "} else {", + " pm.expect(jsonData.message).to.include('No API key provided');", + " pm.collectionVariables.set('paymentIntentId', '');", + "}" ] } } @@ -2027,9 +2108,13 @@ "script": { "type": "text/javascript", "exec": [ - "pm.test('Status code is 204', function () {", - " pm.response.to.have.status(204);", - "});" + "pm.test('Status code is 204 or 400', function () {", + " pm.expect([204, 400]).to.include(pm.response.code);", + "});", + "if (pm.response.code === 400) {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.message).to.include('Payment verification failed');", + "}" ] } } @@ -2065,7 +2150,14 @@ "exec": [ "pm.test('Status code is 200', function () {", " pm.response.to.have.status(200);", - "});" + "});", + "var jsonData = pm.response.json();", + "var coupons = jsonData.content || [];", + "pm.test('coupon list is not empty', function () {", + " pm.expect(coupons.length).to.be.above(0);", + "});", + "if (coupons[0] && coupons[0].couponId !== undefined) pm.collectionVariables.set('couponId', coupons[0].couponId);", + "if (coupons[0] && coupons[0].couponCode !== undefined) pm.collectionVariables.set('couponCode', coupons[0].couponCode);" ] } } @@ -2106,7 +2198,7 @@ "name": "Get Coupon by Code", "request": { "method": "GET", - "url": "{{baseUrl}}/api/v1/coupons/code/SAVE10", + "url": "{{baseUrl}}/api/v1/coupons/code/{{couponCode}}", "header": [ { "key": "Content-Type", @@ -2151,7 +2243,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"couponCode\": \"SAVE10\",\n \"discountType\": \"PERCENTAGE\",\n \"discountValue\": 10,\n \"minOrderAmount\": 50,\n \"active\": true,\n \"startsAt\": \"2026-01-01T00:00:00\",\n \"endsAt\": \"2026-12-31T23:59:59\",\n \"usageLimit\": 100\n}", + "raw": "{\n \"couponCode\": \"POSTMAN-{{$timestamp}}\",\n \"discountType\": \"PERCENTAGE\",\n \"discountValue\": 10,\n \"minOrderAmount\": 50,\n \"active\": true,\n \"startsAt\": \"2026-01-01T00:00:00\",\n \"endsAt\": \"2026-12-31T23:59:59\",\n \"usageLimit\": 100\n}", "options": { "raw": { "language": "json" @@ -2169,7 +2261,8 @@ " pm.response.to.have.status(201);", "});", "var jsonData = pm.response.json();", - "if (jsonData.couponId !== undefined) pm.collectionVariables.set('couponId', jsonData.couponId);" + "if (jsonData.couponId !== undefined) pm.collectionVariables.set('couponId', jsonData.couponId);", + "if (jsonData.couponCode !== undefined) pm.collectionVariables.set('couponCode', jsonData.couponCode);" ] } } @@ -2193,7 +2286,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"couponCode\": \"SAVE10\",\n \"discountType\": \"PERCENTAGE\",\n \"discountValue\": 15,\n \"minOrderAmount\": 50,\n \"active\": true,\n \"startsAt\": \"2026-01-01T00:00:00\",\n \"endsAt\": \"2026-12-31T23:59:59\",\n \"usageLimit\": 100\n}", + "raw": "{\n \"couponCode\": \"POSTMAN-UPD-{{$timestamp}}\",\n \"discountType\": \"PERCENTAGE\",\n \"discountValue\": 15,\n \"minOrderAmount\": 50,\n \"active\": true,\n \"startsAt\": \"2026-01-01T00:00:00\",\n \"endsAt\": \"2026-12-31T23:59:59\",\n \"usageLimit\": 100\n}", "options": { "raw": { "language": "json" @@ -3331,7 +3424,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"petId\": {{adoptionPetId}},\n \"customerId\": 1,\n \"adoptionDate\": \"2026-12-21\",\n \"adoptionStatus\": \"Pending\",\n \"sourceStoreId\": 1\n}", + "raw": "{\n \"petId\": {{adoptionPetId}},\n \"customerId\": 1,\n \"adoptionDate\": \"2026-03-21\",\n \"adoptionStatus\": \"Pending\",\n \"sourceStoreId\": 1\n}", "options": { "raw": { "language": "json" @@ -3373,7 +3466,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"petId\": {{adoptionPetId}},\n \"customerId\": 1,\n \"adoptionDate\": \"2026-12-22\",\n \"adoptionStatus\": \"Completed\",\n \"sourceStoreId\": 1\n}", + "raw": "{\n \"petId\": {{adoptionPetId}},\n \"customerId\": 1,\n \"adoptionDate\": \"2026-03-22\",\n \"adoptionStatus\": \"Completed\",\n \"sourceStoreId\": 1\n}", "options": { "raw": { "language": "json" @@ -4002,7 +4095,10 @@ " pm.response.to.have.status(201);", "});", "var jsonData = pm.response.json();", - "if (jsonData.id !== undefined) pm.collectionVariables.set('messageId', jsonData.id);" + "if (jsonData.id !== undefined) pm.collectionVariables.set('messageId', jsonData.id);", + "pm.test('message includes attachment url', function () {", + " pm.expect(jsonData.attachmentUrl).to.be.a('string');", + "});" ] } } @@ -4033,6 +4129,9 @@ "exec": [ "pm.test('Status code is 200', function () {", " pm.response.to.have.status(200);", + "});", + "pm.test('Attachment response has content type', function () {", + " pm.expect(pm.response.headers.get('Content-Type')).to.be.a('string');", "});" ] } @@ -5811,7 +5910,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"prodId\": 1,\n \"quantity\": 10,\n \"storeId\": 1\n}", + "raw": "{\n \"prodId\": {{productId}},\n \"quantity\": 10,\n \"storeId\": 1\n}", "options": { "raw": { "language": "json" @@ -5884,7 +5983,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"prodId\": 1,\n \"quantity\": 12,\n \"storeId\": 1\n}", + "raw": "{\n \"prodId\": {{productId}},\n \"quantity\": 12,\n \"storeId\": 1\n}", "options": { "raw": { "language": "json" @@ -5955,7 +6054,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"prodId\": 1,\n \"quantity\": 10,\n \"storeId\": 1\n}", + "raw": "{\n \"prodId\": {{productId}},\n \"quantity\": 10,\n \"storeId\": 1\n}", "options": { "raw": { "language": "json"