Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adiciona Github Actions para rodar os testes #75

Closed
wants to merge 6 commits into from
Closed
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
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["next/babel"]
}
5 changes: 5 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
POSTGRES_USER=local
POSTGRES_PASSWORD=local
POSTGRES_DB=tabnews
POSTGRES_HOST=localhost
POSTGRES_PORT=54321
14 changes: 14 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Tests

on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "14"
- run: npm ci
- run: npm test
2 changes: 1 addition & 1 deletion docker-compose.development.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.8"
version: "2.4"
services:
postgres:
container_name: "postgres"
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "2.4"
services:
postgres_test:
container_name: "postgres-test"
image: "postgres:13.3-alpine"
env_file:
- .env.test
ports:
- "54321:5432"
15 changes: 13 additions & 2 deletions models/migrator.js → infra/migrator.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
import databaseFactory from "infra/database.js";
import migrationRunner from "node-pg-migrate";

export default function Migrator(options = {}) {
export default function Migrator() {
const defaultConfigurations = {
dbClient: options.databaseClient,
dir: "./infra/migrations",
direction: "up",
migrationsTable: "migrations",
verbose: true,
};

async function listPendingMigrations() {
const database = databaseFactory();
const databaseClient = await database.getNewConnectionClient();
const pendingMigrations = await migrationRunner({
...defaultConfigurations,
dbClient: databaseClient,
dryRun: true,
});

await databaseClient.end();

return pendingMigrations;
}

async function runPendingMigrations() {
const database = databaseFactory();
const databaseClient = await database.getNewConnectionClient();

const migratedMigrations = await migrationRunner({
...defaultConfigurations,
dbClient: databaseClient,
dryRun: false,
});

await databaseClient.end();

return migratedMigrations;
}

Expand Down
Loading