diff --git a/package.json b/package.json index 59c8390..80e1f9f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@internxt/sdk", "author": "Internxt ", - "version": "1.15.4", + "version": "1.15.5", "description": "An sdk for interacting with Internxt's services", "repository": { "type": "git", diff --git a/src/meet/index.ts b/src/meet/index.ts index 13aab6d..517fc48 100644 --- a/src/meet/index.ts +++ b/src/meet/index.ts @@ -1,7 +1,7 @@ import { ApiSecurity, ApiUrl, AppDetails } from '../shared'; import { basicHeaders, headersWithToken } from '../shared/headers'; import { HttpClient } from '../shared/http/client'; -import { CreateCallResponse, JoinCallPayload, JoinCallResponse, UsersInCallResponse } from './types'; +import { CreateCallResponse, JoinCallPayload, JoinCallResponse, LeaveCallPayload, UsersInCallResponse } from './types'; export class Meet { private readonly client: HttpClient; @@ -28,10 +28,10 @@ export class Meet { return this.client.post(`call/${callId}/users/join`, { ...payload }, headers); } - async leaveCall(callId: string): Promise { + async leaveCall(callId: string, payload?: LeaveCallPayload): Promise { const headers = this.apiSecurity?.token ? this.headersWithToken() : this.basicHeaders(); - return this.client.post(`call/${callId}/users/leave`, {}, headers); + return this.client.post(`call/${callId}/users/leave`, payload ? { ...payload } : {}, headers); } async getCurrentUsersInCall(callId: string): Promise { diff --git a/src/meet/types.ts b/src/meet/types.ts index 66416ad..7e70f5b 100644 --- a/src/meet/types.ts +++ b/src/meet/types.ts @@ -19,6 +19,10 @@ export interface JoinCallResponse { appId: string; } +export interface LeaveCallPayload { + userId: string; +} + export interface UsersInCallResponse { userId: string; name: string; diff --git a/test/drive/meet/index.test.ts b/test/drive/meet/index.test.ts index d65c239..7da3cb8 100644 --- a/test/drive/meet/index.test.ts +++ b/test/drive/meet/index.test.ts @@ -3,7 +3,13 @@ import { ApiSecurity, AppDetails } from '../../../src/shared'; import { basicHeaders, headersWithToken } from '../../../src/shared/headers'; import { HttpClient } from '../../../src/shared/http/client'; import { Meet } from '../../../src/meet/index'; -import { CreateCallResponse, JoinCallPayload, JoinCallResponse, UsersInCallResponse } from '../../../src/meet/types'; +import { + CreateCallResponse, + JoinCallPayload, + JoinCallResponse, + LeaveCallPayload, + UsersInCallResponse, +} from '../../../src/meet/types'; describe('Meet service tests', () => { beforeEach(() => { @@ -131,7 +137,7 @@ describe('Meet service tests', () => { describe('leaveCall method', () => { const callId = 'call-123'; - it('should leave a call successfully with token', async () => { + it('should leave a call successfully with token and no payload', async () => { // Arrange const { client, headers } = clientAndHeadersWithToken(); const postCall = vi.spyOn(HttpClient.prototype, 'post').mockResolvedValue(undefined); @@ -143,7 +149,7 @@ describe('Meet service tests', () => { expect(postCall).toHaveBeenCalledWith(`call/${callId}/users/leave`, {}, headers); }); - it('should leave a call successfully without token', async () => { + it('should leave a call successfully without token and no payload', async () => { // Arrange const { client, headers } = clientAndHeadersWithoutToken(); const postCall = vi.spyOn(HttpClient.prototype, 'post').mockResolvedValue(undefined); @@ -154,6 +160,26 @@ describe('Meet service tests', () => { // Assert expect(postCall).toHaveBeenCalledWith(`call/${callId}/users/leave`, {}, headers); }); + + it('should send userId in body when anonymous user leaves with token', async () => { + const payload: LeaveCallPayload = { userId: 'anon-uuid-456' }; + const { client, headers } = clientAndHeadersWithToken(); + const postCall = vi.spyOn(HttpClient.prototype, 'post').mockResolvedValue(undefined); + + await client.leaveCall(callId, payload); + + expect(postCall).toHaveBeenCalledWith(`call/${callId}/users/leave`, { userId: 'anon-uuid-456' }, headers); + }); + + it('should send userId in body when anonymous user leaves without token', async () => { + const payload: LeaveCallPayload = { userId: 'anon-uuid-789' }; + const { client, headers } = clientAndHeadersWithoutToken(); + const postCall = vi.spyOn(HttpClient.prototype, 'post').mockResolvedValue(undefined); + + await client.leaveCall(callId, payload); + + expect(postCall).toHaveBeenCalledWith(`call/${callId}/users/leave`, { userId: 'anon-uuid-789' }, headers); + }); }); });