From 85e70a567bbea7c031f828f0047674d192d74156 Mon Sep 17 00:00:00 2001 From: "DESKTOP-481791G\\S2-PC00" Date: Tue, 19 May 2026 20:16:02 +0200 Subject: [PATCH 1/4] Tests de integracion: coleccion y workflow actualizado --- .github/workflows/node.js.yml | 5 + cities.postman_collection.json | 323 ++++++++++++++++++++------------- 2 files changed, 204 insertions(+), 124 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 9fd74f2..a4a9343 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 start + - 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..95c55fe 100644 --- a/cities.postman_collection.json +++ b/cities.postman_collection.json @@ -1,126 +1,201 @@ { - "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", + "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", + "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", + "});" + ], + "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", + "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 From cb3ce8473641cbde35c3b755c8d5c5678f09d838 Mon Sep 17 00:00:00 2001 From: "DESKTOP-481791G\\S2-PC00" Date: Tue, 19 May 2026 20:24:04 +0200 Subject: [PATCH 2/4] Configurado entorno para lanzar los tests de integracion --- .github/workflows/node.js.yml | 2 +- docker-compose.dev.yaml | 8 ++++---- package.json | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index a4a9343..b4179a5 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -27,7 +27,7 @@ jobs: - run: npm test - run: docker compose -f docker-compose.dev.yaml up -d - run: sleep 3 - - run: npm start + - 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/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": { From 87aa317cb5a75a946161be4760fe39b3bb087edd Mon Sep 17 00:00:00 2001 From: "DESKTOP-481791G\\S2-PC00" Date: Tue, 19 May 2026 20:28:36 +0200 Subject: [PATCH 3/4] lanza comando en segundo plano --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index b4179a5..e02b844 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -27,7 +27,7 @@ jobs: - run: npm test - run: docker compose -f docker-compose.dev.yaml up -d - run: sleep 3 - - run: npm run start-itest + - run: npm run start-itest & - run: npm install -g newman - run: newman run cities.postman_collection.json \ No newline at end of file From 96ff46aa2f597abe3791aa129b711270424ef203 Mon Sep 17 00:00:00 2001 From: "DESKTOP-481791G\\S2-PC00" Date: Tue, 19 May 2026 21:00:30 +0200 Subject: [PATCH 4/4] actualizada coleccion --- cities.postman_collection.json | 86 +++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/cities.postman_collection.json b/cities.postman_collection.json index 95c55fe..0abb6fd 100644 --- a/cities.postman_collection.json +++ b/cities.postman_collection.json @@ -7,7 +7,7 @@ }, "item": [ { - "name": "cities", + "name": "cities OK", "event": [ { "listen": "test", @@ -49,6 +49,49 @@ }, "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": [ @@ -92,6 +135,12 @@ "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", @@ -118,6 +167,41 @@ }, "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": [