-
Notifications
You must be signed in to change notification settings - Fork 1
LEGLINK-620: AddSecretKeytoVendor-UI #1778
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
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7329bd6
LEGLINK-620: record the vendor signing-key UI design
arianamihailescu 4b894e1
LEGLINK-620: associate a Key Vault secret with a vendor in the UI
arianamihailescu e2422c9
LEGLINK-620: report a failed vendor save once, and clear a key explicβ¦
arianamihailescu aa3af17
LEGLINK-620: cover the vendor create failure branch
arianamihailescu 1dad1c6
LEGLINK-620: gate vendor editing until an update endpoint exists
arianamihailescu fc64b4c
Merge branch 'dev' into LEGLINK-620
arianamihailescu 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
140 changes: 140 additions & 0 deletions
140
...dmin.UI/src/app/components/vendor/vendor-config-form/vendor-config-form.component.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,140 @@ | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
| import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
| import { MatDialogModule } from '@angular/material/dialog'; | ||
| import { MatSnackBarModule } from '@angular/material/snack-bar'; | ||
| import { of, throwError } from 'rxjs'; | ||
|
|
||
| import { VendorConfigFormComponent } from './vendor-config-form.component'; | ||
| import { VendorService } from '../../../services/gateway/vendor/vendor.service'; | ||
| import { FormMode } from '../../../models/FormMode.enum'; | ||
| import { IVendorConfigModel } from '../../../interfaces/vendor/vendor-config-model.interface'; | ||
|
|
||
| describe('VendorConfigFormComponent', () => { | ||
| let component: VendorConfigFormComponent; | ||
| let fixture: ComponentFixture<VendorConfigFormComponent>; | ||
| let vendorService: jasmine.SpyObj<VendorService>; | ||
|
|
||
| const epic: IVendorConfigModel = { id: 'vendor-1', name: 'Epic', secretId: 'epic-signing-pem' }; | ||
| const cerner: IVendorConfigModel = { id: 'vendor-2', name: 'Cerner' }; | ||
|
|
||
| beforeEach(async () => { | ||
| vendorService = jasmine.createSpyObj<VendorService>('VendorService', ['createVendor', 'updateVendor']); | ||
|
|
||
| await TestBed.configureTestingModule({ | ||
| imports: [VendorConfigFormComponent, NoopAnimationsModule, MatDialogModule, MatSnackBarModule], | ||
| providers: [{ provide: VendorService, useValue: vendorService }] | ||
| }).compileComponents(); | ||
|
|
||
| fixture = TestBed.createComponent(VendorConfigFormComponent); | ||
| component = fixture.componentInstance; | ||
| }); | ||
|
|
||
| /** ngOnInit reads `item`, so the inputs have to be set before the first change detection. */ | ||
| function initWith(item: IVendorConfigModel | undefined, formMode: FormMode): void { | ||
| component.item = item as IVendorConfigModel; | ||
| component.formMode = formMode; | ||
| fixture.detectChanges(); | ||
| } | ||
|
|
||
| it('populates the secret id from the item in Edit mode', () => { | ||
| initWith(epic, FormMode.Edit); | ||
|
|
||
| expect(component.name.value).toBe('Epic'); | ||
| expect(component.secretId.value).toBe('epic-signing-pem'); | ||
| }); | ||
|
|
||
| it('expands the key settings panel only when a secret id is already set', () => { | ||
| initWith(epic, FormMode.Edit); | ||
| expect(component.keySettingsExpanded).toBeTrue(); | ||
|
|
||
| // A second component, because keySettingsExpanded is decided once in ngOnInit. | ||
| const bare = TestBed.createComponent(VendorConfigFormComponent); | ||
| bare.componentInstance.item = cerner; | ||
| bare.componentInstance.formMode = FormMode.Edit; | ||
| bare.detectChanges(); | ||
|
|
||
| expect(bare.componentInstance.keySettingsExpanded).toBeFalse(); | ||
| }); | ||
|
|
||
| it('requires a name but not a secret id', () => { | ||
| initWith(cerner, FormMode.Edit); | ||
|
|
||
| expect(component.vendorForm.valid).toBeTrue(); | ||
|
|
||
| component.name.setValue(''); | ||
| expect(component.vendorForm.valid).toBeFalse(); | ||
| }); | ||
|
|
||
| it('sends the secret id when updating', () => { | ||
| vendorService.updateVendor.and.returnValue(of({ success: true, message: '' })); | ||
| initWith(cerner, FormMode.Edit); | ||
|
|
||
| component.secretId.setValue('cerner-signing-pem'); | ||
| component.submitConfiguration(); | ||
|
|
||
| expect(vendorService.updateVendor).toHaveBeenCalledWith( | ||
| jasmine.objectContaining({ id: 'vendor-2', name: 'Cerner', secretId: 'cerner-signing-pem' }) | ||
| ); | ||
| }); | ||
|
|
||
| it('clears the association by sending an explicit null, not undefined or ""', () => { | ||
| vendorService.updateVendor.and.returnValue(of({ success: true, message: '' })); | ||
| initWith(epic, FormMode.Edit); | ||
|
|
||
| component.secretId.setValue(' '); | ||
| component.submitConfiguration(); | ||
|
|
||
| const sent = vendorService.updateVendor.calls.mostRecent().args[0]; | ||
| expect(sent.secretId).toBeNull(); | ||
| // Undefined would be dropped by JSON.stringify, leaving the field absent from the request | ||
| // body -- indistinguishable from "leave it alone" for a partial-update endpoint. | ||
| expect('secretId' in sent).toBeTrue(); | ||
| expect(JSON.parse(JSON.stringify(sent)).secretId).toBeNull(); | ||
| }); | ||
|
|
||
| it('emits success after a saved update', () => { | ||
| vendorService.updateVendor.and.returnValue(of({ success: true, message: '' })); | ||
| initWith(epic, FormMode.Edit); | ||
|
|
||
| const outcomes: boolean[] = []; | ||
| component.submittedConfiguration.subscribe(o => outcomes.push(o.success)); | ||
|
|
||
| component.submitConfiguration(); | ||
|
|
||
| expect(outcomes).toEqual([true]); | ||
| }); | ||
|
|
||
| it('emits failure without closing when the update fails', () => { | ||
| vendorService.updateVendor.and.returnValue(throwError(() => new Error('boom'))); | ||
| initWith(epic, FormMode.Edit); | ||
|
|
||
| const outcomes: { success: boolean; message: string }[] = []; | ||
| component.submittedConfiguration.subscribe(o => outcomes.push(o)); | ||
|
|
||
| component.submitConfiguration(); | ||
|
|
||
| expect(outcomes.length).toBe(1); | ||
| expect(outcomes[0].success).toBeFalse(); | ||
| expect(outcomes[0].message).toBe('boom'); | ||
| }); | ||
|
|
||
| it('does not call the service while the form is invalid', () => { | ||
| initWith(cerner, FormMode.Edit); | ||
|
|
||
| component.name.setValue(''); | ||
| component.submitConfiguration(); | ||
|
|
||
| expect(vendorService.updateVendor).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('creates with the name only, leaving the secret id to a later edit', () => { | ||
| vendorService.createVendor.and.returnValue(of({ success: true })); | ||
| initWith(undefined, FormMode.Create); | ||
|
|
||
| component.name.setValue('Veradigm'); | ||
| component.submitConfiguration(); | ||
|
|
||
| expect(vendorService.createVendor).toHaveBeenCalledWith('Veradigm'); | ||
| expect(vendorService.updateVendor).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
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
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.