diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index cb1f7ca..15130b5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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 @@ -22,7 +23,7 @@ jobs: run: bun install - name: Run tests - run: bun test --bail + run: bun test - name: Build run: bun run build diff --git a/src/client/client.test.ts b/src/client/client.test.ts index 3b3777c..04e1812 100644 --- a/src/client/client.test.ts +++ b/src/client/client.test.ts @@ -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/", @@ -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 } ); @@ -180,6 +198,7 @@ describe("E2E Queue", () => { queueName, }, ]); + await client.queue({ queueName }).delete(); }, { timeout: 35_000 } ); @@ -207,6 +226,7 @@ describe("E2E Queue", () => { queueName, }, ]); + await client.queue({ queueName }).delete(); }, { timeout: 35_000 } ); diff --git a/src/client/queue.test.ts b/src/client/queue.test.ts index cd91cfb..9cabb0b 100644 --- a/src/client/queue.test.ts +++ b/src/client/queue.test.ts @@ -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 () => { @@ -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 () => {