Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/api_productions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
const mockIngestManager = {
load: jest.fn().mockResolvedValue(undefined),
startPolling: jest.fn()
} as any;

Check warning on line 65 in src/api_productions.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

const mockCoreFunctions = {
getAllLinesResponse: jest.fn().mockImplementation((production) =>
Expand Down Expand Up @@ -168,6 +168,12 @@
.mockImplementation((lines: any[], id: string) =>
lines.find((l) => l.id === id)
),
requireLine: jest.fn().mockImplementation((lines: any[], id: string) => {
const found = lines.find((l) => l.id === id);
if (!found) throw new Error(`Line ${id} not found`);
return found;
}),
clearWhepSourceIfPinned: jest.fn().mockResolvedValue(undefined),
updateUserLastSeen: jest
.fn()
.mockImplementation((sessionId: string) => sessionId === 'alive-session'),
Expand All @@ -176,6 +182,7 @@
removeUserSession: jest
.fn()
.mockImplementation((sessionId: string) => sessionId),
emit: jest.fn(),
createUserSession: jest.fn().mockResolvedValue(undefined),
getActiveUsers: jest.fn().mockResolvedValue([])
} as any;
Expand Down Expand Up @@ -483,6 +490,47 @@
});
});

describe('PATCH /session/:id', () => {
test('flushes a 204 once the SDP answer is handled', async () => {
const patchSession = {
_id: 'mock-session',
name: 'usersession',
productionId: '1',
lineId: '1',
endpointId: 'mock-endpoint-1',
isActive: true,
isExpired: false,
isWhip: false,
sessionDescription: { audio: { ssrcs: [1] }, video: { ssrcs: [] } }
};
const getSessionSpy = jest
.spyOn(mockDbManager, 'getSession')
.mockResolvedValue(patchSession as any);
mockProductionManager.getProduction = jest
.fn()
.mockResolvedValue(mockProductions[0]);
mockProductionManager.updateUserEndpoint = jest
.fn()
.mockResolvedValue(undefined);
mockProductionManager.updateSessionHasVideo = jest
.fn()
.mockResolvedValue(undefined);
mockCoreFunctions.handleAnswerRequest = jest
.fn()
.mockResolvedValue(undefined);

const response = await server.inject({
method: 'PATCH',
url: '/api/v1/session/mock-session',
body: { sdpAnswer: 'v=0' }
});

expect(response.statusCode).toBe(204);
expect(mockCoreFunctions.handleAnswerRequest).toHaveBeenCalled();
getSessionSpy.mockRestore();
});
});

describe('POST /production/:id/line/:id/participants', () => {
test('can do long polling for change in line participants', async () => {
mockProductionManager.once = jest
Expand Down
Loading
Loading