Repository navigation
fix(ENG-12483): show specific error toasts when disconnecting an orcid #1083
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
Merged
brianjgeiger
merged 3 commits into
CenterForOpenScience:feature/pbs-26-20
from
Vlad0n20:fix/ENG-12403
Oct 20, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
50802cd
fix(ENG-12403): show specific error toasts when disconnecting an orci…
Vlad0n20 cd870c3
fix(ENG-12403): share external identity deletion between settings com…
Vlad0n20 f12e188
fix(ENG-12403): add deletion service mock and spec, trim component tests
Vlad0n20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/app/features/settings/account-settings/services/account-settings.service.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { BYPASS_ERROR_INTERCEPTOR } from '@core/interceptors/error-interceptor.tokens'; | ||
| import { JsonApiService } from '@osf/shared/services/json-api.service'; | ||
|
|
||
| import { MOCK_API_URL, provideMockEnvironment } from '@testing/providers/environment.provider.mock'; | ||
| import { JsonApiServiceMock, JsonApiServiceMockType } from '@testing/providers/json-api.service.mock'; | ||
|
|
||
| import { AccountSettingsService } from './account-settings.service'; | ||
|
|
||
| describe('AccountSettingsService', () => { | ||
| let service: AccountSettingsService; | ||
| let jsonApiService: JsonApiServiceMockType; | ||
|
|
||
| beforeEach(() => { | ||
| jsonApiService = JsonApiServiceMock.simple(); | ||
|
|
||
| TestBed.configureTestingModule({ | ||
| providers: [ | ||
| AccountSettingsService, | ||
| provideMockEnvironment(), | ||
| { provide: JsonApiService, useValue: jsonApiService }, | ||
| ], | ||
| }); | ||
|
|
||
| service = TestBed.inject(AccountSettingsService); | ||
| }); | ||
|
|
||
| it('should delete an external identity with the error interceptor bypassed', () => { | ||
| service.deleteExternalIdentity('orcid').subscribe(); | ||
|
|
||
| expect(jsonApiService.delete).toHaveBeenCalledTimes(1); | ||
| const [url, , , context] = jsonApiService.delete.mock.calls[0]; | ||
| expect(url).toBe(`${MOCK_API_URL}/users/me/settings/identities/orcid/`); | ||
| expect(context?.get(BYPASS_ERROR_INTERCEPTOR)).toBe(true); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...pp/features/settings/account-settings/services/external-identity-deletion.service.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import { Store } from '@ngxs/store'; | ||
|
|
||
| import { MockProvider } from 'ng-mocks'; | ||
|
|
||
| import { throwError } from 'rxjs'; | ||
|
|
||
| import { Mock } from 'vitest'; | ||
|
|
||
| import { HttpErrorResponse } from '@angular/common/http'; | ||
| import { TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { CustomConfirmationService } from '@osf/shared/services/custom-confirmation.service'; | ||
| import { LoaderService } from '@osf/shared/services/loader.service'; | ||
| import { ToastService } from '@osf/shared/services/toast.service'; | ||
|
|
||
| import { provideOSFCore } from '@testing/osf.testing.provider'; | ||
| import { | ||
| CustomConfirmationServiceMock, | ||
| CustomConfirmationServiceMockType, | ||
| } from '@testing/providers/custom-confirmation-provider.mock'; | ||
| import { LoaderServiceMock } from '@testing/providers/loader-service.mock'; | ||
| import { provideMockStore } from '@testing/providers/store-provider.mock'; | ||
| import { ToastServiceMock, ToastServiceMockType } from '@testing/providers/toast-provider.mock'; | ||
|
|
||
| import { DeleteExternalIdentity } from '../store'; | ||
|
|
||
| import { ExternalIdentityDeletionService } from './external-identity-deletion.service'; | ||
|
|
||
| describe('ExternalIdentityDeletionService', () => { | ||
| let service: ExternalIdentityDeletionService; | ||
| let store: Store; | ||
| let loaderService: LoaderServiceMock; | ||
| let confirmationService: CustomConfirmationServiceMockType; | ||
| let toastService: ToastServiceMockType; | ||
|
|
||
| const identityId = 'ORCID'; | ||
|
|
||
| const confirm = () => { | ||
| const { onConfirm } = confirmationService.confirmDelete.mock.calls[0][0]; | ||
| onConfirm(); | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| loaderService = new LoaderServiceMock(); | ||
| confirmationService = CustomConfirmationServiceMock.simple(); | ||
| toastService = ToastServiceMock.simple(); | ||
|
|
||
| TestBed.configureTestingModule({ | ||
| providers: [ | ||
| provideOSFCore(), | ||
| MockProvider(LoaderService, loaderService), | ||
| MockProvider(CustomConfirmationService, confirmationService), | ||
| MockProvider(ToastService, toastService), | ||
| provideMockStore(), | ||
| ], | ||
| }); | ||
|
|
||
| store = TestBed.inject(Store); | ||
| service = TestBed.inject(ExternalIdentityDeletionService); | ||
| }); | ||
|
|
||
| it('should open delete confirmation with expected payload', () => { | ||
| service.confirmAndDelete(identityId); | ||
|
|
||
| expect(confirmationService.confirmDelete).toHaveBeenCalledWith({ | ||
| headerKey: 'settings.accountSettings.connectedIdentities.deleteDialog.header', | ||
| messageParams: { name: identityId }, | ||
| messageKey: 'settings.accountSettings.connectedIdentities.deleteDialog.message', | ||
| onConfirm: expect.any(Function), | ||
| }); | ||
| }); | ||
|
|
||
| it('should not dispatch delete until confirmation is accepted', () => { | ||
| (store.dispatch as Mock).mockClear(); | ||
| service.confirmAndDelete(identityId); | ||
|
|
||
| expect(loaderService.show).not.toHaveBeenCalled(); | ||
| expect(store.dispatch).not.toHaveBeenCalled(); | ||
| expect(toastService.showSuccess).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should dispatch delete and show success when confirmation is accepted', () => { | ||
| (store.dispatch as Mock).mockClear(); | ||
| service.confirmAndDelete(identityId); | ||
| confirm(); | ||
|
|
||
| expect(loaderService.show).toHaveBeenCalled(); | ||
| expect(store.dispatch).toHaveBeenCalledWith(new DeleteExternalIdentity(identityId)); | ||
| expect(toastService.showSuccess).toHaveBeenCalledWith('settings.accountSettings.connectedIdentities.successDelete'); | ||
| expect(toastService.showError).not.toHaveBeenCalled(); | ||
| expect(loaderService.hide).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it.each([ | ||
| [503, 'settings.accountSettings.connectedIdentities.errors.retryLater'], | ||
| [409, 'settings.accountSettings.connectedIdentities.errors.signInViaOrcid'], | ||
| [500, 'settings.accountSettings.connectedIdentities.errors.contactSupport'], | ||
| [404, 'settings.accountSettings.connectedIdentities.errors.contactSupport'], | ||
| ])('should show the matching error toast for status %i', (status, messageKey) => { | ||
| (store.dispatch as Mock).mockReturnValue(throwError(() => new HttpErrorResponse({ status }))); | ||
| service.confirmAndDelete(identityId); | ||
| confirm(); | ||
|
|
||
| expect(toastService.showError).toHaveBeenCalledWith(messageKey); | ||
| expect(toastService.showSuccess).not.toHaveBeenCalled(); | ||
| expect(loaderService.hide).toHaveBeenCalled(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.