Skip to content

Commit

Permalink
Merge pull request #111 from upstash/hotfix-clear-queues-in-client-tests
Browse files Browse the repository at this point in the history
fix: clear queues after finishing client tests
  • Loading branch information
CahidArda authored Jun 25, 2024
2 parents 659e142 + d16c48a commit 7d00265
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
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

0 comments on commit 7d00265

Please sign in to comment.