Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A collection to test a burger API, with some errors
{
"info": {
"_postman_id": "828b3a96-6f00-4b69-bb67-2751d7fceb0f",
"name": "Burgers",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Get All Burgers",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.collectionVariables.set('burgerCount',pm.response.json().length)"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/burgers",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"burgers"
]
}
},
"response": []
},
{
"name": "Create Burger",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"var burgerName = pm.variables.replaceIn('{{$randomWords}}')+\" Burger\";",
"pm.collectionVariables.set('burgerName',burgerName);"
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Successful POST request\", function () {",
" pm.response.to.have.status(201);",
"});",
"",
"pm.test(\"Burger name is correct\", function() {",
" console.log(pm.response.json().name)",
" pm.expect(pm.response.json().name).to.equal(pm.collectionVariables.get('burgername'));",
"})",
"",
"var burgerId=pm.response.json().id;",
"pm.collectionVariables.set('burgerId',burgerId);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"{{burgerName}}\",\n \"web\": \"{{$randomUrl}}\",\n \"description\": \"{{$randomPhrase}}\",\n \"ingredients\": [\n \"{{$randomNoun}}\",\n \"{{$randomNoun}}\",\n \"{{$randomNoun}}\"\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:3000/burgers/",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"burgers",
""
]
}
},
"response": []
},
{
"name": "Get All Burgers",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"Number of burgers has increased\", function() {",
" let originalBurgerCount=pm.collectionVariables.get('burgerCount')",
" let newBurgerCount=pm.response.json().length",
" pm.expect(newBurgerCount).to.equal(originalBurgerCount+1);",
"})",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/burgers",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"burgers"
]
}
},
"response": []
},
{
"name": "Get Burger",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"Burger Name is correct\", function() {",
" pm.expect(pm.response.json().name).to.equal(pm.collectionVariables.get('burgername'));",
"})",
"",
"var ingredients = pm.response.json().ingredients",
"pm.collectionVariables.set('ingredientOne',ingredients[0]);",
"pm.collectionVariables.set('ingredientTwo',ingredients[1]);",
"pm.collectionVariables.set('ingredientThree',ingredients[2]);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/burgers/{{burgerId}}",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"burgers",
"{{burgerId}}"
]
}
},
"response": []
},
{
"name": "Update Burger",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"pm.collectionVariables.set('newIngredient',pm.variables.replaceIn('{{$randomWord}}'));"
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"New ingredient has been added to burger\", function() {",
" pm.expect(pm.response.json().ingredients[4]).to.equal(pm.collectionVariables.get('newIngredient'));",
"})"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PATCH",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"ingredients\": [\n \"{{ingredientOne}}\",\n \"{{ingredientTwo}}\",\n \"{{ingredientThree}}\",\n \"{{newIngredient}}\"\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:3000/burgers/{{burgerId}}",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"burgers",
"{{burgerId}}"
]
}
},
"response": []
},
{
"name": "Delete Burger",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 204\", function () {",
" pm.response.to.have.status(204);",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "DELETE",
"header": [],
"url": {
"raw": "http://localhost:3000/burgers/{{burgerId}}",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"burgers",
"{{burgerId}}"
]
}
},
"response": []
},
{
"name": "Get Burger",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 404\", function () {",
" pm.response.to.have.status(404);",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/burgers/{{burgerId}}",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"burgers",
"{{burgerId}}"
]
}
},
"response": []
},
{
"name": "Get All Burgers",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"burgers = pm.response.json()",
"",
"pm.test(\"Number of burgers has decreased\", function() {",
" let originalBurgerCount=pm.collectionVariables.get('burgerCount')",
" let newBurgerCount=pm.response.json().length",
" pm.expect(newBurgerCount).to.equal(originalBurgerCount-1)",
"})",
"",
"pm.test(\"Burger should not exist\", function() {",
" var myBurgers = burgers.filter(burger=>burger.name==pm.collectionVariables.get('burgername'));",
" pm.expect(myBurgers.length).to.equal(0);",
"})"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/burgers",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"burgers"
]
}
},
"response": []
}
],
"variable": [
{
"key": "burgerCount",
"value": ""
},
{
"key": "burgerName",
"value": ""
},
{
"key": "burgerId",
"value": ""
},
{
"key": "ingredients",
"value": ""
},
{
"key": "ingredientOne",
"value": ""
},
{
"key": "ingredientTwo",
"value": ""
},
{
"key": "ingredientThree",
"value": ""
},
{
"key": "newIngredient",
"value": ""
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment