Skip to content

Commit

Permalink
update component and guard for null check
Browse files Browse the repository at this point in the history
  • Loading branch information
Jingo88 committed Dec 12, 2024
1 parent 6e6228a commit 847911c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { inject } from "@angular/core";
import { CanActivateFn, Router } from "@angular/router";
import { firstValueFrom, map } from "rxjs";
import { Observable, firstValueFrom, map } from "rxjs";

Check warning on line 3 in libs/angular/src/vault/guards/new-device-verification-notice.guard.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/vault/guards/new-device-verification-notice.guard.ts#L1-L3

Added lines #L1 - L3 were not covered by tests

import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { Account, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";

Check warning on line 7 in libs/angular/src/vault/guards/new-device-verification-notice.guard.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/vault/guards/new-device-verification-notice.guard.ts#L5-L7

Added lines #L5 - L7 were not covered by tests
import { UserId } from "@bitwarden/common/types/guid";

import { NewDeviceVerificationNoticeService } from "../../../../vault/src/services/new-device-verification-notice.service";

Check warning on line 9 in libs/angular/src/vault/guards/new-device-verification-notice.guard.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/vault/guards/new-device-verification-notice.guard.ts#L9

Added line #L9 was not covered by tests

Expand All @@ -22,10 +21,16 @@ export const NewDeviceVerificationNoticeGuard: CanActivateFn = async () => {
FeatureFlag.NewDeviceVerificationPermanentDismiss,
);

const currentAcctId: UserId = await firstValueFrom(
accountService.activeAccount$.pipe(map((acct) => acct?.id)),
const currentAcct$: Observable<Account | null> = accountService.activeAccount$.pipe(
map((acct) => acct),

Check warning on line 25 in libs/angular/src/vault/guards/new-device-verification-notice.guard.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/vault/guards/new-device-verification-notice.guard.ts#L24-L25

Added lines #L24 - L25 were not covered by tests
);
const userItems$ = newDeviceVerificationNoticeService.noticeState$(currentAcctId);
const currentAcct = await firstValueFrom(currentAcct$);

Check warning on line 27 in libs/angular/src/vault/guards/new-device-verification-notice.guard.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/vault/guards/new-device-verification-notice.guard.ts#L27

Added line #L27 was not covered by tests

if (!currentAcct) {
return false;

Check warning on line 30 in libs/angular/src/vault/guards/new-device-verification-notice.guard.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/vault/guards/new-device-verification-notice.guard.ts#L30

Added line #L30 was not covered by tests
}

const userItems$ = newDeviceVerificationNoticeService.noticeState$(currentAcct.id);
const userItems = await firstValueFrom(userItems$);

Check warning on line 34 in libs/angular/src/vault/guards/new-device-verification-notice.guard.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/vault/guards/new-device-verification-notice.guard.ts#L33-L34

Added lines #L33 - L34 were not covered by tests

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ export class NewDeviceVerificationNoticePageOneComponent implements OnInit {
}

async ngOnInit() {
this.currentEmail = (await firstValueFrom(this.currentAcct$)).email;
this.currentUserId = (await firstValueFrom(this.currentAcct$)).id;
const currentAcct = await firstValueFrom(this.currentAcct$);

Check warning on line 64 in libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-one.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-one.component.ts#L64

Added line #L64 was not covered by tests
if (!currentAcct) {
return;

Check warning on line 66 in libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-one.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-one.component.ts#L66

Added line #L66 was not covered by tests
}
this.currentEmail = currentAcct.email;
this.currentUserId = currentAcct.id;
this.formMessage = this.i18nService.t(

Check warning on line 70 in libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-one.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-one.component.ts#L68-L70

Added lines #L68 - L70 were not covered by tests
"newDeviceVerificationNoticePageOneFormContent",
this.currentEmail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export class NewDeviceVerificationNoticePageTwoComponent implements OnInit {
}

async ngOnInit() {
this.currentUserId = (await firstValueFrom(this.currentAcct$)).id;
const currentAcct = await firstValueFrom(this.currentAcct$);

Check warning on line 38 in libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-two.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-two.component.ts#L38

Added line #L38 was not covered by tests
if (!currentAcct) {
return;

Check warning on line 40 in libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-two.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-two.component.ts#L40

Added line #L40 was not covered by tests
}
this.currentUserId = currentAcct.id;

Check warning on line 42 in libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-two.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-two.component.ts#L42

Added line #L42 was not covered by tests
}
async remindMeLaterSelect() {
await this.newDeviceVerificationNoticeService.updateNewDeviceVerificationNoticeState(

Check warning on line 45 in libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-two.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/vault/src/components/new-device-verification-notice/new-device-verification-notice-page-two.component.ts#L45

Added line #L45 was not covered by tests
Expand Down

0 comments on commit 847911c

Please sign in to comment.