Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -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

8 changes: 8 additions & 0 deletions .github/workflows/linting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ["@commitlint/config-conventional"],
};
2 changes: 1 addition & 1 deletion infra/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ services:
env_file:
- ../.env.development
ports:
- "2345:5432"
- "5432:5432"
2 changes: 1 addition & 1 deletion infra/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Client } from "pg";

async function query(queryObject) {
let client;

try {
client = await getNewClient();
const result = await client.query(queryObject);
Expand Down Expand Up @@ -42,5 +41,6 @@ function getSSLValues() {
ca: process.env.POSTGRES_CA,
};
}

return process.env.NODE_ENV === "production" ? true : false;
}
5 changes: 3 additions & 2 deletions infra/migrations/1755523095078_test-migration.js
Original file line number Diff line number Diff line change
@@ -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) => {};
4 changes: 2 additions & 2 deletions infra/scripts/wait-for-postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ const nextJest = require("next/jest");
const createJestConfig = nextJest({
dir: ".",
});

const jestConfig = createJestConfig({
moduleDirectories: ["node_modules", "<rootDir>"],
testTimeout: 180000,
testTimeout: 60000,
});

module.exports = jestConfig;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions pages/api/v1/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default async function migrations(request, response) {
}

let dbClient;

try {
dbClient = await database.getNewClient();

Expand Down
10 changes: 5 additions & 5 deletions pages/api/v1/status/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/api/v1/status/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
});