From 87939ed02b4e00010ff5a34275685e62b61a60c4 Mon Sep 17 00:00:00 2001 From: braiancalot Date: Wed, 30 Oct 2024 20:01:36 -0300 Subject: [PATCH] refactor: use `orchestrator.cleanDatabase()` in tests --- tests/integration/api/v1/migrations/get.test.js | 3 +-- tests/integration/api/v1/migrations/post.test.js | 3 +-- tests/orchestrator.js | 6 ++++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/integration/api/v1/migrations/get.test.js b/tests/integration/api/v1/migrations/get.test.js index 1f3fc6b..3727e9c 100644 --- a/tests/integration/api/v1/migrations/get.test.js +++ b/tests/integration/api/v1/migrations/get.test.js @@ -1,9 +1,8 @@ -import database from "infra/database"; import orchestrator from "tests/orchestrator.js"; beforeAll(async () => { await orchestrator.waitForAllServices(); - await database.query("drop schema public cascade; create schema public;"); + await orchestrator.clearDatabase(); }); describe("GET /api/v1/migrations", () => { diff --git a/tests/integration/api/v1/migrations/post.test.js b/tests/integration/api/v1/migrations/post.test.js index ae7198e..74a3f67 100644 --- a/tests/integration/api/v1/migrations/post.test.js +++ b/tests/integration/api/v1/migrations/post.test.js @@ -1,9 +1,8 @@ -import database from "infra/database"; import orchestrator from "tests/orchestrator.js"; beforeAll(async () => { await orchestrator.waitForAllServices(); - await database.query("drop schema public cascade; create schema public;"); + await orchestrator.clearDatabase(); }); describe("POST /api/v1/migrations", () => { diff --git a/tests/orchestrator.js b/tests/orchestrator.js index a213854..f49d865 100644 --- a/tests/orchestrator.js +++ b/tests/orchestrator.js @@ -1,4 +1,5 @@ import retry from "async-retry"; +import database from "infra/database"; async function waitForAllServices() { await waitForWebServer(); @@ -16,8 +17,13 @@ async function waitForAllServices() { } } +async function clearDatabase() { + await database.query("drop schema public cascade; create schema public;"); +} + const orchestrator = { waitForAllServices, + clearDatabase, }; export default orchestrator;