Skip to content

Commit 1a5eddd

Browse files
authored
[VBLOCKS-5022] feat: preflight public method unit tests (#592)
1 parent f909cc7 commit 1a5eddd

File tree

1 file changed

+299
-1
lines changed

1 file changed

+299
-1
lines changed

src/__tests__/PreflightTest.test.ts

Lines changed: 299 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,304 @@ describe('PreflightTest', () => {
539539
});
540540

541541
describe('public methods', () => {
542-
it('stub', () => {});
542+
let preflight: PreflightTest;
543+
544+
beforeEach(() => {
545+
preflight = new PreflightTest(mockUuid);
546+
});
547+
548+
describe('getCallSid', () => {
549+
it('invokes the native module', async () => {
550+
const spy = jest
551+
.spyOn(Common.NativeModule, 'preflightTest_getCallSid')
552+
.mockResolvedValue('mock-callsid');
553+
554+
await preflight.getCallSid();
555+
556+
expect(spy.mock.calls).toEqual([[mockUuid]]);
557+
});
558+
});
559+
560+
describe('getEndTime', () => {
561+
let spy: jest.SpyInstance;
562+
563+
beforeEach(() => {
564+
spy = jest
565+
.spyOn(Common.NativeModule, 'preflightTest_getEndTime')
566+
.mockResolvedValue('100');
567+
});
568+
569+
it('invokes the native module', async () => {
570+
await preflight.getEndTime();
571+
572+
expect(spy.mock.calls).toEqual([[mockUuid]]);
573+
});
574+
575+
it('returns a number', async () => {
576+
const endTime = await preflight.getEndTime();
577+
578+
expect(endTime).toEqual(100);
579+
});
580+
});
581+
582+
describe('getLatestSample', () => {
583+
let spy: jest.SpyInstance;
584+
585+
beforeEach(() => {
586+
spy = jest
587+
.spyOn(Common.NativeModule, 'preflightTest_getLatestSample')
588+
.mockResolvedValue(JSON.stringify(mockSample));
589+
});
590+
591+
it('invokes the native module', async () => {
592+
await preflight.getLatestSample();
593+
594+
expect(spy.mock.calls).toEqual([[mockUuid]]);
595+
});
596+
597+
it('returns a sample', async () => {
598+
const sample = await preflight.getLatestSample();
599+
600+
expect(sample).toEqual({
601+
audioInputLevel: 10,
602+
audioOutputLevel: 20,
603+
bytesReceived: 30,
604+
bytesSent: 40,
605+
codec: 'mock-codec',
606+
jitter: 50,
607+
mos: 60,
608+
packetsLost: 70,
609+
packetsLostFraction: 80,
610+
packetsReceived: 90,
611+
packetsSent: 100,
612+
rtt: 110,
613+
timestamp: 120,
614+
});
615+
});
616+
});
617+
618+
describe('getReport', () => {
619+
describe('invalid platform', () => {
620+
it('throws an error', async () => {
621+
jest
622+
.spyOn(Common.Platform, 'OS', 'get')
623+
.mockReturnValue('foobar' as any);
624+
625+
jest
626+
.spyOn(Common.NativeModule, 'preflightTest_getReport')
627+
.mockImplementation(async () => '{}');
628+
629+
await expect(async () => {
630+
await preflight.getReport();
631+
}).rejects.toBeInstanceOf(InvalidStateError);
632+
});
633+
});
634+
635+
describe('android', () => {
636+
beforeEach(() => {
637+
jest.spyOn(Common.Platform, 'OS', 'get').mockReturnValue('android');
638+
});
639+
640+
it('invokes the native module', async () => {
641+
const spy = jest
642+
.spyOn(Common.NativeModule, 'preflightTest_getReport')
643+
.mockResolvedValue(
644+
JSON.stringify({ ...baseMockReport, callQuality: 'Excellent' })
645+
);
646+
await preflight.getReport();
647+
expect(spy.mock.calls).toEqual([[mockUuid]]);
648+
});
649+
650+
it('parses a valid native report', async () => {
651+
jest
652+
.spyOn(Common.NativeModule, 'preflightTest_getReport')
653+
.mockResolvedValue(
654+
JSON.stringify({ ...baseMockReport, callQuality: 'Excellent' })
655+
);
656+
657+
const report = await preflight.getReport();
658+
659+
expect(report).toEqual(expectedReport);
660+
});
661+
662+
it('handles null native call quality', async () => {
663+
jest
664+
.spyOn(Common.NativeModule, 'preflightTest_getReport')
665+
.mockResolvedValue(
666+
JSON.stringify({ ...baseMockReport, callQuality: null })
667+
);
668+
669+
const report = await preflight.getReport();
670+
671+
expect(report).toEqual({ ...expectedReport, callQuality: null });
672+
});
673+
674+
it('throws if the native call quality is an invalid string', async () => {
675+
jest
676+
.spyOn(Common.NativeModule, 'preflightTest_getReport')
677+
.mockResolvedValue(
678+
JSON.stringify({ ...baseMockReport, callQuality: 'foobar' })
679+
);
680+
681+
await expect(async () => {
682+
await preflight.getReport();
683+
}).rejects.toBeInstanceOf(InvalidStateError);
684+
});
685+
686+
it('throws if the native call quality is not a string', async () => {
687+
jest
688+
.spyOn(Common.NativeModule, 'preflightTest_getReport')
689+
.mockResolvedValue(
690+
JSON.stringify({ ...baseMockReport, callQuality: 10 })
691+
);
692+
693+
await expect(async () => {
694+
await preflight.getReport();
695+
}).rejects.toBeInstanceOf(InvalidStateError);
696+
});
697+
});
698+
699+
describe('ios', () => {
700+
beforeEach(() => {
701+
jest.spyOn(Common.Platform, 'OS', 'get').mockReturnValue('ios');
702+
});
703+
704+
it('invokes the native module', async () => {
705+
const spy = jest
706+
.spyOn(Common.NativeModule, 'preflightTest_getReport')
707+
.mockResolvedValue(
708+
JSON.stringify({ ...baseMockReport, callQuality: 0 })
709+
);
710+
711+
await preflight.getReport();
712+
713+
expect(spy.mock.calls).toEqual([[mockUuid]]);
714+
});
715+
716+
it('parses a valid native report', async () => {
717+
jest
718+
.spyOn(Common.NativeModule, 'preflightTest_getReport')
719+
.mockResolvedValue(
720+
JSON.stringify({ ...baseMockReport, callQuality: 0 })
721+
);
722+
723+
const report = await preflight.getReport();
724+
725+
expect(report).toEqual(expectedReport);
726+
});
727+
728+
it('handles null native call quality', async () => {
729+
jest
730+
.spyOn(Common.NativeModule, 'preflightTest_getReport')
731+
.mockResolvedValue(
732+
JSON.stringify({ ...baseMockReport, callQuality: null })
733+
);
734+
735+
const report = await preflight.getReport();
736+
737+
expect(report).toEqual({ ...expectedReport, callQuality: null });
738+
});
739+
740+
it('throws if the native call quality is an invalid number', async () => {
741+
jest
742+
.spyOn(Common.NativeModule, 'preflightTest_getReport')
743+
.mockResolvedValue(
744+
JSON.stringify({ ...baseMockReport, callQuality: 100 })
745+
);
746+
747+
await expect(async () => {
748+
await preflight.getReport();
749+
}).rejects.toBeInstanceOf(InvalidStateError);
750+
});
751+
752+
it('throws if the native call quality is not a number', async () => {
753+
jest
754+
.spyOn(Common.NativeModule, 'preflightTest_getReport')
755+
.mockResolvedValue(
756+
JSON.stringify({ ...baseMockReport, callQuality: 'foobar' })
757+
);
758+
759+
await expect(async () => {
760+
await preflight.getReport();
761+
}).rejects.toBeInstanceOf(InvalidStateError);
762+
});
763+
});
764+
});
765+
766+
describe('getStartTime', () => {
767+
it('invokes the native module', async () => {
768+
const spy = jest
769+
.spyOn(Common.NativeModule, 'preflightTest_getStartTime')
770+
.mockImplementation(async () => '10');
771+
772+
await preflight.getStartTime();
773+
774+
expect(spy.mock.calls).toEqual([[mockUuid]]);
775+
});
776+
777+
it('returns a number', async () => {
778+
jest
779+
.spyOn(Common.NativeModule, 'preflightTest_getStartTime')
780+
.mockImplementation(async () => '10');
781+
782+
const startTime = await preflight.getStartTime();
783+
784+
expect(startTime).toEqual(10);
785+
});
786+
});
787+
788+
describe('getState', () => {
789+
it('invokes the native module', async () => {
790+
const spy = jest
791+
.spyOn(Common.NativeModule, 'preflightTest_getState')
792+
.mockImplementation(async () => 'completed');
793+
794+
await preflight.getState();
795+
796+
expect(spy.mock.calls).toEqual([[mockUuid]]);
797+
});
798+
799+
it('returns a valid state', async () => {
800+
jest
801+
.spyOn(Common.NativeModule, 'preflightTest_getState')
802+
.mockImplementation(async () => 'completed');
803+
804+
const state = await preflight.getState();
805+
806+
expect(state).toEqual(PreflightTest.State.Completed);
807+
});
808+
809+
it('throws when the native state is not a string', async () => {
810+
jest
811+
.spyOn(Common.NativeModule, 'preflightTest_getState')
812+
.mockImplementation(async () => 10 as any);
813+
814+
expect(async () => {
815+
await preflight.getState();
816+
}).rejects.toThrowError(InvalidStateError);
817+
});
818+
});
819+
820+
describe('stop', () => {
821+
it('invokes the native module', async () => {
822+
const spy = jest
823+
.spyOn(Common.NativeModule, 'preflightTest_stop')
824+
.mockImplementation(async () => {});
825+
826+
await preflight.stop();
827+
828+
expect(spy.mock.calls).toEqual([[mockUuid]]);
829+
});
830+
831+
it('returns undefined', async () => {
832+
jest
833+
.spyOn(Common.NativeModule, 'preflightTest_stop')
834+
.mockImplementation(async () => {});
835+
836+
const retVal = await preflight.stop();
837+
838+
expect(retVal).toBeUndefined();
839+
});
840+
});
543841
});
544842
});

0 commit comments

Comments
 (0)