-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(Angular): Fixed bug with Setup TOTP and added Jest #2539
Conversation
…otp-angular-fix-with-jest
🦋 Changeset detectedLatest commit: 955ac0b The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
"test": { | ||
"builder": "@angular-devkit/build-angular:karma", | ||
"options": { | ||
"main": "projects/ui-angular/src/test.ts", | ||
"tsConfig": "projects/ui-angular/tsconfig.spec.json", | ||
"karmaConfig": "projects/ui-angular/karma.conf.js" | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed
|
||
setupTOTPSpy.mockResolvedValue(SECRET_KEY); | ||
|
||
const mockAuthenticatorService = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New mocked service
|
||
constructor(public authenticator: AuthenticatorService) {} | ||
|
||
ngOnInit(): void { | ||
this.generateQRCode(); | ||
async ngOnInit(): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be async
@@ -35,8 +35,10 @@ export class AuthenticatorService implements OnDestroy { | |||
const authService = interpret(machine).start(); | |||
|
|||
this._machineSubscription = authService.subscribe((state) => { | |||
this._authState = state; | |||
this._facade = getServiceContextFacade(state); | |||
this._authState = state as unknown as AuthMachineState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was throwing a TS error, so I fixed the type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than cast twice (here and on line 40), can we just type the state
argument on line 37?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can clean it up a little, by setting state to unknown
then only typecasing to AuthMachineState
. That helps clean it up a bit. But I'm not sure how to do that all in one in line 37.
this._machineSubscription = authService.subscribe((state: unknown) => {
this._authState = state as AuthMachineState;
this._facade = getServiceContextFacade(state as AuthMachineState);
});
@@ -7,6 +7,7 @@ import { | |||
getActorState, | |||
SignInState, | |||
translate, | |||
getTotpCode, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored this into it's own utility function in ui
@@ -53,7 +53,6 @@ | |||
"@vitejs/plugin-vue": "^2.3.3", | |||
"@vitejs/plugin-vue-jsx": "^1.3.10", | |||
"@vue/babel-plugin-jsx": "^1.1.1", | |||
"@vue/cli-plugin-unit-jest": "5.0.0-beta.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a really old import that I never used, but was installing an old version of jest. So I removed it.
This pull request introduces 1 alert when merging d6421f3 into c12e9f5 - view on LGTM.com new alerts:
|
...-angular/src/lib/components/authenticator/components/setup-totp/setup-totp.component.spec.ts
Show resolved
Hide resolved
...-angular/src/lib/components/authenticator/components/setup-totp/setup-totp.component.spec.ts
Outdated
Show resolved
Hide resolved
...-angular/src/lib/components/authenticator/components/setup-totp/setup-totp.component.spec.ts
Outdated
Show resolved
Hide resolved
...ts/ui-angular/src/lib/components/authenticator/components/setup-totp/setup-totp.component.ts
Show resolved
Hide resolved
packages/angular/projects/ui-angular/src/lib/primitives/button/button.component.spec.ts
Outdated
Show resolved
Hide resolved
packages/angular/projects/ui-angular/src/lib/primitives/checkbox/checkbox.component.spec.ts
Outdated
Show resolved
Hide resolved
packages/angular/projects/ui-angular/src/lib/primitives/button/button.component.spec.ts
Show resolved
Hide resolved
packages/angular/projects/ui-angular/src/lib/primitives/button/button.component.spec.ts
Show resolved
Hide resolved
...ts/ui-angular/src/lib/components/authenticator/components/setup-totp/setup-totp.component.ts
Show resolved
Hide resolved
...ts/ui-angular/src/lib/components/authenticator/components/setup-totp/setup-totp.component.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this! Left some feedback and questions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚢
@@ -7,50 +7,47 @@ | |||
"dev": "ng build --watch", | |||
"start": "ng serve", | |||
"build": "ng build --prod", | |||
"test": "echo \"Skipped: ng test\"", | |||
"test": "jest", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨ Definitely can be done in a separate PR but we should add yarn angular test
in the top level yarn test
script
packages/angular/projects/ui-angular/src/lib/services/authenticator.service.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description of changes
Fixed issue with Angular Setup TOTP not seeing the totpIssuer and username. Included jest tests for Setup TOTP page.
Issue #, if available
#2475
Description of how you validated changes
Added jest test
Checklist
yarn test
passessideEffects
field updatedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.