├── README.md ├── tau └── Lesson4 │ ├── Local.postman_environment.json │ ├── Production.postman_environment.json │ └── RestfulBookerBVT.postman_collection.json ├── LICENSE └── .github └── workflows └── github-actions-demo.yml /README.md: -------------------------------------------------------------------------------- 1 | # explore-with-postman 2 | A forked copy of Amber Race's Test Automation University course code, to accompany Beth Marshall's Test Automation University Course, "API Test Automation With Postman". 3 | 4 | You can discover more of Amber's amazing code for API exploratory testing on her github page here: https://github.com/ambertests 5 | -------------------------------------------------------------------------------- /tau/Lesson4/Local.postman_environment.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "a9271dab-d1ca-4144-9d5f-e05efe0df251", 3 | "name": "Local", 4 | "values": [ 5 | { 6 | "key": "rb_url", 7 | "value": "http://localhost:3001", 8 | "type": "text", 9 | "description": "", 10 | "enabled": true 11 | } 12 | ], 13 | "_postman_variable_scope": "environment", 14 | "_postman_exported_at": "2019-01-05T17:41:36.797Z", 15 | "_postman_exported_using": "Postman/6.6.1" 16 | } -------------------------------------------------------------------------------- /tau/Lesson4/Production.postman_environment.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "8b72e838-c813-4859-a2fe-0f3bb3f3bc30", 3 | "name": "Production", 4 | "values": [ 5 | { 6 | "key": "rb_url", 7 | "value": "https://restful-booker.herokuapp.com", 8 | "type": "text", 9 | "description": "", 10 | "enabled": true 11 | } 12 | ], 13 | "_postman_variable_scope": "environment", 14 | "_postman_exported_at": "2019-01-05T17:41:29.985Z", 15 | "_postman_exported_using": "Postman/6.6.1" 16 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Amber Race 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/workflows/github-actions-demo.yml: -------------------------------------------------------------------------------- 1 | # This is an intermediate workflow to help you produce a HTML extra test results report 2 | 3 | name: "Newman Tests" 4 | on: [push, pull_request] 5 | 6 | jobs: 7 | test-api: 8 | runs-on: ubuntu-latest 9 | steps: 10 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 11 | - uses: actions/checkout@v2 12 | 13 | # INstall Node on the runner 14 | - name: Install Node 15 | uses: actions/setup-node@v2 16 | with: 17 | node-version: '16.x' 18 | 19 | 20 | # Install the newman command line utility and also install the html extra reporter 21 | - name: Install newman 22 | run: | 23 | npm install -g newman 24 | npm install -g newman-reporter-htmlextra 25 | 26 | # Make directory to upload the test results 27 | - name: Make Directory for results 28 | run: mkdir -p testResults 29 | 30 | - name: Run API Tests 31 | run: newman run "tau/Lesson4/RestfulBookerBVT.postman_collection.json" -e "tau/Lesson4/Production.postman_environment.json" -r htmlextra --reporter-htmlextra-export testResults/htmlreport.html 32 | 33 | # Upload the contents of Test Results directory to workspace 34 | - name: Output the run Details 35 | uses: actions/upload-artifact@v2 36 | with: 37 | name: RunReports 38 | path: testResults 39 | -------------------------------------------------------------------------------- /tau/Lesson4/RestfulBookerBVT.postman_collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "_postman_id": "5d1ba4ae-d097-4a2b-a251-801c44b01f7a", 4 | "name": "Restful Booker BVT", 5 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" 6 | }, 7 | "item": [ 8 | { 9 | "name": "Get Bookings", 10 | "item": [ 11 | { 12 | "name": "Get All Bookings", 13 | "event": [ 14 | { 15 | "listen": "test", 16 | "script": { 17 | "id": "c34de8f7-c523-471a-b74b-b065d0aa980e", 18 | "exec": [ 19 | "", 20 | "var jsonData = pm.response.json();", 21 | "", 22 | "//we created at least one booking at the folder level, so there should always be bookings", 23 | "pm.test(\"Response is not empty\", function () {", 24 | " // See Chaijs docs for complete list of available assertions", 25 | " // https://www.chaijs.com/api/bdd", 26 | " pm.expect(jsonData).to.not.have.lengthOf(0);", 27 | "});", 28 | "" 29 | ], 30 | "type": "text/javascript" 31 | } 32 | } 33 | ], 34 | "request": { 35 | "method": "GET", 36 | "header": [], 37 | "body": { 38 | "mode": "raw", 39 | "raw": "" 40 | }, 41 | "url": { 42 | "raw": "{{rb_url}}/booking", 43 | "host": [ 44 | "{{rb_url}}" 45 | ], 46 | "path": [ 47 | "booking" 48 | ] 49 | } 50 | }, 51 | "response": [] 52 | }, 53 | { 54 | "name": "Search By First Name", 55 | "event": [ 56 | { 57 | "listen": "prerequest", 58 | "script": { 59 | "id": "f90c42c7-9bf8-42c4-942d-e4ae5cbabef1", 60 | "exec": [ 61 | "" 62 | ], 63 | "type": "text/javascript" 64 | } 65 | }, 66 | { 67 | "listen": "test", 68 | "script": { 69 | "id": "74cc0f85-d34c-4e5c-b9f9-41dd90417f83", 70 | "exec": [ 71 | "", 72 | "var jsonData = pm.response.json();", 73 | "// since we created the object with this value at the folder level,", 74 | "// the search should always return at least one id", 75 | "pm.test(\"Response is not empty\", function () {", 76 | " pm.expect(jsonData).to.not.have.lengthOf(0);", 77 | "});", 78 | "", 79 | "// use lodash map to get a flat array of all the returned booking ids", 80 | "// [{\"bookingid:1\"},{\"bookingid:2\"}] ==> [1, 2]", 81 | "var booking_ids = _.map(jsonData, 'bookingid');", 82 | "", 83 | "// the id for our newly created object should be in the list of ids", 84 | "pm.test(\"Expected booking id is in the returned array\", function () {", 85 | " pm.expect(booking_ids).to.include(pm.variables.get(\"booking_id\"));", 86 | "});", 87 | "" 88 | ], 89 | "type": "text/javascript" 90 | } 91 | } 92 | ], 93 | "request": { 94 | "method": "GET", 95 | "header": [], 96 | "body": { 97 | "mode": "raw", 98 | "raw": "" 99 | }, 100 | "url": { 101 | "raw": "{{rb_url}}/booking?firstname={{firstname}}", 102 | "host": [ 103 | "{{rb_url}}" 104 | ], 105 | "path": [ 106 | "booking" 107 | ], 108 | "query": [ 109 | { 110 | "key": "firstname", 111 | "value": "{{firstname}}" 112 | } 113 | ] 114 | } 115 | }, 116 | "response": [] 117 | }, 118 | { 119 | "name": "Search By Last Name", 120 | "event": [ 121 | { 122 | "listen": "prerequest", 123 | "script": { 124 | "id": "f90c42c7-9bf8-42c4-942d-e4ae5cbabef1", 125 | "exec": [ 126 | "" 127 | ], 128 | "type": "text/javascript" 129 | } 130 | }, 131 | { 132 | "listen": "test", 133 | "script": { 134 | "id": "74cc0f85-d34c-4e5c-b9f9-41dd90417f83", 135 | "exec": [ 136 | "", 137 | "var jsonData = pm.response.json();", 138 | "", 139 | "pm.test(\"Response is not empty\", function () {", 140 | " pm.expect(jsonData).to.not.have.lengthOf(0);", 141 | "});", 142 | "", 143 | "// use lodash map to get a flat array of all the returned booking ids", 144 | "var booking_ids = _.map(jsonData, 'bookingid');", 145 | "", 146 | "// the id for our newly created object should be there", 147 | "pm.test(\"Expected booking id is in the returned array\", function () {", 148 | " pm.expect(booking_ids).to.include(pm.variables.get(\"booking_id\"));", 149 | "});", 150 | "" 151 | ], 152 | "type": "text/javascript" 153 | } 154 | } 155 | ], 156 | "request": { 157 | "method": "GET", 158 | "header": [], 159 | "body": { 160 | "mode": "raw", 161 | "raw": "" 162 | }, 163 | "url": { 164 | "raw": "{{rb_url}}/booking?lastname={{lastname}}", 165 | "host": [ 166 | "{{rb_url}}" 167 | ], 168 | "path": [ 169 | "booking" 170 | ], 171 | "query": [ 172 | { 173 | "key": "lastname", 174 | "value": "{{lastname}}" 175 | } 176 | ] 177 | } 178 | }, 179 | "response": [] 180 | }, 181 | { 182 | "name": "Search By First and Last Name", 183 | "event": [ 184 | { 185 | "listen": "prerequest", 186 | "script": { 187 | "id": "f90c42c7-9bf8-42c4-942d-e4ae5cbabef1", 188 | "exec": [ 189 | "" 190 | ], 191 | "type": "text/javascript" 192 | } 193 | }, 194 | { 195 | "listen": "test", 196 | "script": { 197 | "id": "74cc0f85-d34c-4e5c-b9f9-41dd90417f83", 198 | "exec": [ 199 | "", 200 | "var jsonData = pm.response.json();", 201 | "", 202 | "pm.test(\"Response is not empty\", function () {", 203 | " pm.expect(jsonData).to.not.have.lengthOf(0);", 204 | "});", 205 | "", 206 | "// use lodash map to get a flat array of all the returned booking ids", 207 | "var booking_ids = _.map(jsonData, 'bookingid');", 208 | "", 209 | "// the id for our newly created object should be there", 210 | "pm.test(\"Expected booking id is in the returned array\", function () {", 211 | " pm.expect(booking_ids).to.include(pm.variables.get(\"booking_id\"));", 212 | "});", 213 | "" 214 | ], 215 | "type": "text/javascript" 216 | } 217 | } 218 | ], 219 | "request": { 220 | "method": "GET", 221 | "header": [], 222 | "body": { 223 | "mode": "raw", 224 | "raw": "" 225 | }, 226 | "url": { 227 | "raw": "{{rb_url}}/booking?firstname={{firstname}}&lastname={{lastname}}", 228 | "host": [ 229 | "{{rb_url}}" 230 | ], 231 | "path": [ 232 | "booking" 233 | ], 234 | "query": [ 235 | { 236 | "key": "firstname", 237 | "value": "{{firstname}}" 238 | }, 239 | { 240 | "key": "lastname", 241 | "value": "{{lastname}}" 242 | } 243 | ] 244 | } 245 | }, 246 | "response": [] 247 | }, 248 | { 249 | "name": "Search By Checkin", 250 | "event": [ 251 | { 252 | "listen": "prerequest", 253 | "script": { 254 | "id": "f90c42c7-9bf8-42c4-942d-e4ae5cbabef1", 255 | "exec": [ 256 | "" 257 | ], 258 | "type": "text/javascript" 259 | } 260 | }, 261 | { 262 | "listen": "test", 263 | "script": { 264 | "id": "74cc0f85-d34c-4e5c-b9f9-41dd90417f83", 265 | "exec": [ 266 | "", 267 | "var jsonData = pm.response.json();", 268 | "", 269 | "pm.test(\"Response is not empty\", function () {", 270 | " pm.expect(jsonData).to.not.have.lengthOf(0);", 271 | "});", 272 | "", 273 | "// use lodash map to get a flat array of all the returned booking ids", 274 | "// https://lodash.com/docs/4.17.11#map", 275 | "var booking_ids = _.map(jsonData, 'bookingid');", 276 | "console.log(booking_ids);", 277 | "", 278 | "// the id for our newly created object should be there", 279 | "pm.test(\"Expected booking id is in the returned array\", function () {", 280 | " pm.expect(booking_ids).to.include(pm.variables.get(\"booking_id\"));", 281 | "});", 282 | "" 283 | ], 284 | "type": "text/javascript" 285 | } 286 | } 287 | ], 288 | "request": { 289 | "method": "GET", 290 | "header": [], 291 | "body": { 292 | "mode": "raw", 293 | "raw": "" 294 | }, 295 | "url": { 296 | "raw": "{{rb_url}}/booking?checkin={{checkin}}", 297 | "host": [ 298 | "{{rb_url}}" 299 | ], 300 | "path": [ 301 | "booking" 302 | ], 303 | "query": [ 304 | { 305 | "key": "checkin", 306 | "value": "{{checkin}}" 307 | } 308 | ] 309 | } 310 | }, 311 | "response": [] 312 | }, 313 | { 314 | "name": "Search By Checkout", 315 | "event": [ 316 | { 317 | "listen": "prerequest", 318 | "script": { 319 | "id": "f90c42c7-9bf8-42c4-942d-e4ae5cbabef1", 320 | "exec": [ 321 | "" 322 | ], 323 | "type": "text/javascript" 324 | } 325 | }, 326 | { 327 | "listen": "test", 328 | "script": { 329 | "id": "74cc0f85-d34c-4e5c-b9f9-41dd90417f83", 330 | "exec": [ 331 | "", 332 | "var jsonData = pm.response.json();", 333 | "", 334 | "pm.test(\"Response is not empty\", function () {", 335 | " pm.expect(jsonData).to.not.have.lengthOf(0);", 336 | "});", 337 | "", 338 | "// use lodash map to get a flat array of all the returned booking ids", 339 | "// https://lodash.com/docs/4.17.11#map", 340 | "var booking_ids = _.map(jsonData, 'bookingid');", 341 | "", 342 | "// the id for our newly created object should be there", 343 | "pm.test(\"Expected booking id is in the returned array\", function () {", 344 | " pm.expect(booking_ids).to.include(pm.variables.get(\"booking_id\"));", 345 | "});", 346 | "" 347 | ], 348 | "type": "text/javascript" 349 | } 350 | } 351 | ], 352 | "request": { 353 | "method": "GET", 354 | "header": [], 355 | "body": { 356 | "mode": "raw", 357 | "raw": "" 358 | }, 359 | "url": { 360 | "raw": "{{rb_url}}/booking?checkout={{checkout}}", 361 | "host": [ 362 | "{{rb_url}}" 363 | ], 364 | "path": [ 365 | "booking" 366 | ], 367 | "query": [ 368 | { 369 | "key": "checkout", 370 | "value": "{{checkout}}" 371 | } 372 | ] 373 | } 374 | }, 375 | "response": [] 376 | }, 377 | { 378 | "name": "Empty Search", 379 | "event": [ 380 | { 381 | "listen": "test", 382 | "script": { 383 | "id": "8b187d98-662c-48ae-9e5d-ed529ef45d12", 384 | "exec": [ 385 | "var jsonData = pm.response.json();", 386 | "", 387 | "pm.test(\"Response is empty\", function () {", 388 | " pm.expect(jsonData).to.have.lengthOf(0);", 389 | "});" 390 | ], 391 | "type": "text/javascript" 392 | } 393 | } 394 | ], 395 | "request": { 396 | "method": "GET", 397 | "header": [], 398 | "body": { 399 | "mode": "raw", 400 | "raw": "" 401 | }, 402 | "url": { 403 | "raw": "{{rb_url}}/booking?firstname=non_existent_name", 404 | "host": [ 405 | "{{rb_url}}" 406 | ], 407 | "path": [ 408 | "booking" 409 | ], 410 | "query": [ 411 | { 412 | "key": "firstname", 413 | "value": "non_existent_name" 414 | } 415 | ] 416 | } 417 | }, 418 | "response": [] 419 | } 420 | ], 421 | "event": [ 422 | { 423 | "listen": "prerequest", 424 | "script": { 425 | "id": "eac3a568-9f07-486c-8969-cc852363f656", 426 | "type": "text/javascript", 427 | "exec": [ 428 | "", 429 | "const createBooking = {", 430 | " url: pm.environment.get(\"rb_url\") + \"/booking\",", 431 | " method: 'POST',", 432 | " header: 'Content-Type:application/json',", 433 | " body: {", 434 | " mode: 'raw',", 435 | " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", 436 | " }", 437 | "};", 438 | "pm.sendRequest(createBooking, function (err, res) {", 439 | " pm.expect(err).is.null;", 440 | " pm.variables.set(\"booking_id\", res.json().bookingid)", 441 | "});" 442 | ] 443 | } 444 | }, 445 | { 446 | "listen": "test", 447 | "script": { 448 | "id": "90ac4d0a-93bd-4468-810b-5f23ce7945f7", 449 | "type": "text/javascript", 450 | "exec": [ 451 | "pm.test(\"Status code is 200\", function () {", 452 | " pm.response.to.have.status(200);", 453 | "});", 454 | "", 455 | "var jsonData = pm.response.json();", 456 | "", 457 | "if(jsonData.length > 0){", 458 | " pm.test(\"Responses are booking ids\", function() {", 459 | " // lodash forEach will iterate through each object ", 460 | " // in the array and apply the given function", 461 | " // https://lodash.com/docs/4.17.11#forEach", 462 | " _.forEach(jsonData, function(booking) {", 463 | " pm.expect(booking).to.have.property(\"bookingid\")", 464 | " })", 465 | " })", 466 | "}" 467 | ] 468 | } 469 | } 470 | ] 471 | }, 472 | { 473 | "name": "Get Booking by ID", 474 | "item": [ 475 | { 476 | "name": "Existing ID", 477 | "event": [ 478 | { 479 | "listen": "prerequest", 480 | "script": { 481 | "id": "c4d895d9-1886-4369-819e-92688aad5e88", 482 | "exec": [ 483 | "const createBooking = {", 484 | " url: pm.environment.get(\"rb_url\") + \"/booking\",", 485 | " method: 'POST',", 486 | " header: 'Content-Type:application/json',", 487 | " body: {", 488 | " mode: 'raw',", 489 | " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", 490 | " }", 491 | "};", 492 | "pm.sendRequest(createBooking, function (err, res) {", 493 | " pm.expect(err).is.null;", 494 | " pm.variables.set(\"booking_id\", res.json().bookingid)", 495 | " pm.variables.set(\"expected\", res.json().booking)", 496 | "});" 497 | ], 498 | "type": "text/javascript" 499 | } 500 | }, 501 | { 502 | "listen": "test", 503 | "script": { 504 | "id": "1728438e-328c-406c-93d8-b32cba372079", 505 | "exec": [ 506 | "pm.test(\"Status code is 200\", function () {", 507 | " pm.response.to.have.status(200);", 508 | "});", 509 | "", 510 | "pm.test(\"Expected booking is returned\", function () {", 511 | " var jsonData = pm.response.json();", 512 | " pm.expect(jsonData).to.eql(pm.variables.get(\"expected\"));", 513 | "});" 514 | ], 515 | "type": "text/javascript" 516 | } 517 | } 518 | ], 519 | "request": { 520 | "method": "GET", 521 | "header": [], 522 | "body": { 523 | "mode": "raw", 524 | "raw": "" 525 | }, 526 | "url": { 527 | "raw": "{{rb_url}}/booking/{{booking_id}}", 528 | "host": [ 529 | "{{rb_url}}" 530 | ], 531 | "path": [ 532 | "booking", 533 | "{{booking_id}}" 534 | ] 535 | } 536 | }, 537 | "response": [] 538 | }, 539 | { 540 | "name": "Non-Existent ID", 541 | "event": [ 542 | { 543 | "listen": "test", 544 | "script": { 545 | "id": "15fc9672-7ee2-4c7a-9346-0637f73faaa5", 546 | "exec": [ 547 | "pm.test(\"Status code is 404\", function () {", 548 | " pm.response.to.have.status(\"Not Found\")", 549 | "});" 550 | ], 551 | "type": "text/javascript" 552 | } 553 | } 554 | ], 555 | "request": { 556 | "method": "GET", 557 | "header": [], 558 | "body": { 559 | "mode": "raw", 560 | "raw": "" 561 | }, 562 | "url": { 563 | "raw": "{{rb_url}}/booking/0", 564 | "host": [ 565 | "{{rb_url}}" 566 | ], 567 | "path": [ 568 | "booking", 569 | "0" 570 | ] 571 | } 572 | }, 573 | "response": [] 574 | } 575 | ] 576 | }, 577 | { 578 | "name": "Create Booking", 579 | "item": [ 580 | { 581 | "name": "Valid Create", 582 | "event": [ 583 | { 584 | "listen": "test", 585 | "script": { 586 | "id": "b4381f93-9575-411f-a03e-e23a586a5db8", 587 | "exec": [ 588 | "pm.test(\"Status code is 200\", function () {", 589 | " pm.response.to.have.status(200);", 590 | "});", 591 | "", 592 | "pm.test(\"Response booking is correct\", function () {", 593 | " var booking = pm.response.json().booking;", 594 | " pm.expect(booking.firstname, \"unexpected firstname\").to.eql(pm.variables.get(\"firstname\"));", 595 | " pm.expect(booking.lastname, \"unexpected lastname\").to.eql(pm.variables.get(\"lastname\"));", 596 | " pm.expect(booking.totalprice, \"unexpected totalprice\").to.eql(pm.variables.get(\"totalprice\"));", 597 | " pm.expect(booking.depositpaid, \"unexpected depositpaid\").to.eql(pm.variables.get(\"depositpaid\"));", 598 | " pm.expect(booking.bookingdates.checkin, \"unexpected checkin\").to.eql(pm.variables.get(\"checkin\"));", 599 | " pm.expect(booking.bookingdates.checkout, \"unexpected checkout\").to.eql(pm.variables.get(\"checkout\"));", 600 | " pm.expect(booking.additionalneeds, \"unexpected additionalneeds\").to.eql(pm.variables.get(\"additionalneeds\"));", 601 | "});" 602 | ], 603 | "type": "text/javascript" 604 | } 605 | } 606 | ], 607 | "request": { 608 | "method": "POST", 609 | "header": [ 610 | { 611 | "key": "Content-Type", 612 | "value": "application/json" 613 | } 614 | ], 615 | "body": { 616 | "mode": "raw", 617 | "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}" 618 | }, 619 | "url": { 620 | "raw": "{{rb_url}}/booking", 621 | "host": [ 622 | "{{rb_url}}" 623 | ], 624 | "path": [ 625 | "booking" 626 | ] 627 | } 628 | }, 629 | "response": [] 630 | }, 631 | { 632 | "name": "First name is null", 633 | "event": [ 634 | { 635 | "listen": "test", 636 | "script": { 637 | "id": "b4381f93-9575-411f-a03e-e23a586a5db8", 638 | "exec": [ 639 | "pm.test(\"Create fails\", function () {", 640 | " pm.response.to.not.have.success;", 641 | "});", 642 | "" 643 | ], 644 | "type": "text/javascript" 645 | } 646 | } 647 | ], 648 | "request": { 649 | "method": "POST", 650 | "header": [ 651 | { 652 | "key": "Content-Type", 653 | "value": "application/json" 654 | } 655 | ], 656 | "body": { 657 | "mode": "raw", 658 | "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}" 659 | }, 660 | "url": { 661 | "raw": "{{rb_url}}/booking", 662 | "host": [ 663 | "{{rb_url}}" 664 | ], 665 | "path": [ 666 | "booking" 667 | ] 668 | } 669 | }, 670 | "response": [] 671 | } 672 | ] 673 | }, 674 | { 675 | "name": "Modify Booking", 676 | "item": [ 677 | { 678 | "name": "Valid Update", 679 | "event": [ 680 | { 681 | "listen": "prerequest", 682 | "script": { 683 | "id": "8038a405-e8b2-42f0-a30e-68bfe1fcbfd8", 684 | "exec": [ 685 | "// create the base booking", 686 | "const createBooking = {", 687 | " url: pm.environment.get(\"rb_url\") + \"/booking\",", 688 | " method: 'POST',", 689 | " header: 'Content-Type:application/json',", 690 | " body: {", 691 | " mode: 'raw',", 692 | " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", 693 | " }", 694 | "};", 695 | "pm.sendRequest(createBooking, function (err, res) {", 696 | " pm.expect(err).is.null;", 697 | " pm.variables.set(\"booking_id\", res.json().bookingid)", 698 | "});", 699 | "", 700 | "const uuid = require(\"uuid\");", 701 | "// reset the firstname and lastname variables", 702 | "pm.variables.set(\"firstname\", uuid());", 703 | "pm.variables.set(\"lastname\", uuid());" 704 | ], 705 | "type": "text/javascript" 706 | } 707 | }, 708 | { 709 | "listen": "test", 710 | "script": { 711 | "id": "fc46bdbf-a724-43ae-80f9-2b1251bfc890", 712 | "exec": [ 713 | "pm.test(\"Status code is 200\", function () {", 714 | " pm.response.to.have.status(200);", 715 | "});", 716 | "var booking = pm.response.json();", 717 | "pm.test(\"Response firstname is correct\", function () {", 718 | " pm.expect(booking.firstname, \"unexpected firstname\").to.eql(pm.variables.get(\"firstname\"));", 719 | "});", 720 | "pm.test(\"Response lastname is correct\", function () {", 721 | " pm.expect(booking.lastname, \"unexpected lastname\").to.eql(pm.variables.get(\"lastname\"));", 722 | "});", 723 | "pm.test(\"Response totalprice is correct\", function () {", 724 | " pm.expect(booking.totalprice, \"unexpected totalprice\").to.eql(pm.variables.get(\"totalprice\"));", 725 | "});", 726 | "pm.test(\"Response depositpaid is correct\", function () {", 727 | " pm.expect(booking.depositpaid, \"unexpected depositpaid\").to.eql(pm.variables.get(\"depositpaid\"));", 728 | "});", 729 | "pm.test(\"Response checkin is correct\", function () {", 730 | " pm.expect(booking.bookingdates.checkin, \"unexpected checkin\").to.eql(pm.variables.get(\"checkin\"));", 731 | "});", 732 | "pm.test(\"Response checkout is correct\", function () {", 733 | " pm.expect(booking.bookingdates.checkout, \"unexpected checkout\").to.eql(pm.variables.get(\"checkout\"));", 734 | "});", 735 | "pm.test(\"Response additionalneeds is correct\", function () {", 736 | " pm.expect(booking.additionalneeds, \"unexpected additionalneeds\").to.eql(pm.variables.get(\"additionalneeds\"));", 737 | "});" 738 | ], 739 | "type": "text/javascript" 740 | } 741 | } 742 | ], 743 | "request": { 744 | "auth": { 745 | "type": "basic", 746 | "basic": [ 747 | { 748 | "key": "password", 749 | "value": "password123", 750 | "type": "string" 751 | }, 752 | { 753 | "key": "username", 754 | "value": "admin", 755 | "type": "string" 756 | } 757 | ] 758 | }, 759 | "method": "PUT", 760 | "header": [ 761 | { 762 | "key": "Content-Type", 763 | "value": "application/json" 764 | }, 765 | { 766 | "key": "Accept", 767 | "value": "application/json" 768 | }, 769 | { 770 | "key": "Cookie", 771 | "value": "token=abc123" 772 | } 773 | ], 774 | "body": { 775 | "mode": "raw", 776 | "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}" 777 | }, 778 | "url": { 779 | "raw": "{{rb_url}}/booking/{{booking_id}}", 780 | "host": [ 781 | "{{rb_url}}" 782 | ], 783 | "path": [ 784 | "booking", 785 | "{{booking_id}}" 786 | ] 787 | } 788 | }, 789 | "response": [] 790 | }, 791 | { 792 | "name": "Update Invalid Name", 793 | "event": [ 794 | { 795 | "listen": "prerequest", 796 | "script": { 797 | "id": "8038a405-e8b2-42f0-a30e-68bfe1fcbfd8", 798 | "exec": [ 799 | "// create the base booking", 800 | "const createBooking = {", 801 | " url: pm.environment.get(\"rb_url\") + \"/booking\",", 802 | " method: 'POST',", 803 | " header: 'Content-Type:application/json',", 804 | " body: {", 805 | " mode: 'raw',", 806 | " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", 807 | " }", 808 | "};", 809 | "pm.sendRequest(createBooking, function (err, res) {", 810 | " pm.expect(err).is.null;", 811 | " pm.variables.set(\"booking_id\", res.json().bookingid)", 812 | "});", 813 | "" 814 | ], 815 | "type": "text/javascript" 816 | } 817 | }, 818 | { 819 | "listen": "test", 820 | "script": { 821 | "id": "fc46bdbf-a724-43ae-80f9-2b1251bfc890", 822 | "exec": [ 823 | "pm.test(\"Update fails\", function () {", 824 | " pm.response.to.not.have.success;", 825 | "});", 826 | "", 827 | "pm.sendRequest(pm.environment.get(\"rb_url\") + \"/booking/\" + pm.variables.get(\"booking_id\"), function (err, res) {", 828 | " if (err) { console.log(err); }", 829 | " pm.test('Booking is unchanged', function () {", 830 | " pm.expect(err).to.equal(null);", 831 | " pm.expect(res.text()).to.include(pm.variables.get(\"firstname\"));", 832 | " });", 833 | "});" 834 | ], 835 | "type": "text/javascript" 836 | } 837 | } 838 | ], 839 | "request": { 840 | "auth": { 841 | "type": "basic", 842 | "basic": [ 843 | { 844 | "key": "password", 845 | "value": "password123", 846 | "type": "string" 847 | }, 848 | { 849 | "key": "username", 850 | "value": "admin", 851 | "type": "string" 852 | } 853 | ] 854 | }, 855 | "method": "PUT", 856 | "header": [ 857 | { 858 | "key": "Content-Type", 859 | "value": "application/json" 860 | }, 861 | { 862 | "key": "Accept", 863 | "value": "application/json" 864 | }, 865 | { 866 | "key": "Cookie", 867 | "value": "token=abc123" 868 | } 869 | ], 870 | "body": { 871 | "mode": "raw", 872 | "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}" 873 | }, 874 | "url": { 875 | "raw": "{{rb_url}}/booking/{{booking_id}}", 876 | "host": [ 877 | "{{rb_url}}" 878 | ], 879 | "path": [ 880 | "booking", 881 | "{{booking_id}}" 882 | ] 883 | } 884 | }, 885 | "response": [] 886 | }, 887 | { 888 | "name": "Update Invalid Date", 889 | "event": [ 890 | { 891 | "listen": "prerequest", 892 | "script": { 893 | "id": "8038a405-e8b2-42f0-a30e-68bfe1fcbfd8", 894 | "exec": [ 895 | "// create the base booking", 896 | "const createBooking = {", 897 | " url: pm.environment.get(\"rb_url\") + \"/booking\",", 898 | " method: 'POST',", 899 | " header: 'Content-Type:application/json',", 900 | " body: {", 901 | " mode: 'raw',", 902 | " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", 903 | " }", 904 | "};", 905 | "pm.sendRequest(createBooking, function (err, res) {", 906 | " pm.expect(err).is.null;", 907 | " pm.variables.set(\"booking_id\", res.json().bookingid)", 908 | "});", 909 | "" 910 | ], 911 | "type": "text/javascript" 912 | } 913 | }, 914 | { 915 | "listen": "test", 916 | "script": { 917 | "id": "fc46bdbf-a724-43ae-80f9-2b1251bfc890", 918 | "exec": [ 919 | "pm.test(\"Update fails\", function () {", 920 | " pm.response.to.not.have.success;", 921 | "});", 922 | "", 923 | "pm.sendRequest(pm.environment.get(\"rb_url\") + \"/booking/\" + pm.variables.get(\"booking_id\"), function (err, res) {", 924 | " if (err) { console.log(err); }", 925 | " pm.test('Booking is unchanged', function () {", 926 | " pm.expect(err).to.equal(null);", 927 | " pm.expect(res.text()).to.include(pm.variables.get(\"firstname\"));", 928 | " });", 929 | "});" 930 | ], 931 | "type": "text/javascript" 932 | } 933 | } 934 | ], 935 | "request": { 936 | "auth": { 937 | "type": "basic", 938 | "basic": [ 939 | { 940 | "key": "password", 941 | "value": "password123", 942 | "type": "string" 943 | }, 944 | { 945 | "key": "username", 946 | "value": "admin", 947 | "type": "string" 948 | } 949 | ] 950 | }, 951 | "method": "PUT", 952 | "header": [ 953 | { 954 | "key": "Content-Type", 955 | "value": "application/json" 956 | }, 957 | { 958 | "key": "Accept", 959 | "value": "application/json" 960 | }, 961 | { 962 | "key": "Cookie", 963 | "value": "token=abc123" 964 | } 965 | ], 966 | "body": { 967 | "mode": "raw", 968 | "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}" 969 | }, 970 | "url": { 971 | "raw": "{{rb_url}}/booking/{{booking_id}}", 972 | "host": [ 973 | "{{rb_url}}" 974 | ], 975 | "path": [ 976 | "booking", 977 | "{{booking_id}}" 978 | ] 979 | } 980 | }, 981 | "response": [] 982 | } 983 | ] 984 | }, 985 | { 986 | "name": "Patch Modify Booking", 987 | "item": [ 988 | { 989 | "name": "Partial Update Booking", 990 | "event": [ 991 | { 992 | "listen": "prerequest", 993 | "script": { 994 | "id": "d41d9c0c-c456-4394-aff2-71ca18fe5dcd", 995 | "exec": [ 996 | "// create the base booking", 997 | "const createBooking = {", 998 | " url: pm.environment.get(\"rb_url\") + \"/booking\",", 999 | " method: 'POST',", 1000 | " header: 'Content-Type:application/json',", 1001 | " body: {", 1002 | " mode: 'raw',", 1003 | " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", 1004 | " }", 1005 | "};", 1006 | "pm.sendRequest(createBooking, function (err, res) {", 1007 | " pm.expect(err).is.null;", 1008 | " pm.variables.set(\"booking_id\", res.json().bookingid)", 1009 | "});", 1010 | "", 1011 | "const uuid = require(\"uuid\");", 1012 | "// reset the firstname and lastname variables", 1013 | "pm.variables.set(\"firstname\", uuid());", 1014 | "pm.variables.set(\"lastname\", uuid());" 1015 | ], 1016 | "type": "text/javascript" 1017 | } 1018 | }, 1019 | { 1020 | "listen": "test", 1021 | "script": { 1022 | "id": "f306c460-57fc-4ab6-bd34-6bbe86ac1d97", 1023 | "exec": [ 1024 | "pm.test(\"Status code is 200\", function () {", 1025 | " pm.response.to.have.status(200);", 1026 | "});", 1027 | "", 1028 | "var booking = pm.response.json();", 1029 | "pm.test(\"Response firstname is correct\", function () {", 1030 | " pm.expect(booking.firstname, \"unexpected firstname\").to.eql(pm.variables.get(\"firstname\"));", 1031 | "});", 1032 | "pm.test(\"Response lastname is correct\", function () {", 1033 | " pm.expect(booking.lastname, \"unexpected lastname\").to.eql(pm.variables.get(\"lastname\"));", 1034 | "});", 1035 | "" 1036 | ], 1037 | "type": "text/javascript" 1038 | } 1039 | } 1040 | ], 1041 | "request": { 1042 | "auth": { 1043 | "type": "basic", 1044 | "basic": [ 1045 | { 1046 | "key": "password", 1047 | "value": "password123", 1048 | "type": "string" 1049 | }, 1050 | { 1051 | "key": "username", 1052 | "value": "admin", 1053 | "type": "string" 1054 | } 1055 | ] 1056 | }, 1057 | "method": "PATCH", 1058 | "header": [ 1059 | { 1060 | "key": "Content-Type", 1061 | "value": "application/json" 1062 | }, 1063 | { 1064 | "key": "Accept", 1065 | "value": "application/json" 1066 | }, 1067 | { 1068 | "key": "Cookie", 1069 | "value": "token=abc123" 1070 | } 1071 | ], 1072 | "body": { 1073 | "mode": "raw", 1074 | "raw": "{\n \"firstname\" : \"{{firstname}}\",\n \"lastname\" : \"{{lastname}}\"\n}" 1075 | }, 1076 | "url": { 1077 | "raw": "{{rb_url}}/booking/{{booking_id}}", 1078 | "host": [ 1079 | "{{rb_url}}" 1080 | ], 1081 | "path": [ 1082 | "booking", 1083 | "{{booking_id}}" 1084 | ] 1085 | } 1086 | }, 1087 | "response": [] 1088 | }, 1089 | { 1090 | "name": "Invalid Patch", 1091 | "event": [ 1092 | { 1093 | "listen": "prerequest", 1094 | "script": { 1095 | "id": "d41d9c0c-c456-4394-aff2-71ca18fe5dcd", 1096 | "exec": [ 1097 | "// create the base booking", 1098 | "const createBooking = {", 1099 | " url: pm.environment.get(\"rb_url\") + \"/booking\",", 1100 | " method: 'POST',", 1101 | " header: 'Content-Type:application/json',", 1102 | " body: {", 1103 | " mode: 'raw',", 1104 | " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", 1105 | " }", 1106 | "};", 1107 | "pm.sendRequest(createBooking, function (err, res) {", 1108 | " pm.expect(err).is.null;", 1109 | " pm.variables.set(\"booking_id\", res.json().bookingid)", 1110 | "});" 1111 | ], 1112 | "type": "text/javascript" 1113 | } 1114 | }, 1115 | { 1116 | "listen": "test", 1117 | "script": { 1118 | "id": "f306c460-57fc-4ab6-bd34-6bbe86ac1d97", 1119 | "exec": [ 1120 | "pm.test(\"Patch fails\", function () {", 1121 | " pm.response.to.not.have.success;", 1122 | "});", 1123 | "", 1124 | "pm.sendRequest(pm.environment.get(\"rb_url\") + \"/booking/\" + pm.variables.get(\"booking_id\"), function (err, res) {", 1125 | " if (err) { console.log(err); }", 1126 | " pm.test('Booking is unchanged', function () {", 1127 | " pm.expect(err).to.equal(null);", 1128 | " pm.expect(res.text()).to.include(pm.variables.get(\"firstname\"));", 1129 | " });", 1130 | "});" 1131 | ], 1132 | "type": "text/javascript" 1133 | } 1134 | } 1135 | ], 1136 | "request": { 1137 | "auth": { 1138 | "type": "basic", 1139 | "basic": [ 1140 | { 1141 | "key": "password", 1142 | "value": "password123", 1143 | "type": "string" 1144 | }, 1145 | { 1146 | "key": "username", 1147 | "value": "admin", 1148 | "type": "string" 1149 | } 1150 | ] 1151 | }, 1152 | "method": "PATCH", 1153 | "header": [ 1154 | { 1155 | "key": "Content-Type", 1156 | "value": "application/json" 1157 | }, 1158 | { 1159 | "key": "Accept", 1160 | "value": "application/json" 1161 | }, 1162 | { 1163 | "key": "Cookie", 1164 | "value": "token=abc123" 1165 | } 1166 | ], 1167 | "body": { 1168 | "mode": "raw", 1169 | "raw": "{\n \"firstname\" : null,\n \"lastname\" : \"{{lastname}}\"\n}" 1170 | }, 1171 | "url": { 1172 | "raw": "{{rb_url}}/booking/{{booking_id}}", 1173 | "host": [ 1174 | "{{rb_url}}" 1175 | ], 1176 | "path": [ 1177 | "booking", 1178 | "{{booking_id}}" 1179 | ] 1180 | } 1181 | }, 1182 | "response": [] 1183 | } 1184 | ] 1185 | }, 1186 | { 1187 | "name": "Ping", 1188 | "event": [ 1189 | { 1190 | "listen": "test", 1191 | "script": { 1192 | "id": "63b6f724-102f-4d03-8675-f30f5f3a988b", 1193 | "exec": [ 1194 | "pm.test(\"Ping is successful\", function () {", 1195 | " pm.response.to.be.success;", 1196 | "});" 1197 | ], 1198 | "type": "text/javascript" 1199 | } 1200 | } 1201 | ], 1202 | "request": { 1203 | "method": "GET", 1204 | "header": [], 1205 | "body": { 1206 | "mode": "raw", 1207 | "raw": "" 1208 | }, 1209 | "url": { 1210 | "raw": "{{rb_url}}/ping", 1211 | "host": [ 1212 | "{{rb_url}}" 1213 | ], 1214 | "path": [ 1215 | "ping" 1216 | ] 1217 | } 1218 | }, 1219 | "response": [] 1220 | }, 1221 | { 1222 | "name": "Auth", 1223 | "event": [ 1224 | { 1225 | "listen": "test", 1226 | "script": { 1227 | "id": "cd2ebd72-b117-48c1-aaea-eb85c0c8753c", 1228 | "exec": [ 1229 | "pm.test(\"Status code is 200\", function () {", 1230 | " pm.response.to.have.status(200);", 1231 | "});", 1232 | "", 1233 | "pm.test(\"Response contains token\", function () {", 1234 | " var jsonData = pm.response.json();", 1235 | " pm.expect(jsonData).to.have.property(\"token\");", 1236 | "});" 1237 | ], 1238 | "type": "text/javascript" 1239 | } 1240 | } 1241 | ], 1242 | "request": { 1243 | "method": "POST", 1244 | "header": [ 1245 | { 1246 | "key": "Content-Type", 1247 | "value": "application/json" 1248 | } 1249 | ], 1250 | "body": { 1251 | "mode": "raw", 1252 | "raw": "{\n \"username\" : \"admin\",\n \"password\" : \"password123\"\n}" 1253 | }, 1254 | "url": { 1255 | "raw": "{{rb_url}}/auth", 1256 | "host": [ 1257 | "{{rb_url}}" 1258 | ], 1259 | "path": [ 1260 | "auth" 1261 | ] 1262 | } 1263 | }, 1264 | "response": [] 1265 | }, 1266 | { 1267 | "name": "Delete Booking", 1268 | "event": [ 1269 | { 1270 | "listen": "prerequest", 1271 | "script": { 1272 | "id": "d27455dc-a367-4d1f-890f-f5fea189d0ff", 1273 | "exec": [ 1274 | "// create the base booking", 1275 | "const createBooking = {", 1276 | " url: pm.environment.get(\"rb_url\") + \"/booking\",", 1277 | " method: 'POST',", 1278 | " header: 'Content-Type:application/json',", 1279 | " body: {", 1280 | " mode: 'raw',", 1281 | " raw: JSON.stringify(pm.variables.get(\"new_booking\"))", 1282 | " }", 1283 | "};", 1284 | "pm.sendRequest(createBooking, function (err, res) {", 1285 | " pm.expect(err).is.null;", 1286 | " pm.variables.set(\"booking_id\", res.json().bookingid)", 1287 | "});" 1288 | ], 1289 | "type": "text/javascript" 1290 | } 1291 | }, 1292 | { 1293 | "listen": "test", 1294 | "script": { 1295 | "id": "6057ab1f-a1bc-4186-bfab-4d0cd2d6ff9f", 1296 | "exec": [ 1297 | "pm.test(\"Status code is 200\", function () {", 1298 | " pm.response.to.have.status(200);", 1299 | "});", 1300 | "", 1301 | "", 1302 | "pm.sendRequest(pm.environment.get(\"rb_url\") + \"/booking/\" + pm.variables.get(\"booking_id\"), function (err, res) {", 1303 | " if (err) { console.log(err); }", 1304 | " pm.test('Booking no longer exists', function () {", 1305 | " pm.expect(err).to.equal(null);", 1306 | " pm.expect(res.code).to.eql(404);", 1307 | " });", 1308 | "});" 1309 | ], 1310 | "type": "text/javascript" 1311 | } 1312 | } 1313 | ], 1314 | "request": { 1315 | "auth": { 1316 | "type": "basic", 1317 | "basic": [ 1318 | { 1319 | "key": "password", 1320 | "value": "password123", 1321 | "type": "string" 1322 | }, 1323 | { 1324 | "key": "username", 1325 | "value": "admin", 1326 | "type": "string" 1327 | } 1328 | ] 1329 | }, 1330 | "method": "DELETE", 1331 | "header": [ 1332 | { 1333 | "key": "Content-Type", 1334 | "value": "application/json" 1335 | }, 1336 | { 1337 | "key": "Cookie", 1338 | "value": "token=abc123" 1339 | } 1340 | ], 1341 | "body": {}, 1342 | "url": { 1343 | "raw": "{{rb_url}}/booking/{{booking_id}}", 1344 | "host": [ 1345 | "{{rb_url}}" 1346 | ], 1347 | "path": [ 1348 | "booking", 1349 | "{{booking_id}}" 1350 | ] 1351 | } 1352 | }, 1353 | "response": [] 1354 | } 1355 | ], 1356 | "event": [ 1357 | { 1358 | "listen": "prerequest", 1359 | "script": { 1360 | "id": "858f0d4e-0d8a-4587-a962-f5d8f2446884", 1361 | "type": "text/javascript", 1362 | "exec": [ 1363 | "// top names of 1996", 1364 | "var firstNames = [\"Emily\",\"Michael\", \"Jessica\",\"Matthew\", \"Ashley\",", 1365 | "\"Jacob\",\"Sarah\",\"Christopher\",\"Samantha\",\"Joshua\",", 1366 | "\"Taylor\",\"Nicholas\",\"Hannah\",\"Tyler\",\"Alexis\",", 1367 | "\"Brandon\",\"Rachel\",\"Austin\",\"Elizabeth\",\"Andrew\"];", 1368 | "", 1369 | "// top surnames in the U.S.", 1370 | "var lastNames = [\"Smith\", \"Johnson\", \"Williams\", \"Jones\", \"Brown\", ", 1371 | "\"Davis\", \"Miller\", \"Wilson\", \"Moore\", \"Taylor\", ", 1372 | "\"Anderson\", \"Thomas\", \"Jackson\", \"White\", \"Harris\", ", 1373 | "\"Martin\", \"Thompson\", \"Garcia\", \"Martinez\", \"Robinson\"];", 1374 | "", 1375 | "// randomly select first and last names then add to collection variables", 1376 | "pm.variables.set(\"firstname\", firstNames[_.random(firstNames.length - 1)]);", 1377 | "pm.variables.set(\"lastname\", lastNames[_.random(lastNames.length - 1)]);", 1378 | "", 1379 | "// the random function comes from the loadash module (\"_.\")", 1380 | "// https://lodash.com/docs/4.17.11#random", 1381 | "pm.variables.set(\"totalprice\", _.random(50, 250));", 1382 | "pm.variables.set(\"depositpaid\", (_.random(1) === 1));", 1383 | "", 1384 | "// the moment module helps with date manipulation and formatting", 1385 | "const moment = require(\"moment\");", 1386 | "var checkin = moment().add(\"days\", _.random(1, 180));", 1387 | "pm.variables.set(\"checkin\", checkin.format(\"YYYY-MM-DD\"));", 1388 | "", 1389 | "var checkout = checkin.add(\"days\", _.random(1, 14));", 1390 | "pm.variables.set(\"checkout\", checkout.format(\"YYYY-MM-DD\"));", 1391 | "", 1392 | "var needs = [\"breakfast\", \"lunch\", \"early checkin\", \"late checkout\", null];", 1393 | "pm.variables.set(\"additionalneeds\", needs[_.random(needs.length-1)]);", 1394 | "", 1395 | "// put all the selected variables into a new booking object and save to a variable", 1396 | "var booking = {", 1397 | " \"firstname\" : pm.variables.get(\"firstname\"),", 1398 | " \"lastname\" : pm.variables.get(\"lastname\"),", 1399 | " \"totalprice\" : pm.variables.get(\"totalprice\"),", 1400 | " \"depositpaid\" : pm.variables.get(\"depositpaid\"),", 1401 | " \"bookingdates\" : {", 1402 | " \"checkin\" : pm.variables.get(\"checkin\"),", 1403 | " \"checkout\" : pm.variables.get(\"checkout\")", 1404 | " },", 1405 | " \"additionalneeds\" : pm.variables.get(\"additionalneeds\")", 1406 | "}", 1407 | "pm.variables.set(\"new_booking\", booking)" 1408 | ] 1409 | } 1410 | }, 1411 | { 1412 | "listen": "test", 1413 | "script": { 1414 | "id": "da1316f6-9655-441e-bd27-8abc3715f398", 1415 | "type": "text/javascript", 1416 | "exec": [ 1417 | "" 1418 | ] 1419 | } 1420 | } 1421 | ] 1422 | } 1423 | 1424 | 1425 | --------------------------------------------------------------------------------