diff --git a/package-lock.json b/package-lock.json index fe4d902..4feea63 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "helmet": "^7.1.0", "jsonwebtoken": "^9.0.2", "mongoose": "^8.0.3", + "morgan": "^1.10.0", "pg": "^8.15.6", "winston": "^3.17.0" }, @@ -2949,6 +2950,24 @@ "license": "Apache-2.0", "optional": true }, + "node_modules/basic-auth": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", + "integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.1.2" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/basic-auth/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT" + }, "node_modules/bcrypt": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/bcrypt/-/bcrypt-5.1.1.tgz", @@ -7711,6 +7730,49 @@ "url": "https://opencollective.com/mongoose" } }, + "node_modules/morgan": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz", + "integrity": "sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ==", + "license": "MIT", + "dependencies": { + "basic-auth": "~2.0.1", + "debug": "2.6.9", + "depd": "~2.0.0", + "on-finished": "~2.3.0", + "on-headers": "~1.0.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/morgan/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/morgan/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT" + }, + "node_modules/morgan/node_modules/on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/mpath": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", diff --git a/package.json b/package.json index 13524ef..a6ce4f7 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "helmet": "^7.1.0", "jsonwebtoken": "^9.0.2", "mongoose": "^8.0.3", + "morgan": "^1.10.0", "pg": "^8.15.6", "winston": "^3.17.0" }, diff --git a/src/__tests__/integration.test.ts b/src/__tests__/integration.test.ts new file mode 100644 index 0000000..a4ba974 --- /dev/null +++ b/src/__tests__/integration.test.ts @@ -0,0 +1,25 @@ +import request from 'supertest'; +import { app } from '../boot/setup'; + +describe('Integration Tests', () => { + it('GET /health should return 200 OK', async () => { + const response = await request(app).get('/health'); + expect(response.status).toBe(200); + expect(response.body).toHaveProperty('status', 'ok'); + }); + + it('GET /users (unauthenticated) should return 200 OK', async () => { + const response = await request(app).get('/users'); + expect(response.status).toBe(200); + }); + + it('GET /messages without token should return 401', async () => { + const response = await request(app).get('/messages'); + expect(response.status).toBe(401); + }); + + it('GET /unknown-route should return 404', async () => { + const response = await request(app).get('/nonexistent'); + expect(response.status).toBe(404); + }); +}); diff --git a/src/boot/setup.ts b/src/boot/setup.ts index 0352a60..9b1c260 100644 --- a/src/boot/setup.ts +++ b/src/boot/setup.ts @@ -113,4 +113,4 @@ const startApp = (): void => { } }; -export { startApp }; \ No newline at end of file +export { startApp, app }; diff --git a/tsconfig.json b/tsconfig.json index 4a4f7e5..2d673a0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,7 +25,7 @@ "ts-node": { "files": true }, - "exclude": ["node_modules", "dist", "src/__tests__/**/*"], - "include": ["src/**/*.ts"], + "exclude": ["node_modules"], + "include": ["src/**/*.ts", "src/__tests__/**/*"], "files": ["src/types/express.d.ts"] }