mirror of
https://github.com/bitwarden/browser
synced 2026-02-11 05:53:42 +00:00
Fix tests
This commit is contained in:
@@ -16,12 +16,12 @@ describe("TotpService", () => {
|
||||
beforeEach(() => {
|
||||
generateTotpMock = jest
|
||||
.fn()
|
||||
.mockReturnValueOnce({
|
||||
.mockResolvedValueOnce({
|
||||
code: "123456",
|
||||
period: 30,
|
||||
})
|
||||
.mockReturnValueOnce({ code: "654321", period: 30 })
|
||||
.mockReturnValueOnce({ code: "567892", period: 30 });
|
||||
.mockResolvedValueOnce({ code: "654321", period: 30 })
|
||||
.mockResolvedValueOnce({ code: "567892", period: 30 });
|
||||
|
||||
const mockBitwardenClient = {
|
||||
vault: () => ({
|
||||
@@ -59,7 +59,7 @@ describe("TotpService", () => {
|
||||
jest.advanceTimersByTime(1000);
|
||||
});
|
||||
|
||||
it("should emit TOTP response every second", () => {
|
||||
it("should emit TOTP response every second", async () => {
|
||||
const responses: TotpResponse[] = [];
|
||||
|
||||
totpService
|
||||
@@ -69,8 +69,7 @@ describe("TotpService", () => {
|
||||
responses.push(result);
|
||||
});
|
||||
|
||||
jest.advanceTimersByTime(2000);
|
||||
|
||||
await jest.advanceTimersByTimeAsync(2000);
|
||||
expect(responses).toEqual([
|
||||
{ code: "123456", period: 30 },
|
||||
{ code: "654321", period: 30 },
|
||||
@@ -78,16 +77,16 @@ describe("TotpService", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("should stop emitting TOTP response after unsubscribing", () => {
|
||||
it("should stop emitting TOTP response after unsubscribing", async () => {
|
||||
const responses: TotpResponse[] = [];
|
||||
|
||||
const subscription = totpService.getCode$("WQIQ25BRKZYCJVYP").subscribe((result) => {
|
||||
responses.push(result);
|
||||
});
|
||||
|
||||
jest.advanceTimersByTime(1000);
|
||||
await jest.advanceTimersByTimeAsync(1900);
|
||||
subscription.unsubscribe();
|
||||
jest.advanceTimersByTime(1000);
|
||||
await jest.advanceTimersByTimeAsync(2000);
|
||||
|
||||
expect(responses).toHaveLength(2);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Observable, from, shareReplay, switchMap, timer } from "rxjs";
|
||||
import { Observable, concatMap, from, shareReplay, switchMap, timer } from "rxjs";
|
||||
|
||||
import { TotpResponse } from "@bitwarden/sdk-internal";
|
||||
|
||||
@@ -30,7 +30,7 @@ export class TotpService implements TotpServiceAbstraction {
|
||||
|
||||
getCode$(key: string): Observable<TotpResponse> {
|
||||
return timer(0, 1000).pipe(
|
||||
switchMap(() =>
|
||||
concatMap(() =>
|
||||
this.sdkService.client$.pipe(
|
||||
switchMap((sdk) => {
|
||||
return from(sdk.vault().totp().generate_totp(key));
|
||||
|
||||
@@ -33,8 +33,8 @@ function setupVerificationResponse(
|
||||
|
||||
sdkService.client$ = of({
|
||||
crypto: () => ({
|
||||
verify_asymmetric_keys: jest.fn().mockReturnValue(mockVerificationResponse),
|
||||
make_key_pair: jest.fn().mockReturnValue(mockKeyPairResponse),
|
||||
verify_asymmetric_keys: jest.fn().mockResolvedValue(mockVerificationResponse),
|
||||
make_key_pair: jest.fn().mockResolvedValue(mockKeyPairResponse),
|
||||
}),
|
||||
free: jest.fn(),
|
||||
echo: jest.fn(),
|
||||
|
||||
Reference in New Issue
Block a user