adding ring test
Some checks are pending
CI / CI (push) Waiting to run

This commit is contained in:
balzack 2025-03-08 20:40:17 -08:00
parent 1dd09a1632
commit 8c43bd18be
2 changed files with 69 additions and 18 deletions

View File

@ -1,34 +1,51 @@
import { EventEmitter } from 'eventemitter3';
import { type Link } from '../src/api';
import { Revision } from '../src/entities';
export class MockLinkModule implements Link {
private emitter: EventEmitter;
export class MockLink {
private statusListener: ((status: string)=>Promise<void>) | null;
private messageListener: ((message: any)=>Promise<void>) | null;
private status: string;
constructor() {
this.emitter = new EventEmitter();
}
public setStatusListener(ev: (status: string) => Promise<void>): void {
}
public clearStatusListener(): void {
}
public setMessageListener(ev: (message: any) => Promise<void>): void {
}
public clearMessageListener(): void {
this.statusListener = null;
this.messageListener = null;
this.status = 'idle';
}
public getIce(): { urls: string; username: string; credential: string }[] {
return [];
}
public async sendMessage(message: any): Promise<void> {
public async call(node: string, secure: boolean, token: string, cardId: string, contactNode: string, contactSecure: boolean, contactGuid: string, contactToken: string) {
return;
}
public async close(): Promise<void> {
public async join(server: string, secure: boolean, token: string, ice: { urls: string; username: string; credential: string }[], endCall: ()=>Promise<void>) {
return;
}
public async close() {
return;
}
public setStatusListener(listener: (status: string) => Promise<void>) {
this.statusListener = listener;
this.statusListener(this.status);
}
public clearStatusListener() {
this.statusListener = null;
}
public setMessageListener(listener: (message: any) => Promise<void>) {
this.messageListener = listener;
}
public clearMessageListener() {
this.messageListener = null;
}
public async sendMessage(message: any) {
}
}

View File

@ -0,0 +1,34 @@
import { RingModule } from '../src/ring';
import { MockLink } from '../__mocks__/link';
import { waitFor } from '../__mocks__/waitFor';
import { ConsoleLogging } from '../src/logging';
jest.mock('../src/net/fetchUtil', () => {
const fn = jest.fn().mockImplementation((url: string, options: { method: string, body: string }) => {
console.log(url, options);
return Promise.resolve({ state: 200, json: () => {} });
});
return {
fetchWithTimeout: fn,
checkResponse: () => {},
}
});
const mockLink = new MockLink();
jest.mock('../src/link', () => {
return {
Connection: jest.fn().mockImplementation(() => {
return mockLink;
})
}
})
test('rings correctly', async () => {
const endContactCall = async (cardId: string, callId: string) => {
console.log("ending");
}
const log = new ConsoleLogging();
const ring = new RingModule(log, endContactCall);
});