Skip to content

Commit

Permalink
refactor: use orchestrator.clearDatabase() in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlAnNuB authored Sep 13, 2024
1 parent 780b2a3 commit 516f08d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
3 changes: 1 addition & 2 deletions tests/integration/api/v1/migrations/get.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import database from "infra/database.js";
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", () => {
Expand Down
22 changes: 13 additions & 9 deletions tests/integration/api/v1/migrations/post.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import database from "infra/database.js";
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", () => {
describe("Anonymous user", () => {
describe("Running pending migrations", () => {
test("For the first time", async () => {
const response1 = await fetch("http://localhost:3000/api/v1/migrations", {
method: "POST",
});
const response1 = await fetch(
"http://localhost:3000/api/v1/migrations",
{
method: "POST",
},
);
expect(response1.status).toBe(201);

const response1Body = await response1.json();
Expand All @@ -21,9 +23,12 @@ describe("POST /api/v1/migrations", () => {
expect(response1Body.length).toBeGreaterThan(0);
});
test("For the second time", async () => {
const response2 = await fetch("http://localhost:3000/api/v1/migrations", {
method: "POST",
});
const response2 = await fetch(
"http://localhost:3000/api/v1/migrations",
{
method: "POST",
},
);
expect(response2.status).toBe(200);

const response2Body = await response2.json();
Expand All @@ -34,4 +39,3 @@ describe("POST /api/v1/migrations", () => {
});
});
});

6 changes: 6 additions & 0 deletions tests/orchestrator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import retry from "async-retry";
import database from "infra/database.js";

async function waitForAllServices() {
await waitForWebServer();
Expand All @@ -18,7 +19,12 @@ async function waitForAllServices() {
}
}

async function clearDatabase() {
await database.query("DROP SCHEMA public CASCADE; CREATE SCHEMA public;");
}

const orchestrator = {
waitForAllServices,
clearDatabase,
};
export default orchestrator;

0 comments on commit 516f08d

Please sign in to comment.