{ "info": { "_postman_id": "5d1ba4ae-d097-4a2b-a251-801c44b01f7a", "name": "Restful Booker BVT", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "item": [ { "name": "Get Bookings", "item": [ { "name": "Get All Bookings", "event": [ { "listen": "test", "script": { "id": "c34de8f7-c523-471a-b74b-b065d0aa980e", "exec": [ "", "var jsonData = pm.response.json();", "", "//we created at least one booking at the folder level, so there should always be bookings", "pm.test(\"Response is not empty\", function () {", " // See Chaijs docs for complete list of available assertions", " // https://www.chaijs.com/api/bdd", " pm.expect(jsonData).to.not.have.lengthOf(0);", "});", "" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "{{rb_url}}/booking", "host": [ "{{rb_url}}" ], "path": [ "booking" ] } }, "response": [] }, { "name": "Search By First Name", "event": [ { "listen": "prerequest", "script": { "id": "f90c42c7-9bf8-42c4-942d-e4ae5cbabef1", "exec": [ "" ], "type": "text/javascript" } }, { "listen": "test", "script": { "id": "74cc0f85-d34c-4e5c-b9f9-41dd90417f83", "exec": [ "", "var jsonData = pm.response.json();", "// since we created the object with this value at the folder level,", "// the search should always return at least one id", "pm.test(\"Response is not empty\", function () {", " pm.expect(jsonData).to.not.have.lengthOf(0);", "});", "", "// use lodash map to get a flat array of all the returned booking ids", "// [{\"bookingid:1\"},{\"bookingid:2\"}] ==> [1, 2]", "var booking_ids = _.map(jsonData, 'bookingid');", "", "// the id for our newly created object should be in the list of ids", "pm.test(\"Expected booking id is in the returned array\", function () {", " pm.expect(booking_ids).to.include(pm.variables.get(\"booking_id\"));", "});", "" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "{{rb_url}}/booking?firstname={{firstname}}", "host": [ "{{rb_url}}" ], "path": [ "booking" ], "query": [ { "key": "firstname", "value": "{{firstname}}" } ] } }, "response": [] }, { "name": "Search By Last Name", "event": [ { "listen": "prerequest", "script": { "id": "f90c42c7-9bf8-42c4-942d-e4ae5cbabef1", "exec": [ "" ], "type": "text/javascript" } }, { "listen": "test", "script": { "id": "74cc0f85-d34c-4e5c-b9f9-41dd90417f83", "exec": [ "", "var jsonData = pm.response.json();", "", "pm.test(\"Response is not empty\", function () {", " pm.expect(jsonData).to.not.have.lengthOf(0);", "});", "", "// use lodash map to get a flat array of all the returned booking ids", "var booking_ids = _.map(jsonData, 'bookingid');", "", "// the id for our newly created object should be there", "pm.test(\"Expected booking id is in the returned array\", function () {", " pm.expect(booking_ids).to.include(pm.variables.get(\"booking_id\"));", "});", "" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "{{rb_url}}/booking?lastname={{lastname}}", "host": [ "{{rb_url}}" ], "path": [ "booking" ], "query": [ { "key": "lastname", "value": "{{lastname}}" } ] } }, "response": [] }, { "name": "Search By First and Last Name", "event": [ { "listen": "prerequest", "script": { "id": "f90c42c7-9bf8-42c4-942d-e4ae5cbabef1", "exec": [ "" ], "type": "text/javascript" } }, { "listen": "test", "script": { "id": "74cc0f85-d34c-4e5c-b9f9-41dd90417f83", "exec": [ "", "var jsonData = pm.response.json();", "", "pm.test(\"Response is not empty\", function () {", " pm.expect(jsonData).to.not.have.lengthOf(0);", "});", "", "// use lodash map to get a flat array of all the returned booking ids", "var booking_ids = _.map(jsonData, 'bookingid');", "", "// the id for our newly created object should be there", "pm.test(\"Expected booking id is in the returned array\", function () {", " pm.expect(booking_ids).to.include(pm.variables.get(\"booking_id\"));", "});", "" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "{{rb_url}}/booking?firstname={{firstname}}&lastname={{lastname}}", "host": [ "{{rb_url}}" ], "path": [ "booking" ], "query": [ { "key": "firstname", "value": "{{firstname}}" }, { "key": "lastname", "value": "{{lastname}}" } ] } }, "response": [] }, { "name": "Search By Checkin", "event": [ { "listen": "prerequest", "script": { "id": "f90c42c7-9bf8-42c4-942d-e4ae5cbabef1", "exec": [ "" ], "type": "text/javascript" } }, { "listen": "test", "script": { "id": "74cc0f85-d34c-4e5c-b9f9-41dd90417f83", "exec": [ "", "var jsonData = pm.response.json();", "", "pm.test(\"Response is not empty\", function () {", " pm.expect(jsonData).to.not.have.lengthOf(0);", "});", "", "// use lodash map to get a flat array of all the returned booking ids", "// https://lodash.com/docs/4.17.11#map", "var booking_ids = _.map(jsonData, 'bookingid');", "console.log(booking_ids);", "", "// the id for our newly created object should be there", "pm.test(\"Expected booking id is in the returned array\", function () {", " pm.expect(booking_ids).to.include(pm.variables.get(\"booking_id\"));", "});", "" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "{{rb_url}}/booking?checkin={{checkin}}", "host": [ "{{rb_url}}" ], "path": [ "booking" ], "query": [ { "key": "checkin", "value": "{{checkin}}" } ] } }, "response": [] }, { "name": "Search By Checkout", "event": [ { "listen": "prerequest", "script": { "id": "f90c42c7-9bf8-42c4-942d-e4ae5cbabef1", "exec": [ "" ], "type": "text/javascript" } }, { "listen": "test", "script": { "id": "74cc0f85-d34c-4e5c-b9f9-41dd90417f83", "exec": [ "", "var jsonData = pm.response.json();", "", "pm.test(\"Response is not empty\", function () {", " pm.expect(jsonData).to.not.have.lengthOf(0);", "});", "", "// use lodash map to get a flat array of all the returned booking ids", "// https://lodash.com/docs/4.17.11#map", "var booking_ids = _.map(jsonData, 'bookingid');", "", "// the id for our newly created object should be there", "pm.test(\"Expected booking id is in the returned array\", function () {", " pm.expect(booking_ids).to.include(pm.variables.get(\"booking_id\"));", "});", "" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "{{rb_url}}/booking?checkout={{checkout}}", "host": [ "{{rb_url}}" ], "path": [ "booking" ], "query": [ { "key": "checkout", "value": "{{checkout}}" } ] } }, "response": [] }, { "name": "Empty Search", "event": [ { "listen": "test", "script": { "id": "8b187d98-662c-48ae-9e5d-ed529ef45d12", "exec": [ "var jsonData = pm.response.json();", "", "pm.test(\"Response is empty\", function () {", " pm.expect(jsonData).to.have.lengthOf(0);", "});" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "{{rb_url}}/booking?firstname=non_existent_name", "host": [ "{{rb_url}}" ], "path": [ "booking" ], "query": [ { "key": "firstname", "value": "non_existent_name" } ] } }, "response": [] } ], "event": [ { "listen": "prerequest", "script": { "id": "eac3a568-9f07-486c-8969-cc852363f656", "type": "text/javascript", "exec": [ "", "const createBooking = {", " url: pm.environment.get(\"rb_url\") + \"/booking\",", " method: 'POST',", " header: 'Content-Type:application/json',", " body: {", " mode: 'raw',", " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", " }", "};", "pm.sendRequest(createBooking, function (err, res) {", " pm.expect(err).is.null;", " pm.variables.set(\"booking_id\", res.json().bookingid)", "});" ] } }, { "listen": "test", "script": { "id": "90ac4d0a-93bd-4468-810b-5f23ce7945f7", "type": "text/javascript", "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "var jsonData = pm.response.json();", "", "if(jsonData.length > 0){", " pm.test(\"Responses are booking ids\", function() {", " // lodash forEach will iterate through each object ", " // in the array and apply the given function", " // https://lodash.com/docs/4.17.11#forEach", " _.forEach(jsonData, function(booking) {", " pm.expect(booking).to.have.property(\"bookingid\")", " })", " })", "}" ] } } ] }, { "name": "Get Booking by ID", "item": [ { "name": "Existing ID", "event": [ { "listen": "prerequest", "script": { "id": "c4d895d9-1886-4369-819e-92688aad5e88", "exec": [ "const createBooking = {", " url: pm.environment.get(\"rb_url\") + \"/booking\",", " method: 'POST',", " header: 'Content-Type:application/json',", " body: {", " mode: 'raw',", " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", " }", "};", "pm.sendRequest(createBooking, function (err, res) {", " pm.expect(err).is.null;", " pm.variables.set(\"booking_id\", res.json().bookingid)", " pm.variables.set(\"expected\", res.json().booking)", "});" ], "type": "text/javascript" } }, { "listen": "test", "script": { "id": "1728438e-328c-406c-93d8-b32cba372079", "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "pm.test(\"Expected booking is returned\", function () {", " var jsonData = pm.response.json();", " pm.expect(jsonData).to.eql(pm.variables.get(\"expected\"));", "});" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "{{rb_url}}/booking/{{booking_id}}", "host": [ "{{rb_url}}" ], "path": [ "booking", "{{booking_id}}" ] } }, "response": [] }, { "name": "Non-Existent ID", "event": [ { "listen": "test", "script": { "id": "15fc9672-7ee2-4c7a-9346-0637f73faaa5", "exec": [ "pm.test(\"Status code is 404\", function () {", " pm.response.to.have.status(\"Not Found\")", "});" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "{{rb_url}}/booking/0", "host": [ "{{rb_url}}" ], "path": [ "booking", "0" ] } }, "response": [] } ] }, { "name": "Create Booking", "item": [ { "name": "Valid Create", "event": [ { "listen": "test", "script": { "id": "b4381f93-9575-411f-a03e-e23a586a5db8", "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "pm.test(\"Response booking is correct\", function () {", " var booking = pm.response.json().booking;", " pm.expect(booking.firstname, \"unexpected firstname\").to.eql(pm.variables.get(\"firstname\"));", " pm.expect(booking.lastname, \"unexpected lastname\").to.eql(pm.variables.get(\"lastname\"));", " pm.expect(booking.totalprice, \"unexpected totalprice\").to.eql(pm.variables.get(\"totalprice\"));", " pm.expect(booking.depositpaid, \"unexpected depositpaid\").to.eql(pm.variables.get(\"depositpaid\"));", " pm.expect(booking.bookingdates.checkin, \"unexpected checkin\").to.eql(pm.variables.get(\"checkin\"));", " pm.expect(booking.bookingdates.checkout, \"unexpected checkout\").to.eql(pm.variables.get(\"checkout\"));", " pm.expect(booking.additionalneeds, \"unexpected additionalneeds\").to.eql(pm.variables.get(\"additionalneeds\"));", "});" ], "type": "text/javascript" } } ], "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"firstname\" : \"{{firstname}}\",\n \"lastname\" : \"{{lastname}}\",\n \"totalprice\" : {{totalprice}},\n \"depositpaid\" : {{depositpaid}},\n \"bookingdates\" : {\n \"checkin\" : \"{{checkin}}\",\n \"checkout\" : \"{{checkout}}\"\n },\n \"additionalneeds\" : \"{{additionalneeds}}\"\n}" }, "url": { "raw": "{{rb_url}}/booking", "host": [ "{{rb_url}}" ], "path": [ "booking" ] } }, "response": [] }, { "name": "First name is null", "event": [ { "listen": "test", "script": { "id": "b4381f93-9575-411f-a03e-e23a586a5db8", "exec": [ "pm.test(\"Create fails\", function () {", " pm.response.to.not.have.success;", "});", "" ], "type": "text/javascript" } } ], "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"firstname\" : null,\n \"lastname\" : \"{{lastname}}\",\n \"totalprice\" : {{totalprice}},\n \"depositpaid\" : {{depositpaid}},\n \"bookingdates\" : {\n \"checkin\" : \"{{checkin}}\",\n \"checkout\" : \"{{checkout}}\"\n },\n \"additionalneeds\" : \"{{additionalneeds}}\"\n}" }, "url": { "raw": "{{rb_url}}/booking", "host": [ "{{rb_url}}" ], "path": [ "booking" ] } }, "response": [] } ] }, { "name": "Modify Booking", "item": [ { "name": "Valid Update", "event": [ { "listen": "prerequest", "script": { "id": "8038a405-e8b2-42f0-a30e-68bfe1fcbfd8", "exec": [ "// create the base booking", "const createBooking = {", " url: pm.environment.get(\"rb_url\") + \"/booking\",", " method: 'POST',", " header: 'Content-Type:application/json',", " body: {", " mode: 'raw',", " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", " }", "};", "pm.sendRequest(createBooking, function (err, res) {", " pm.expect(err).is.null;", " pm.variables.set(\"booking_id\", res.json().bookingid)", "});", "", "const uuid = require(\"uuid\");", "// reset the firstname and lastname variables", "pm.variables.set(\"firstname\", uuid());", "pm.variables.set(\"lastname\", uuid());" ], "type": "text/javascript" } }, { "listen": "test", "script": { "id": "fc46bdbf-a724-43ae-80f9-2b1251bfc890", "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "var booking = pm.response.json();", "pm.test(\"Response firstname is correct\", function () {", " pm.expect(booking.firstname, \"unexpected firstname\").to.eql(pm.variables.get(\"firstname\"));", "});", "pm.test(\"Response lastname is correct\", function () {", " pm.expect(booking.lastname, \"unexpected lastname\").to.eql(pm.variables.get(\"lastname\"));", "});", "pm.test(\"Response totalprice is correct\", function () {", " pm.expect(booking.totalprice, \"unexpected totalprice\").to.eql(pm.variables.get(\"totalprice\"));", "});", "pm.test(\"Response depositpaid is correct\", function () {", " pm.expect(booking.depositpaid, \"unexpected depositpaid\").to.eql(pm.variables.get(\"depositpaid\"));", "});", "pm.test(\"Response checkin is correct\", function () {", " pm.expect(booking.bookingdates.checkin, \"unexpected checkin\").to.eql(pm.variables.get(\"checkin\"));", "});", "pm.test(\"Response checkout is correct\", function () {", " pm.expect(booking.bookingdates.checkout, \"unexpected checkout\").to.eql(pm.variables.get(\"checkout\"));", "});", "pm.test(\"Response additionalneeds is correct\", function () {", " pm.expect(booking.additionalneeds, \"unexpected additionalneeds\").to.eql(pm.variables.get(\"additionalneeds\"));", "});" ], "type": "text/javascript" } } ], "request": { "auth": { "type": "basic", "basic": [ { "key": "password", "value": "password123", "type": "string" }, { "key": "username", "value": "admin", "type": "string" } ] }, "method": "PUT", "header": [ { "key": "Content-Type", "value": "application/json" }, { "key": "Accept", "value": "application/json" }, { "key": "Cookie", "value": "token=abc123" } ], "body": { "mode": "raw", "raw": "{\n \"firstname\" : \"{{firstname}}\",\n \"lastname\" : \"{{lastname}}\",\n \"totalprice\" : {{totalprice}},\n \"depositpaid\" : {{depositpaid}},\n \"bookingdates\" : {\n \"checkin\" : \"{{checkin}}\",\n \"checkout\" : \"{{checkout}}\"\n },\n \"additionalneeds\" : \"{{additionalneeds}}\"\n}" }, "url": { "raw": "{{rb_url}}/booking/{{booking_id}}", "host": [ "{{rb_url}}" ], "path": [ "booking", "{{booking_id}}" ] } }, "response": [] }, { "name": "Update Invalid Name", "event": [ { "listen": "prerequest", "script": { "id": "8038a405-e8b2-42f0-a30e-68bfe1fcbfd8", "exec": [ "// create the base booking", "const createBooking = {", " url: pm.environment.get(\"rb_url\") + \"/booking\",", " method: 'POST',", " header: 'Content-Type:application/json',", " body: {", " mode: 'raw',", " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", " }", "};", "pm.sendRequest(createBooking, function (err, res) {", " pm.expect(err).is.null;", " pm.variables.set(\"booking_id\", res.json().bookingid)", "});", "" ], "type": "text/javascript" } }, { "listen": "test", "script": { "id": "fc46bdbf-a724-43ae-80f9-2b1251bfc890", "exec": [ "pm.test(\"Update fails\", function () {", " pm.response.to.not.have.success;", "});", "", "pm.sendRequest(pm.environment.get(\"rb_url\") + \"/booking/\" + pm.variables.get(\"booking_id\"), function (err, res) {", " if (err) { console.log(err); }", " pm.test('Booking is unchanged', function () {", " pm.expect(err).to.equal(null);", " pm.expect(res.text()).to.include(pm.variables.get(\"firstname\"));", " });", "});" ], "type": "text/javascript" } } ], "request": { "auth": { "type": "basic", "basic": [ { "key": "password", "value": "password123", "type": "string" }, { "key": "username", "value": "admin", "type": "string" } ] }, "method": "PUT", "header": [ { "key": "Content-Type", "value": "application/json" }, { "key": "Accept", "value": "application/json" }, { "key": "Cookie", "value": "token=abc123" } ], "body": { "mode": "raw", "raw": "{\n \"firstname\" : null,\n \"lastname\" : \"{{lastname}}\",\n \"totalprice\" : {{totalprice}},\n \"depositpaid\" : {{depositpaid}},\n \"bookingdates\" : {\n \"checkin\" : \"{{checkin}}\",\n \"checkout\" : \"{{checkout}}\"\n },\n \"additionalneeds\" : \"{{additionalneeds}}\"\n}" }, "url": { "raw": "{{rb_url}}/booking/{{booking_id}}", "host": [ "{{rb_url}}" ], "path": [ "booking", "{{booking_id}}" ] } }, "response": [] }, { "name": "Update Invalid Date", "event": [ { "listen": "prerequest", "script": { "id": "8038a405-e8b2-42f0-a30e-68bfe1fcbfd8", "exec": [ "// create the base booking", "const createBooking = {", " url: pm.environment.get(\"rb_url\") + \"/booking\",", " method: 'POST',", " header: 'Content-Type:application/json',", " body: {", " mode: 'raw',", " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", " }", "};", "pm.sendRequest(createBooking, function (err, res) {", " pm.expect(err).is.null;", " pm.variables.set(\"booking_id\", res.json().bookingid)", "});", "" ], "type": "text/javascript" } }, { "listen": "test", "script": { "id": "fc46bdbf-a724-43ae-80f9-2b1251bfc890", "exec": [ "pm.test(\"Update fails\", function () {", " pm.response.to.not.have.success;", "});", "", "pm.sendRequest(pm.environment.get(\"rb_url\") + \"/booking/\" + pm.variables.get(\"booking_id\"), function (err, res) {", " if (err) { console.log(err); }", " pm.test('Booking is unchanged', function () {", " pm.expect(err).to.equal(null);", " pm.expect(res.text()).to.include(pm.variables.get(\"firstname\"));", " });", "});" ], "type": "text/javascript" } } ], "request": { "auth": { "type": "basic", "basic": [ { "key": "password", "value": "password123", "type": "string" }, { "key": "username", "value": "admin", "type": "string" } ] }, "method": "PUT", "header": [ { "key": "Content-Type", "value": "application/json" }, { "key": "Accept", "value": "application/json" }, { "key": "Cookie", "value": "token=abc123" } ], "body": { "mode": "raw", "raw": "{\n \"firstname\" : \"{{firstname}}\",\n \"lastname\" : \"{{lastname}}\",\n \"totalprice\" : {{totalprice}},\n \"depositpaid\" : {{depositpaid}},\n \"bookingdates\" : {\n \"checkin\" : \"2019-12-32\",\n \"checkout\" : \"{{checkout}}\"\n },\n \"additionalneeds\" : \"{{additionalneeds}}\"\n}" }, "url": { "raw": "{{rb_url}}/booking/{{booking_id}}", "host": [ "{{rb_url}}" ], "path": [ "booking", "{{booking_id}}" ] } }, "response": [] } ] }, { "name": "Patch Modify Booking", "item": [ { "name": "Partial Update Booking", "event": [ { "listen": "prerequest", "script": { "id": "d41d9c0c-c456-4394-aff2-71ca18fe5dcd", "exec": [ "// create the base booking", "const createBooking = {", " url: pm.environment.get(\"rb_url\") + \"/booking\",", " method: 'POST',", " header: 'Content-Type:application/json',", " body: {", " mode: 'raw',", " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", " }", "};", "pm.sendRequest(createBooking, function (err, res) {", " pm.expect(err).is.null;", " pm.variables.set(\"booking_id\", res.json().bookingid)", "});", "", "const uuid = require(\"uuid\");", "// reset the firstname and lastname variables", "pm.variables.set(\"firstname\", uuid());", "pm.variables.set(\"lastname\", uuid());" ], "type": "text/javascript" } }, { "listen": "test", "script": { "id": "f306c460-57fc-4ab6-bd34-6bbe86ac1d97", "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "var booking = pm.response.json();", "pm.test(\"Response firstname is correct\", function () {", " pm.expect(booking.firstname, \"unexpected firstname\").to.eql(pm.variables.get(\"firstname\"));", "});", "pm.test(\"Response lastname is correct\", function () {", " pm.expect(booking.lastname, \"unexpected lastname\").to.eql(pm.variables.get(\"lastname\"));", "});", "" ], "type": "text/javascript" } } ], "request": { "auth": { "type": "basic", "basic": [ { "key": "password", "value": "password123", "type": "string" }, { "key": "username", "value": "admin", "type": "string" } ] }, "method": "PATCH", "header": [ { "key": "Content-Type", "value": "application/json" }, { "key": "Accept", "value": "application/json" }, { "key": "Cookie", "value": "token=abc123" } ], "body": { "mode": "raw", "raw": "{\n \"firstname\" : \"{{firstname}}\",\n \"lastname\" : \"{{lastname}}\"\n}" }, "url": { "raw": "{{rb_url}}/booking/{{booking_id}}", "host": [ "{{rb_url}}" ], "path": [ "booking", "{{booking_id}}" ] } }, "response": [] }, { "name": "Invalid Patch", "event": [ { "listen": "prerequest", "script": { "id": "d41d9c0c-c456-4394-aff2-71ca18fe5dcd", "exec": [ "// create the base booking", "const createBooking = {", " url: pm.environment.get(\"rb_url\") + \"/booking\",", " method: 'POST',", " header: 'Content-Type:application/json',", " body: {", " mode: 'raw',", " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", " }", "};", "pm.sendRequest(createBooking, function (err, res) {", " pm.expect(err).is.null;", " pm.variables.set(\"booking_id\", res.json().bookingid)", "});" ], "type": "text/javascript" } }, { "listen": "test", "script": { "id": "f306c460-57fc-4ab6-bd34-6bbe86ac1d97", "exec": [ "pm.test(\"Patch fails\", function () {", " pm.response.to.not.have.success;", "});", "", "pm.sendRequest(pm.environment.get(\"rb_url\") + \"/booking/\" + pm.variables.get(\"booking_id\"), function (err, res) {", " if (err) { console.log(err); }", " pm.test('Booking is unchanged', function () {", " pm.expect(err).to.equal(null);", " pm.expect(res.text()).to.include(pm.variables.get(\"firstname\"));", " });", "});" ], "type": "text/javascript" } } ], "request": { "auth": { "type": "basic", "basic": [ { "key": "password", "value": "password123", "type": "string" }, { "key": "username", "value": "admin", "type": "string" } ] }, "method": "PATCH", "header": [ { "key": "Content-Type", "value": "application/json" }, { "key": "Accept", "value": "application/json" }, { "key": "Cookie", "value": "token=abc123" } ], "body": { "mode": "raw", "raw": "{\n \"firstname\" : null,\n \"lastname\" : \"{{lastname}}\"\n}" }, "url": { "raw": "{{rb_url}}/booking/{{booking_id}}", "host": [ "{{rb_url}}" ], "path": [ "booking", "{{booking_id}}" ] } }, "response": [] } ] }, { "name": "Ping", "event": [ { "listen": "test", "script": { "id": "63b6f724-102f-4d03-8675-f30f5f3a988b", "exec": [ "pm.test(\"Ping is successful\", function () {", " pm.response.to.be.success;", "});" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [], "body": { "mode": "raw", "raw": "" }, "url": { "raw": "{{rb_url}}/ping", "host": [ "{{rb_url}}" ], "path": [ "ping" ] } }, "response": [] }, { "name": "Auth", "event": [ { "listen": "test", "script": { "id": "cd2ebd72-b117-48c1-aaea-eb85c0c8753c", "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "pm.test(\"Response contains token\", function () {", " var jsonData = pm.response.json();", " pm.expect(jsonData).to.have.property(\"token\");", "});" ], "type": "text/javascript" } } ], "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"username\" : \"admin\",\n \"password\" : \"password123\"\n}" }, "url": { "raw": "{{rb_url}}/auth", "host": [ "{{rb_url}}" ], "path": [ "auth" ] } }, "response": [] }, { "name": "Delete Booking", "event": [ { "listen": "prerequest", "script": { "id": "d27455dc-a367-4d1f-890f-f5fea189d0ff", "exec": [ "// create the base booking", "const createBooking = {", " url: pm.environment.get(\"rb_url\") + \"/booking\",", " method: 'POST',", " header: 'Content-Type:application/json',", " body: {", " mode: 'raw',", " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", " }", "};", "pm.sendRequest(createBooking, function (err, res) {", " pm.expect(err).is.null;", " pm.variables.set(\"booking_id\", res.json().bookingid)", "});" ], "type": "text/javascript" } }, { "listen": "test", "script": { "id": "6057ab1f-a1bc-4186-bfab-4d0cd2d6ff9f", "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "", "pm.sendRequest(pm.environment.get(\"rb_url\") + \"/booking/\" + pm.variables.get(\"booking_id\"), function (err, res) {", " if (err) { console.log(err); }", " pm.test('Booking no longer exists', function () {", " pm.expect(err).to.equal(null);", " pm.expect(res.code).to.eql(404);", " });", "});" ], "type": "text/javascript" } } ], "request": { "auth": { "type": "basic", "basic": [ { "key": "password", "value": "password123", "type": "string" }, { "key": "username", "value": "admin", "type": "string" } ] }, "method": "DELETE", "header": [ { "key": "Content-Type", "value": "application/json" }, { "key": "Cookie", "value": "token=abc123" } ], "body": {}, "url": { "raw": "{{rb_url}}/booking/{{booking_id}}", "host": [ "{{rb_url}}" ], "path": [ "booking", "{{booking_id}}" ] } }, "response": [] } ], "event": [ { "listen": "prerequest", "script": { "id": "858f0d4e-0d8a-4587-a962-f5d8f2446884", "type": "text/javascript", "exec": [ "// top names of 1996", "var firstNames = [\"Emily\",\"Michael\", \"Jessica\",\"Matthew\", \"Ashley\",", "\"Jacob\",\"Sarah\",\"Christopher\",\"Samantha\",\"Joshua\",", "\"Taylor\",\"Nicholas\",\"Hannah\",\"Tyler\",\"Alexis\",", "\"Brandon\",\"Rachel\",\"Austin\",\"Elizabeth\",\"Andrew\"];", "", "// top surnames in the U.S.", "var lastNames = [\"Smith\", \"Johnson\", \"Williams\", \"Jones\", \"Brown\", ", "\"Davis\", \"Miller\", \"Wilson\", \"Moore\", \"Taylor\", ", "\"Anderson\", \"Thomas\", \"Jackson\", \"White\", \"Harris\", ", "\"Martin\", \"Thompson\", \"Garcia\", \"Martinez\", \"Robinson\"];", "", "// randomly select first and last names then add to collection variables", "pm.variables.set(\"firstname\", firstNames[_.random(firstNames.length - 1)]);", "pm.variables.set(\"lastname\", lastNames[_.random(lastNames.length - 1)]);", "", "// the random function comes from the loadash module (\"_.\")", "// https://lodash.com/docs/4.17.11#random", "pm.variables.set(\"totalprice\", _.random(50, 250));", "pm.variables.set(\"depositpaid\", (_.random(1) === 1));", "", "// the moment module helps with date manipulation and formatting", "const moment = require(\"moment\");", "var checkin = moment().add(\"days\", _.random(1, 180));", "pm.variables.set(\"checkin\", checkin.format(\"YYYY-MM-DD\"));", "", "var checkout = checkin.add(\"days\", _.random(1, 14));", "pm.variables.set(\"checkout\", checkout.format(\"YYYY-MM-DD\"));", "", "var needs = [\"breakfast\", \"lunch\", \"early checkin\", \"late checkout\", null];", "pm.variables.set(\"additionalneeds\", needs[_.random(needs.length-1)]);", "", "// put all the selected variables into a new booking object and save to a variable", "var booking = {", " \"firstname\" : pm.variables.get(\"firstname\"),", " \"lastname\" : pm.variables.get(\"lastname\"),", " \"totalprice\" : pm.variables.get(\"totalprice\"),", " \"depositpaid\" : pm.variables.get(\"depositpaid\"),", " \"bookingdates\" : {", " \"checkin\" : pm.variables.get(\"checkin\"),", " \"checkout\" : pm.variables.get(\"checkout\")", " },", " \"additionalneeds\" : pm.variables.get(\"additionalneeds\")", "}", "pm.variables.set(\"new_booking\", booking)" ] } }, { "listen": "test", "script": { "id": "da1316f6-9655-441e-bd27-8abc3715f398", "type": "text/javascript", "exec": [ "" ] } } ] }