diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 9fd74f2..e02b844 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -25,4 +25,9 @@ jobs: cache: 'npm' - run: npm install - run: npm test + - run: docker compose -f docker-compose.dev.yaml up -d + - run: sleep 3 + - run: npm run start-itest & + - run: npm install -g newman + - run: newman run cities.postman_collection.json \ No newline at end of file diff --git a/cities.postman_collection.json b/cities.postman_collection.json index bdfae01..0abb6fd 100644 --- a/cities.postman_collection.json +++ b/cities.postman_collection.json @@ -1,126 +1,285 @@ { - "info": { - "_postman_id": "def0ceb3-9597-4f31-bc0f-54f466157759", - "name": "cities", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", - "_exporter_id": "3720353" - }, - "item": [ - { - "name": "cities", - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "http://localhost:8080/cities", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "8080", - "path": [ - "cities" - ] - } - }, - "response": [] - }, - { - "name": "cities/:city", - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "http://localhost:8080/cities/Zaragoza", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "8080", - "path": [ - "cities", - "Zaragoza" - ] - } - }, - "response": [] - }, - { - "name": "cities/:city", - "request": { - "method": "DELETE", - "header": [], - "url": { - "raw": "http://localhost:8080/cities/Zaragoza", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "8080", - "path": [ - "cities", - "Zaragoza" - ] - } - }, - "response": [] - }, - { - "name": "cities", - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"Zaragoza\",\n \"altitude\": 1000,\n \"population\": 1000,\n \"capital\": true\n}", - "options": { - "raw": { - "language": "json" - } - } - }, - "url": { - "raw": "http://localhost:8080/cities", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "8080", - "path": [ - "cities" - ] - } - }, - "response": [] - }, - { - "name": "cities/:city", - "request": { - "method": "PUT", - "header": [], - "body": { - "mode": "raw", - "raw": "{\n \"altitude\": 800,\n \"population\": 102200,\n \"capital\": true\n}", - "options": { - "raw": { - "language": "json" - } - } - }, - "url": { - "raw": "http://localhost:8080/cities/Huesca", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "8080", - "path": [ - "cities", - "Huesca" - ] - } - }, - "response": [] - } - ] + "info": { + "_postman_id": "345cd8e8-b78f-4d18-ba0a-ffdc20aa9a71", + "name": "cities v2", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "3720353" + }, + "item": [ + { + "name": "cities OK", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 201\", function () {\r", + " pm.response.to.have.status(201);\r", + "});" + ], + "type": "text/javascript", + "packages": {}, + "requests": {} + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Zaragohghza\",\n \"altitude\": 1000,\n \"population\": 1000,\n \"capital\": true\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8080/cities", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "cities" + ] + } + }, + "response": [] + }, + { + "name": "cities bad-request", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {\r", + " pm.response.to.have.status(400);\r", + "});" + ], + "type": "text/javascript", + "packages": {}, + "requests": {} + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"altitude\": 1000,\n \"population\": 1000,\n \"capital\": true\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8080/cities", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "cities" + ] + } + }, + "response": [] + }, + { + "name": "cities", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {\r", + " pm.response.to.have.status(200);\r", + "});" + ], + "type": "text/javascript", + "packages": {}, + "requests": {} + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:8080/cities", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "cities" + ] + } + }, + "response": [] + }, + { + "name": "cities/:city", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {\r", + " pm.response.to.have.status(200);\r", + "});\r", + "\r", + "pm.test('Response structure is ok', () => {\r", + " pm.expect(pm.response.json()).to.have.property('id');\r", + " pm.expect(pm.response.json()).to.have.property('name');\r", + " pm.expect(pm.response.json()).to.have.property('population');\r", + "});" + ], + "type": "text/javascript", + "packages": {}, + "requests": {} + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:8080/cities/2", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "cities", + "2" + ] + } + }, + "response": [] + }, + { + "name": "cities/:city 404", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {\r", + " pm.response.to.have.status(404);\r", + "});" + ], + "type": "text/javascript", + "packages": {}, + "requests": {} + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:8080/cities/10", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "cities", + "10" + ] + } + }, + "response": [] + }, + { + "name": "cities/:city", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {\r", + " pm.response.to.have.status(200);\r", + "});" + ], + "type": "text/javascript", + "packages": {}, + "requests": {} + } + } + ], + "request": { + "method": "PUT", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"altitude\": 800,\n \"population\": 102200,\n \"capital\": true\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8080/cities/55", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "cities", + "55" + ] + } + }, + "response": [] + }, + { + "name": "cities/:city", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 204\", function () {\r", + " pm.response.to.have.status(204);\r", + "});" + ], + "type": "text/javascript", + "packages": {}, + "requests": {} + } + } + ], + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "http://localhost:8080/cities/12", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "cities", + "12" + ] + } + }, + "response": [] + } + ] } \ No newline at end of file diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index 550e0c4..1b36ce4 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -4,11 +4,11 @@ services: image: mariadb:11.3.2 container_name: cities-dev-db environment: - MYSQL_USER: $MARIADB_USER - MYSQL_PASSWORD: $MARIADB_PASSWORD - MYSQL_DATABASE: $MARIADB_DATABASE + MYSQL_USER: user + MYSQL_PASSWORD: password + MYSQL_DATABASE: cities MYSQL_PORT: 3306 - MYSQL_ROOT_PASSWORD: $MARIADB_ROOT_PASSWORD + MYSQL_ROOT_PASSWORD: password ports: - "3306:3306" volumes: diff --git a/package.json b/package.json index fb1cb20..4a795ad 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "cities-backend", "scripts": { "start": "node src/app.js --config config.local.yaml", + "start-itest": "node src/app.js --config config.sample.yaml", "test": "jest src/test/unit" }, "dependencies": {