Skip to content

Commit 8c43bd1

Browse files
committed
adding ring test
1 parent 1dd09a1 commit 8c43bd1

File tree

2 files changed

+64
-13
lines changed

2 files changed

+64
-13
lines changed

app/sdk/__mocks__/link.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
11
import { EventEmitter } from 'eventemitter3';
2-
import { type Link } from '../src/api';
2+
import { Revision } from '../src/entities';
33

4-
export class MockLinkModule implements Link {
5-
private emitter: EventEmitter;
4+
export class MockLink {
5+
private statusListener: ((status: string)=>Promise<void>) | null;
6+
private messageListener: ((message: any)=>Promise<void>) | null;
7+
private status: string;
68

79
constructor() {
8-
this.emitter = new EventEmitter();
10+
this.statusListener = null;
11+
this.messageListener = null;
12+
this.status = 'idle';
913
}
1014

11-
public setStatusListener(ev: (status: string) => Promise<void>): void {
15+
public getIce(): { urls: string; username: string; credential: string }[] {
16+
return [];
1217
}
1318

14-
public clearStatusListener(): void {
19+
public async call(node: string, secure: boolean, token: string, cardId: string, contactNode: string, contactSecure: boolean, contactGuid: string, contactToken: string) {
20+
return;
1521
}
1622

17-
public setMessageListener(ev: (message: any) => Promise<void>): void {
23+
public async join(server: string, secure: boolean, token: string, ice: { urls: string; username: string; credential: string }[], endCall: ()=>Promise<void>) {
24+
return;
1825
}
1926

20-
public clearMessageListener(): void {
27+
public async close() {
28+
return;
2129
}
2230

23-
public getIce(): { urls: string; username: string; credential: string }[] {
24-
return [];
31+
public setStatusListener(listener: (status: string) => Promise<void>) {
32+
this.statusListener = listener;
33+
this.statusListener(this.status);
2534
}
26-
27-
public async sendMessage(message: any): Promise<void> {
35+
36+
public clearStatusListener() {
37+
this.statusListener = null;
2838
}
2939

30-
public async close(): Promise<void> {
40+
public setMessageListener(listener: (message: any) => Promise<void>) {
41+
this.messageListener = listener;
42+
}
43+
44+
public clearMessageListener() {
45+
this.messageListener = null;
3146
}
3247

48+
public async sendMessage(message: any) {
49+
}
3350
}
3451

app/sdk/__tests__/ring.tests.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { RingModule } from '../src/ring';
2+
import { MockLink } from '../__mocks__/link';
3+
import { waitFor } from '../__mocks__/waitFor';
4+
import { ConsoleLogging } from '../src/logging';
5+
6+
jest.mock('../src/net/fetchUtil', () => {
7+
const fn = jest.fn().mockImplementation((url: string, options: { method: string, body: string }) => {
8+
console.log(url, options);
9+
return Promise.resolve({ state: 200, json: () => {} });
10+
});
11+
12+
return {
13+
fetchWithTimeout: fn,
14+
checkResponse: () => {},
15+
}
16+
});
17+
18+
const mockLink = new MockLink();
19+
jest.mock('../src/link', () => {
20+
return {
21+
Connection: jest.fn().mockImplementation(() => {
22+
return mockLink;
23+
})
24+
}
25+
})
26+
27+
test('rings correctly', async () => {
28+
const endContactCall = async (cardId: string, callId: string) => {
29+
console.log("ending");
30+
}
31+
32+
const log = new ConsoleLogging();
33+
const ring = new RingModule(log, endContactCall);
34+
});

0 commit comments

Comments
 (0)