diff --git a/.env.development b/.env.development index e611294..f7306e7 100644 --- a/.env.development +++ b/.env.development @@ -4,4 +4,3 @@ POSTGRES_USER = postgres POSTGRES_DB = postgres POSTGRES_PASSWORD = 12345 DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB - diff --git a/.github/workflows/linting.yaml b/.github/workflows/linting.yaml index ea3f6a3..f519a67 100644 --- a/.github/workflows/linting.yaml +++ b/.github/workflows/linting.yaml @@ -4,7 +4,15 @@ on: pull_request jobs: prettier: + name: Prettier + runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: "lts/hydrogen" + - run: npm ci - run: npm run lint:prettier:check diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..69b4242 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,3 @@ +module.exports = { + extends: ["@commitlint/config-conventional"], +}; diff --git a/infra/compose.yaml b/infra/compose.yaml index 12bcf9f..aecd776 100644 --- a/infra/compose.yaml +++ b/infra/compose.yaml @@ -5,4 +5,4 @@ services: env_file: - ../.env.development ports: - - "2345:5432" + - "5432:5432" diff --git a/infra/database.js b/infra/database.js index f3b6020..0acffe1 100644 --- a/infra/database.js +++ b/infra/database.js @@ -2,7 +2,6 @@ import { Client } from "pg"; async function query(queryObject) { let client; - try { client = await getNewClient(); const result = await client.query(queryObject); @@ -42,5 +41,6 @@ function getSSLValues() { ca: process.env.POSTGRES_CA, }; } + return process.env.NODE_ENV === "production" ? true : false; } diff --git a/infra/migrations/1755523095078_test-migration.js b/infra/migrations/1755523095078_test-migration.js index fbce4d4..d345e57 100644 --- a/infra/migrations/1755523095078_test-migration.js +++ b/infra/migrations/1755523095078_test-migration.js @@ -1,7 +1,8 @@ +/* eslint-disable no-unused-vars */ /* eslint-disable camelcase */ exports.shorthands = undefined; -exports.up = pgm => {}; +exports.up = (pgm) => {}; -exports.down = pgm => {}; +exports.down = (pgm) => {}; diff --git a/infra/scripts/wait-for-postgres.js b/infra/scripts/wait-for-postgres.js index eb53750..b82daca 100644 --- a/infra/scripts/wait-for-postgres.js +++ b/infra/scripts/wait-for-postgres.js @@ -10,9 +10,9 @@ function checkPostgres() { return; } - console.log("\nPostgres está pronto e aceitando conexões!\n"); + console.log("\n🟢 Postgres está pronto e aceitando conexões!\n"); } } -process.stdout.write("\n\nAguardando Postgres aceitar conexões"); +process.stdout.write("\n\n🔴 Aguardando Postgres aceitar conexões"); checkPostgres(); diff --git a/jest.config.js b/jest.config.js index 82d5f7b..b1af9ce 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,10 +8,9 @@ const nextJest = require("next/jest"); const createJestConfig = nextJest({ dir: ".", }); - const jestConfig = createJestConfig({ moduleDirectories: ["node_modules", ""], - testTimeout: 180000, + testTimeout: 60000, }); module.exports = jestConfig; diff --git a/package.json b/package.json index 1b3155d..6238674 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "lint:prettier:check": "prettier --check .", "lint:prettier:fix": "prettier --write .", "lint:eslint:check": "next lint --dir .", - "test": "npm run services:up && concurrently --names \"next,jest\" --hide \"next\" -k -s command-jest \"next dev\" \"jest --runInBand\"", + "test": "npm run services:up && concurrently -n next,jest --hide next -k -s command-jest \"next dev\" \"jest --runInBand --verbose\"", "test:watch": "jest --watchAll --runInBand", "migration:create": "node-pg-migrate -m infra/migrations create", "migration:up": "node-pg-migrate -m infra/migrations --envPath .env.development up", diff --git a/pages/api/v1/migrations/index.js b/pages/api/v1/migrations/index.js index 71d65cf..60bb65e 100644 --- a/pages/api/v1/migrations/index.js +++ b/pages/api/v1/migrations/index.js @@ -11,6 +11,7 @@ export default async function migrations(request, response) { } let dbClient; + try { dbClient = await database.getNewClient(); diff --git a/pages/api/v1/status/index.js b/pages/api/v1/status/index.js index 89e1989..c581f9f 100644 --- a/pages/api/v1/status/index.js +++ b/pages/api/v1/status/index.js @@ -1,7 +1,7 @@ -import database from "infra/database.js"; +import database from "infra/database"; async function status(request, response) { - const updatedAT = new Date().toISOString(); + const updatedAt = new Date().toISOString(); const databaseVersionResult = await database.query("SHOW server_version;"); const databaseVersionValue = databaseVersionResult.rows[0].server_version; @@ -14,14 +14,14 @@ async function status(request, response) { const databaseName = process.env.POSTGRES_DB; const databaseOpenedConnectionsResult = await database.query({ - text: "SELECT count(*)::int FROM pg_stat_activity WHERE datname = $1", + text: "SELECT count(*)::int FROM pg_stat_activity WHERE datname = $1;", values: [databaseName], }); const databaseOpenedConnectionsValue = - await databaseOpenedConnectionsResult.rows[0].count; + databaseOpenedConnectionsResult.rows[0].count; response.status(200).json({ - updated_at: updatedAT, + updated_at: updatedAt, dependencies: { database: { version: databaseVersionValue, diff --git a/tests/integration/api/v1/status/get.test.js b/tests/integration/api/v1/status/get.test.js index fe1d613..8f2c1a6 100644 --- a/tests/integration/api/v1/status/get.test.js +++ b/tests/integration/api/v1/status/get.test.js @@ -4,7 +4,7 @@ beforeAll(async () => { await orchestrator.waitForAllServices(); }); -test("Get to /api/v1/status should return 200", async () => { +test("GET to /api/v1/status should return 200", async () => { const response = await fetch("http://localhost:3000/api/v1/status"); expect(response.status).toBe(200); @@ -13,7 +13,7 @@ test("Get to /api/v1/status should return 200", async () => { const parsedUpdatedAt = new Date(responseBody.updated_at).toISOString(); expect(responseBody.updated_at).toEqual(parsedUpdatedAt); - expect(responseBody.dependencies.database.version).toEqual("17.2"); + expect(responseBody.dependencies.database.version).toEqual("16.0"); expect(responseBody.dependencies.database.max_connections).toEqual(100); expect(responseBody.dependencies.database.opened_connections).toEqual(1); });