From d7009dadb31376079fabf5d35c8590e9289b64c7 Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Thu, 20 Jun 2024 11:24:38 +0200 Subject: [PATCH] Implement end call endpoint --- __tests__/call.test.ts | 8 +++++++- src/StreamCall.ts | 16 ++++++++++++++-- test-cleanup.js | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/__tests__/call.test.ts b/__tests__/call.test.ts index 9d7593f..85e032a 100644 --- a/__tests__/call.test.ts +++ b/__tests__/call.test.ts @@ -10,7 +10,7 @@ import { describe('call API', () => { let client: StreamClient; - const callId = `call${uuidv4()}`; + const callId = `callnodetest${uuidv4()}`; let call: StreamCall; beforeAll(async () => { @@ -280,5 +280,11 @@ describe('call API', () => { ); }); }); + + it('delete', async () => { + const response = await call.delete({ hard: true }); + + expect(response.call.cid).toBe(call.cid); + }); }); }); diff --git a/src/StreamCall.ts b/src/StreamCall.ts index 8bcbbde..061f239 100644 --- a/src/StreamCall.ts +++ b/src/StreamCall.ts @@ -6,6 +6,7 @@ import { GetCallStatsRequest, ProductvideoApi, VideoBlockUserRequest, + VideoDeleteCallRequest, VideoGetOrCreateCallRequest, VideoGoLiveRequest, VideoMuteUsersRequest, @@ -28,14 +29,18 @@ export class StreamCall { constructor( private readonly streamClient: StreamClient, - private readonly type: string, - private readonly id: string, + public readonly type: string, + public readonly id: string, ) { this.baseRequest = { id: this.id, type: this.type }; const configuration = this.streamClient.getConfiguration('video'); this.apiClient = new ProductvideoApi(configuration); } + get cid() { + return `${this.type}:${this.id}`; + } + blockUser = (videoBlockUserRequest: VideoBlockUserRequest) => { return this.apiClient.blockUser({ ...this.baseRequest, @@ -51,6 +56,13 @@ export class StreamCall { return this.apiClient.getCall({ ...(request ?? {}), ...this.baseRequest }); }; + delete = (videoDeleteCallRequest?: VideoDeleteCallRequest) => { + return this.apiClient.deleteCall({ + ...this.baseRequest, + videoDeleteCallRequest: videoDeleteCallRequest || null, + }); + }; + getOrCreate = (videoGetOrCreateCallRequest?: VideoGetOrCreateCallRequest) => { return this.apiClient.getOrCreateCall({ ...this.baseRequest, diff --git a/test-cleanup.js b/test-cleanup.js index 2aff8ba..19776ca 100644 --- a/test-cleanup.js +++ b/test-cleanup.js @@ -24,6 +24,19 @@ const cleanupBlockLists = async () => { ); }; +const cleanupCalls = async () => { + const calls = (await client.video.queryCalls()).calls; + const testCalls = Object.keys(calls).filter((t) => + t.startsWith("callnodetest"), + ); + + await Promise.all( + testCalls.map((t) => + client.video.call(t.call.type, t.call.id).delete({ hard: true }), + ), + ); +}; + const cleanupCallTypes = async () => { const callTypes = (await client.video.listCallTypes()).call_types; const customCallTypes = Object.keys(callTypes).filter( @@ -127,6 +140,7 @@ const cleanup = async () => { await cleanUpRoles(); await cleanUpUsers(); await cleanupExternalStorage(); + await cleanupCalls(); }; cleanup().then(() => {