Skip to content

Instantly share code, notes, and snippets.

@vojtech-cerveny
Created May 2, 2023 14:10
Show Gist options
  • Save vojtech-cerveny/328e859c784f68d213c05d8a0efec423 to your computer and use it in GitHub Desktop.
Save vojtech-cerveny/328e859c784f68d213c05d8a0efec423 to your computer and use it in GitHub Desktop.
Czechitas collection
{
"info": {
"_postman_id": "dcab6bbd-a770-48b7-980a-a3f2ded1ef31",
"name": "DATOJ23 API tests",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "2294419",
"_collection_link": "https://web.postman.co/workspace/e9052594-972b-45e0-b6b0-7e7aff2f415f/collection/2294419-dcab6bbd-a770-48b7-980a-a3f2ded1ef31?action=share&creator=2294419&source=collection_link"
},
"item": [
{
"name": "Register parent",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// Test the response status code",
"pm.test(\"Status code is 201\", function () {",
" pm.response.to.have.status(201);",
"});",
"",
"// Test the response body",
"pm.test(\"Response body has required properties\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check if the required properties exist",
" pm.expect(jsonData).to.have.property(\"name\");",
" pm.expect(jsonData).to.have.property(\"email\");",
" pm.expect(jsonData).to.have.property(\"role\");",
" pm.expect(jsonData).to.have.property(\"updated_at\");",
" pm.expect(jsonData).to.have.property(\"created_at\");",
" pm.expect(jsonData).to.have.property(\"id\");",
" pm.expect(jsonData).to.have.property(\"access_token\");",
"});",
"",
"// Test the data type of the response properties",
"pm.test(\"Response property data types are correct\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check the data types of the response properties",
" pm.expect(jsonData.name).to.be.a(\"string\");",
" pm.expect(jsonData.email).to.be.a(\"string\");",
" pm.expect(jsonData.role).to.be.eq(\"parent\");",
" pm.expect(jsonData.id).to.be.a(\"number\");",
" pm.expect(jsonData.access_token).to.be.a(\"string\");",
"",
" // Check if the updated_at property is in ISO datetime format",
" pm.expect(new Date(jsonData.updated_at)).to.not.be.NaN;",
" pm.expect(new Date(jsonData.updated_at)).to.be.an.instanceof(Date);",
"",
" // Check if the created_at property is in ISO datetime format",
" pm.expect(new Date(jsonData.created_at)).to.not.be.NaN;",
" pm.expect(new Date(jsonData.created_at)).to.be.an.instanceof(Date);",
"",
" // Save the access token value to a Postman variable",
" pm.environment.set(\"access_token\", jsonData.access_token);",
" // Save others",
" pm.environment.set(\"parent_user_id\", jsonData.id);",
" pm.environment.set(\"parent_name\", jsonData.name);",
" pm.environment.set(\"parent_email\", jsonData.email);",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"{{$randomFullName}}\",\n \"email\": \"automation+{{$timestamp}}@gmail.com\",\n \"password\": \"Czechitas123\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/users/register",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"users",
"register"
]
}
},
"response": []
},
{
"name": "Register parent - Already used email",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// Test the response status code",
"pm.test(\"Status code is 422\", function () {",
" pm.response.to.have.status(422);",
"});",
"",
"// Test the response body",
"pm.test(\"Response body has required properties and correct data types\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check if the required properties exist",
" pm.expect(jsonData).to.have.property(\"message\");",
" pm.expect(jsonData).to.have.property(\"errors\");",
"",
" // Check the data types of the response properties",
" pm.expect(jsonData.message).to.be.eq(\"The email has already been taken.\");",
" pm.expect(jsonData.errors).to.be.an(\"object\");",
"",
" // Check if the errors object has the expected properties",
" pm.expect(jsonData.errors).to.have.property(\"email\");",
" pm.expect(jsonData.errors.email).to.be.an(\"array\");",
" pm.expect(jsonData.errors.email).to.have.length(1);",
" pm.expect(jsonData.errors.email[0]).to.be.eq(\"The email has already been taken.\");",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"{{$randomFullName}}\",\n \"email\": \"{{parent_email}}\",\n \"password\": \"Czechitas123\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/users/register",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"users",
"register"
]
}
},
"response": []
},
{
"name": "Register parent - Empty name",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// Test the response status code",
"pm.test(\"Status code is 422\", function () {",
" pm.response.to.have.status(422);",
"});",
"",
"// Test the response body",
"pm.test(\"Response body has required properties and correct data types\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check if the required properties exist",
" pm.expect(jsonData).to.have.property(\"message\");",
" pm.expect(jsonData).to.have.property(\"errors\");",
"",
" // Check the data types of the response properties",
" pm.expect(jsonData.message).to.be.eq(\"The name field is required.\");",
" pm.expect(jsonData.errors).to.be.an(\"object\");",
"",
" // Check if the errors object has the expected properties",
" pm.expect(jsonData.errors).to.have.property(\"name\");",
" pm.expect(jsonData.errors.name).to.be.an(\"array\");",
" pm.expect(jsonData.errors.name).to.have.length(1);",
" pm.expect(jsonData.errors.name[0]).to.be.eq(\"The name field is required.\");",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"\",\n \"email\": \"automation+{{$timestamp}}@gmail.com\",\n \"password\": \"Czechitas123\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/users/register",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"users",
"register"
]
}
},
"response": []
},
{
"name": "Register parent - Invalid email and password",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// Test the response status code",
"pm.test(\"Status code is 422\", function () {",
" pm.response.to.have.status(422);",
"});",
"",
"// Test the response body",
"pm.test(\"Response body has required properties and correct data types\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check if the required properties exist",
" pm.expect(jsonData).to.have.property(\"message\");",
" pm.expect(jsonData).to.have.property(\"errors\");",
"",
" // Check the data types of the response properties",
" pm.expect(jsonData.message).to.be.eq(\"The email must be a valid email address. (and 3 more errors)\");",
" pm.expect(jsonData.errors).to.be.an(\"object\");",
"",
" // Check if the errors object has the expected properties - email",
" pm.expect(jsonData.errors).to.have.property(\"email\");",
" pm.expect(jsonData.errors.email).to.be.an(\"array\");",
" pm.expect(jsonData.errors.email).to.have.length(1);",
" pm.expect(jsonData.errors.email[0]).to.be.eq(\"The email must be a valid email address.\");",
"",
" // Check if the errors object has the expected properties - password",
" pm.expect(jsonData.errors).to.have.property(\"password\");",
" pm.expect(jsonData.errors.password).to.be.an(\"array\");",
" pm.expect(jsonData.errors.password).to.have.length(3);",
" pm.expect(jsonData.errors.password[0]).to.be.eq(\"The password must be at least 6 characters.\");",
" pm.expect(jsonData.errors.password[1]).to.be.eq(\"The password field must contain at least one uppercase and one lowercase letter.\");",
" pm.expect(jsonData.errors.password[2]).to.be.eq(\"The password field must contain at least one number.\");",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"{{$randomFullName}}\",\n \"email\": \"{{$randomFullName}}\",\n \"password\": \"abc\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/users/register",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"users",
"register"
]
}
},
"response": []
},
{
"name": "Get current user info",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// Test the response status code",
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"// Test the response body",
"pm.test(\"Response body has required properties\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check if the required properties exist",
" pm.expect(jsonData).to.have.property(\"id\");",
" pm.expect(jsonData).to.have.property(\"name\");",
" pm.expect(jsonData).to.have.property(\"email\");",
" pm.expect(jsonData).to.have.property(\"is_blocked\");",
" pm.expect(jsonData).to.have.property(\"role\");",
" pm.expect(jsonData).to.have.property(\"updated_at\");",
" pm.expect(jsonData).to.have.property(\"created_at\");",
"});",
"",
"// Test the data type of the response properties",
"pm.test(\"Response property data types are correct\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check the data types of the response properties",
" pm.expect(jsonData.id).to.be.eq(pm.environment.get(\"parent_user_id\"));",
" pm.expect(jsonData.name).to.be.eq(pm.environment.get(\"parent_name\"));",
" pm.expect(jsonData.email).to.be.eq(pm.environment.get(\"parent_email\"))",
" pm.expect(jsonData.role).to.be.eq(\"parent\");",
" pm.expect(jsonData.is_blocked).to.be.eq(false);",
"",
" // Check if the updated_at property is in ISO datetime format",
" pm.expect(new Date(jsonData.updated_at)).to.not.be.NaN;",
" pm.expect(new Date(jsonData.updated_at)).to.be.an.instanceof(Date);",
"",
" // Check if the created_at property is in ISO datetime format",
" pm.expect(new Date(jsonData.created_at)).to.not.be.NaN;",
" pm.expect(new Date(jsonData.created_at)).to.be.an.instanceof(Date);",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{access_token}}",
"type": "string"
}
]
},
"method": "GET",
"header": [],
"url": {
"raw": "{{baseUrl}}/api/users/current",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"users",
"current"
]
}
},
"response": []
},
{
"name": "List all terms",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// Test the response status code",
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"// Test the response body",
"pm.test(\"Response body has required properties and correct data types\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check that the response is an array",
" pm.expect(jsonData).to.be.an(\"array\");",
" pm.expect(jsonData).to.have.length.gte(0);",
"",
" pm.environment.set(\"first_term_id\", jsonData[0].id);",
" pm.environment.set(\"first_category_id\", jsonData[0].category_id);",
"",
" // Loop through the array to check each object",
" jsonData.forEach(function(obj) {",
" // Check if the required properties exist",
" pm.expect(obj).to.have.property(\"id\");",
" pm.expect(obj).to.have.property(\"category_id\");",
" pm.expect(obj).to.have.property(\"start\");",
" pm.expect(obj).to.have.property(\"end\");",
" pm.expect(obj).to.have.property(\"price\");",
"",
" // Check the data types of the response properties",
" pm.expect(obj.id).to.be.a(\"number\");",
" pm.expect(obj.category_id).to.be.a(\"number\");",
" pm.expect(obj.start).to.be.a(\"string\");",
" pm.expect(obj.end).to.be.a(\"string\");",
" pm.expect(obj.price).to.be.a(\"number\");",
"",
" // Check if the start property is in ISO datetime format",
" pm.expect(new Date(obj.start)).to.not.be.NaN;",
" pm.expect(new Date(obj.start)).to.be.an.instanceof(Date);",
"",
" // Check if the end property is in ISO datetime format",
" pm.expect(new Date(obj.end)).to.not.be.NaN;",
" pm.expect(new Date(obj.end)).to.be.an.instanceof(Date);",
" });",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{access_token}}",
"type": "string"
}
]
},
"method": "GET",
"header": [],
"url": {
"raw": "{{baseUrl}}/api/terms",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"terms"
]
}
},
"response": []
},
{
"name": "Create term - expect unauthorized error",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"moment = require(\"moment\")",
"",
"let start = moment().startOf(\"isoWeek\").add(1, \"week\");",
"",
"pm.environment.set(\"next_week_monday\", start.format(\"YYYY-MM-DD\"));",
"pm.environment.set(\"next_week_friday\", start.add(4, \"day\").format(\"YYYY-MM-DD\"));"
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"// Test the response status code",
"pm.test(\"Status code is 403\", function () {",
" pm.response.to.have.status(403);",
"});",
"",
"// Test the response body",
"pm.test(\"Response body has required properties\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check if the required properties exist",
" pm.expect(jsonData).to.have.property(\"message\");",
"});",
"",
"// Test the data type of the response properties",
"pm.test(\"Response property data types are correct\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check the data types of the response properties",
" pm.expect(jsonData.message).to.be.eq(\"This action is unauthorized.\");",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{access_token}}",
"type": "string"
}
]
},
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"category_id\": {{first_category_id}},\n \"start\": \"{{next_week_monday}}\",\n \"end\": \"{{next_week_friday}}\",\n \"price\": 1800\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/terms",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"terms"
]
}
},
"response": []
},
{
"name": "Update term - expect unauthorized error",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"// Test the response status code",
"pm.test(\"Status code is 403\", function () {",
" pm.response.to.have.status(403);",
"});",
"",
"// Test the response body",
"pm.test(\"Response body has required properties\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check if the required properties exist",
" pm.expect(jsonData).to.have.property(\"message\");",
"});",
"",
"// Test the data type of the response properties",
"pm.test(\"Response property data types are correct\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check the data types of the response properties",
" pm.expect(jsonData.message).to.be.eq(\"This action is unauthorized.\");",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{access_token}}",
"type": "string"
}
]
},
"method": "PUT",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"category_id\": {{first_category_id}},\n \"start\": \"{{next_week_monday}}\",\n \"end\": \"{{next_week_friday}}\",\n \"price\": 1800\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/terms/{{first_term_id}}",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"terms",
"{{first_term_id}}"
]
}
},
"response": []
},
{
"name": "Delete term - expect unauthorized error",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"// Test the response status code",
"pm.test(\"Status code is 403\", function () {",
" pm.response.to.have.status(403);",
"});",
"",
"// Test the response body",
"pm.test(\"Response body has required properties\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check if the required properties exist",
" pm.expect(jsonData).to.have.property(\"message\");",
"});",
"",
"// Test the data type of the response properties",
"pm.test(\"Response property data types are correct\", function () {",
" // Parse the response body as JSON",
" var jsonData = pm.response.json();",
"",
" // Check the data types of the response properties",
" pm.expect(jsonData.message).to.be.eq(\"This action is unauthorized.\");",
"});",
""
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{access_token}}",
"type": "string"
}
]
},
"method": "DELETE",
"header": [],
"url": {
"raw": "{{baseUrl}}/api/terms/{{first_term_id}}",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"terms",
"{{first_term_id}}"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "baseUrl",
"value": "https://datoj23.herokuapp.com",
"type": "string"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment