From 25e42d9ebd5b5f5b3783219c911aba9cd9934bd3 Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Thu, 23 Nov 2023 15:27:37 +0100 Subject: [PATCH] Add cleanup GH job --- .github/workflows/cleanup.yml | 32 ++++++++++++++++++++++++++++++++ __tests__/messages.test.ts | 6 +++++- test-cleanup.js | 4 +++- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/cleanup.yml diff --git a/.github/workflows/cleanup.yml b/.github/workflows/cleanup.yml new file mode 100644 index 0000000..fee897b --- /dev/null +++ b/.github/workflows/cleanup.yml @@ -0,0 +1,32 @@ +name: Cleanup after tests +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + STREAM_API_KEY: ${{ vars.TEST_API_KEY }} + STREAM_SECRET: ${{ secrets.TEST_SECRET }} + +# Runs midnight at every Sunday https://crontab.guru/weekly +on: + schedule: + - cron: "0 0 * * 0" + +cleanup: + runs-on: ubuntu-latest + concurrency: + group: test-workflow + cancel-in-progress: true + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 20 + cache: "yarn" + + - name: Install Dependencies + run: yarn install --immutable + - name: Build + run: yarn build + - name: Cleanup + run: node test-cleanup.js diff --git a/__tests__/messages.test.ts b/__tests__/messages.test.ts index 3029698..6c27073 100644 --- a/__tests__/messages.test.ts +++ b/__tests__/messages.test.ts @@ -1,5 +1,5 @@ import 'dotenv/config'; -import { beforeAll, describe, expect, it } from 'vitest'; +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; import { createTestClient } from './create-test-client'; import { StreamChannel } from '../src/StreamChannel'; import { StreamClient } from '../src/StreamClient'; @@ -188,4 +188,8 @@ describe('messages API', () => { `Stream error code 4: GetMessage failed with error: "Message with id ${messageId} doesn't exist"`, ); }); + + afterAll(async () => { + await channel.delete({ hardDelete: true }); + }); }); diff --git a/test-cleanup.js b/test-cleanup.js index 3aea9fc..931166a 100644 --- a/test-cleanup.js +++ b/test-cleanup.js @@ -57,7 +57,9 @@ const cleanUpChannels = async () => { await Promise.all( channels.map((c) => - client.chat.channel(c.channel.type, c.channel.id).delete(), + client.chat + .channel(c.channel.type, c.channel.id) + .delete({ hardDelete: true }), ), ); };