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

fix: clear queues after finishing client tests #111

Merged
merged 3 commits into from
Jun 25, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:

env:
QSTASH_TOKEN: ${{ secrets.QSTASH_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
jobs:
local-tests:
runs-on: ubuntu-latest
Expand All @@ -22,7 +23,7 @@ jobs:
run: bun install

- name: Run tests
run: bun test --bail
run: bun test

- name: Build
run: bun run build
Expand Down
22 changes: 21 additions & 1 deletion src/client/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { afterAll, describe, expect, test } from "bun:test";
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { nanoid } from "nanoid";
import { Client } from "./client";

export const clearQueues = async (client: Client) => {
const queueDetails = await client.queue().list();
await Promise.all(
queueDetails.map(async (q) => {
await client.queue({ queueName: q.name }).delete();
})
);
};

describe("E2E Publish", () => {
const client = new Client({ token: process.env.QSTASH_TOKEN! });

afterAll(async () => {
await clearQueues(client);
});

beforeAll(async () => {
await clearQueues(client);
});

test("should publish a json message", async () => {
const result = await client.publishJSON({
url: "https://example.com/",
Expand Down Expand Up @@ -153,6 +170,7 @@ describe("E2E Queue", () => {

const verifiedMessage = await client.messages.get(queueDetails.messageId);
expect(verifiedMessage.queueName).toBe(queueName);
await client.queue({ queueName }).delete();
},
{ timeout: 35_000 }
);
Expand Down Expand Up @@ -180,6 +198,7 @@ describe("E2E Queue", () => {
queueName,
},
]);
await client.queue({ queueName }).delete();
},
{ timeout: 35_000 }
);
Expand Down Expand Up @@ -207,6 +226,7 @@ describe("E2E Queue", () => {
queueName,
},
]);
await client.queue({ queueName }).delete();
},
{ timeout: 35_000 }
);
Expand Down
17 changes: 10 additions & 7 deletions src/client/queue.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { afterAll, describe, expect, test } from "bun:test";
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { Client } from "./client";
import { clearQueues } from "./client.test";

describe("Queue", () => {
const client = new Client({ token: process.env.QSTASH_TOKEN! });

afterAll(async () => {
const queueDetails = await client.queue().list();
await Promise.all(
queueDetails.map(async (q) => {
await client.queue({ queueName: q.name }).delete();
})
);
await clearQueues(client);
});

beforeAll(async () => {
await clearQueues(client);
});

test("should create a queue, verify it then remove it", async () => {
Expand All @@ -23,6 +23,9 @@ describe("Queue", () => {
expect(queueDetails.name).toEqual(queueName);

await client.queue({ queueName }).delete();

const queues = await client.queue().list();
expect(queues.length).toBe(0);
});

test("should create multiple queue, verify them then remove them", async () => {
Expand Down