Skip to content

Commit

Permalink
Cut down on @ts- skips
Browse files Browse the repository at this point in the history
  • Loading branch information
bogue committed Jan 9, 2024
1 parent c03b5f7 commit c66e4be
Show file tree
Hide file tree
Showing 41 changed files with 412 additions and 547 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@
}
}
}
}
}
29 changes: 10 additions & 19 deletions src/__tests__/api-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ client.setToken(token);
describe('With correct API results', () => {
beforeEach(() => {
jest.resetModules();
// @ts-expect-error
global.fetch = jest.fn(() => Promise.resolve(mockedJson));
global.fetch = jest.fn(() => Promise.resolve(mockedJson)) as any;
});

describe('logIn test', () => {
Expand All @@ -102,13 +101,12 @@ describe('With correct API results', () => {
Authorization: `Basic ${Base64.encode(`${username}:${password}`)}`,
'Content-Type': 'application/json',
};
// @ts-expect-error

const result = await client.auth.logIn({
username,
password,
});
} as any) as any;
expect(result).toBeInstanceOf(Session);
// @ts-expect-error
expect(result.token).toBe(1);
expect(global.fetch).toBeCalledWith(`https://${server}/api/auth/${authVersion}/token`, {
method: 'post',
Expand All @@ -123,8 +121,7 @@ describe('With correct API results', () => {
describe('logOut test', () => {
it('should delete the specified token', async () => {
const oldToken = 123;
// @ts-expect-error
await client.auth.logOut(oldToken);
await client.auth.logOut(oldToken as any);
expect(global.fetch).toBeCalledWith(`https://${server}/api/auth/${authVersion}/token/${oldToken}`, {
method: 'delete',
body: null,
Expand All @@ -139,8 +136,7 @@ describe('With correct API results', () => {
describe('With unAuthorized API results', () => {
beforeEach(() => {
jest.resetModules();
// @ts-expect-error
global.fetch = jest.fn(() => Promise.resolve(mockedUnAuthorized));
global.fetch = jest.fn(() => Promise.resolve(mockedUnAuthorized)) as any;
});

describe('checkLogin test', () => {
Expand All @@ -162,8 +158,7 @@ describe('With unAuthorized API results', () => {
describe('With not found API results', () => {
beforeEach(() => {
jest.resetModules();
// @ts-expect-error
global.fetch = jest.fn(() => Promise.resolve(mockedNotFound));
global.fetch = jest.fn(() => Promise.resolve(mockedNotFound)) as any;
});

describe('fetchVoicemail test', () => {
Expand Down Expand Up @@ -198,19 +193,17 @@ describe('With not found API results', () => {
describe('With erroneous text API results', () => {
beforeEach(() => {
jest.resetModules();
// @ts-expect-error
global.fetch = jest.fn(() => Promise.resolve(mockedTextError));
global.fetch = jest.fn(() => Promise.resolve(mockedTextError)) as any;
});

it('throw an exception when the response is >= 500', async () => {
let error = null;

try {
// @ts-expect-error
await client.auth.logIn({
username,
password,
});
} as any);
} catch (e: any) {
error = e;
}
Expand All @@ -225,19 +218,17 @@ describe('With erroneous text API results', () => {
describe('With erroneous json API results', () => {
beforeEach(() => {
jest.resetModules();
// @ts-expect-error
global.fetch = jest.fn(() => Promise.resolve(mockedJsonError));
global.fetch = jest.fn(() => Promise.resolve(mockedJsonError)) as any;
});

it('throw an exception when the response is >= 500', async () => {
let error = null;

try {
// @ts-expect-error
await client.auth.logIn({
username,
password,
});
} as any);
} catch (e: any) {
error = e;
}
Expand Down
38 changes: 13 additions & 25 deletions src/__tests__/web-rtc-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ jest.mock('sip.js/lib/platform/web/transport');
jest.mock('sip.js/lib/api/user-agent', () => ({
start: () => {},
UserAgent: class UserAgent {
// @ts-ignore
static makeURI = () => {};
static makeURI: () => null = () => null;

// @ts-ignore
start = () => {};

transport = {};
},
}));

// @ts-expect-error
const client = new WebRTCClient({});
const client = new WebRTCClient({} as any, null, undefined);

describe('WebRTC client', () => {
it('should compute muted/unmuted state', async () => {
Expand Down Expand Up @@ -65,14 +62,11 @@ describe('WebRTC client', () => {
},
},
};
// @ts-expect-error
expect(client.isAudioMuted(mutedSession)).toBeTruthy();
// @ts-expect-error
expect(client.isAudioMuted(oldKindMuted)).toBeTruthy();
// @ts-expect-error
expect(client.isAudioMuted(unMutedSession)).toBeFalsy();
// @ts-expect-error
expect(client.isAudioMuted(oldKindUnmuted)).toBeFalsy();

expect(client.isAudioMuted(mutedSession as any)).toBeTruthy();
expect(client.isAudioMuted(oldKindMuted as any)).toBeTruthy();
expect(client.isAudioMuted(unMutedSession as any)).toBeFalsy();
expect(client.isAudioMuted(oldKindUnmuted as any)).toBeFalsy();
});
});
describe('changeAudioInputDevice', () => {
Expand Down Expand Up @@ -131,27 +125,21 @@ describe('changeAudioInputDevice', () => {
},
});
it('should change the audio input track if the provided id is different', async () => {
// @ts-expect-error
client.setMediaConstraints(constraints);
client.setMediaConstraints(constraints as any);
expect(client.getAudioDeviceId()).toBe(defaultId);
// @ts-expect-error
const result = await client.changeAudioInputDevice(deviceId, session);
const result = await client.changeAudioInputDevice(deviceId, session as any);
expect(result).toBeTruthy();
});
it('should NOT change the audio input track if the provided id is the same', async () => {
// @ts-expect-error
client.setMediaConstraints(constraints);
client.setMediaConstraints(constraints as any);
expect(client.getAudioDeviceId()).toBe(defaultId);
// @ts-expect-error
const result = await client.changeAudioInputDevice(defaultId, session);
const result = await client.changeAudioInputDevice(defaultId, session as any);
expect(result).toBeFalsy();
});
it('should change the audio input track if the provided id is the same and force param is TRUE', async () => {
// @ts-expect-error
client.setMediaConstraints(constraints);
client.setMediaConstraints(constraints as any);
expect(client.getAudioDeviceId()).toBe(defaultId);
// @ts-expect-error
const result = await client.changeAudioInputDevice(defaultId, session, true);
const result = await client.changeAudioInputDevice(defaultId, session as any, true);
expect(result).toBeTruthy();
});
describe('setVideoInputDevice', () => {
Expand Down
3 changes: 1 addition & 2 deletions src/api/chatd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ export default ((client: ApiRequester, baseUrl: string): ChatD => ({
const uuids: Array<UUID> = contactUuids || [];

if (uuids.length > MAX_PRESENCE_FETCHED) {
const requests = uuids.reduce((acc, _, i) => {
const requests = uuids.reduce((acc: Promise<PresenceResponse[]>[], _, i) => {
if (i % MAX_PRESENCE_FETCHED === 0) {
// @ts-ignore
acc.push(this.getMultipleLineState(uuids.slice(i, i + MAX_PRESENCE_FETCHED)));
}
return acc;
Expand Down
9 changes: 3 additions & 6 deletions src/api/dird.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ type PhoneBookSearchQueryParams = {

const getContactPayload = (contact: NewContact | Contact) => ({
email: contact.email,
// @ts-ignore
firstname: contact.firstName ? contact.firstName : '',
// @ts-ignore
lastname: contact.lastName ? contact.lastName : '',
// @ts-ignore
number: contact.phoneNumber ? contact.phoneNumber : '',
firstname: (contact as any).firstName ? (contact as any).firstName : '',
lastname: (contact as any).lastName ? (contact as any).lastName : '',
number: (contact as any).phoneNumber ? (contact as any).phoneNumber : '',
entreprise: contact.entreprise ? contact.entreprise : '',
birthday: contact.birthday ? contact.birthday : '',
address: contact.address ? contact.address : '',
Expand Down
3 changes: 1 addition & 2 deletions src/checker/checks/ice-ipv4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ export default {
}

if (ips.every(checkIsIPV4)) {
// @ts-ignore
resolve();
resolve(null);
} else {
const nonIPV4 = ips.find(ip => !checkIsIPV4(ip));
reject(new Error(`Non IPv4 ice candidate found : ${nonIPV4}.`));
Expand Down
4 changes: 2 additions & 2 deletions src/checker/checks/webrtc-transport.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Invitation, Inviter } from 'sip.js';
import WebRTCClient from '../../web-rtc-client';
import { Session as WazoSession } from '../../domain/types';

export default {
name: 'WebRTC Transport (WS) ~30s',
check: (server: string, session: Inviter | Invitation): Promise<void> => new Promise((resolve, reject) => {
check: (server: string, session: WazoSession): Promise<void> => new Promise((resolve, reject) => {
const [host, port = 443] = server.split(':');

const client = new WebRTCClient({
Expand Down
2 changes: 1 addition & 1 deletion src/domain/AdHocAPIConference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class AdHocAPIConference {

async start() {
this.started = true;
// @ts-ignore
// @ts-ignore: date / number
this.answerTime = Object.values(this.participants).length ? Object.values(this.participants)[0].answerTime : null;
const participantIds = Object.keys(this.participants);
const conference = await getApiClient().calld.createAdHocConference(this.host.callId, participantIds);
Expand Down
2 changes: 1 addition & 1 deletion src/domain/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type AgentResponse = {
paused_reason: string;
};

type AgentArguments = {
export type AgentArguments = {
context: string;
extension: string;
id: number;
Expand Down
7 changes: 3 additions & 4 deletions src/domain/CallSession.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { SessionState } from 'sip.js/lib/api/session-state';
import type { Invitation } from 'sip.js/lib/api';
import { Inviter } from 'sip.js/lib/api';
import Call from './Call';
import newFrom from '../utils/new-from';
import updateFrom from '../utils/update-from';
import { Session as WazoSession } from './types';

type CallSessionArguments = {
answered: boolean;
Expand Down Expand Up @@ -33,7 +32,7 @@ type CallSessionArguments = {
screensharing: boolean;
recording: boolean;
recordingPaused: boolean;
sipSession?: Inviter | Invitation;
sipSession?: WazoSession;
conference: boolean;
};
export default class CallSession {
Expand Down Expand Up @@ -97,7 +96,7 @@ export default class CallSession {

recordingPaused: boolean;

sipSession: Inviter | Invitation | undefined;
sipSession: WazoSession | undefined;

conference: boolean;

Expand Down
2 changes: 1 addition & 1 deletion src/domain/Contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ export default class Contact {

merge(old: Contact): Contact {
Object.keys(old).filter(key => key !== 'lineState').forEach(key => {
// @ts-ignore
// @ts-ignore: keys
this[key] = old[key] || this[key];
});

Expand Down
Loading

0 comments on commit c66e4be

Please sign in to comment.