-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
520 additions
and
116 deletions.
There are no files selected for viewing
This file contains 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 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,90 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { provideMockActions } from '@ngrx/effects/testing'; | ||
import { Subject, Observable, of, ReplaySubject } from 'rxjs'; | ||
|
||
import { AdminCollectionEffects } from './admin-collection.effect'; | ||
import { AdminService } from '../service/admin.service'; | ||
import { Admin } from '../model/admin'; | ||
import { LoadAdminRequest, LoadAdminSuccess, UpdateAdminSuccess } from '../action/admin-collection.action'; | ||
import { AddNotification } from '../../notification/action/notification.action'; | ||
import { NotificationType, Notification } from '../../notification/model/notification'; | ||
|
||
describe('Admin Collection Effects', () => { | ||
let effects: AdminCollectionEffects; | ||
let actions: Subject<any>; | ||
|
||
let admin: Admin = { | ||
username: 'foo', | ||
firstName: 'bar', | ||
lastName: 'baz', | ||
role: 'ROLE_ADMIN', | ||
emailAddress: 'foo@bar.baz' | ||
}; | ||
|
||
let mockAdminService = { | ||
query: (): Observable<Admin[]> => of([admin]), | ||
queryByRole: (role: string): Observable<Admin[]> => of([admin]), | ||
update: (user: Admin): Observable<Admin> => of(admin), | ||
remove: (userId: string): Observable<boolean> => of(true) | ||
}; | ||
|
||
let adminService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [], | ||
providers: [ | ||
{ provide: AdminService, useValue: mockAdminService }, | ||
AdminCollectionEffects, | ||
provideMockActions(() => actions), | ||
], | ||
}); | ||
|
||
effects = TestBed.get(AdminCollectionEffects); | ||
adminService = TestBed.get(AdminService); | ||
}); | ||
|
||
describe(`loadAdminRequest$ effect`, () => { | ||
it('should load admins and fire a success action', () => { | ||
spyOn(adminService, 'query').and.returnValue(of([admin])); | ||
actions = new ReplaySubject(1); | ||
|
||
actions.next(new LoadAdminRequest()); | ||
|
||
effects.loadAdminRequest$.subscribe(result => { | ||
expect(result).toEqual(new LoadAdminSuccess([admin])); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('updateAdminRoleReload$ effect', () => { | ||
it('should reload the admins when the admin is updated', () => { | ||
actions = new ReplaySubject(1); | ||
|
||
actions.next(new UpdateAdminSuccess({id: 'foo', changes: { ...admin }})); | ||
|
||
effects.updateAdminRoleReload$.subscribe(result => { | ||
expect(result).toEqual(new LoadAdminRequest()); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('updateAdminRoleSuccess$', () => { | ||
it('should fire a notification to the notification service', () => { | ||
let payload = { id: 'foo', changes: { ...admin } }; | ||
actions = new ReplaySubject(1); | ||
|
||
actions.next(new UpdateAdminSuccess(payload)); | ||
|
||
effects.updateAdminRoleSuccess$.subscribe(result => { | ||
expect(result).toEqual(new AddNotification( | ||
new Notification( | ||
NotificationType.Success, | ||
`User update successful for ${payload.changes.username}`, | ||
5000 | ||
) | ||
)); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains 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
77 changes: 77 additions & 0 deletions
77
ui/src/app/admin/effect/metadata-collection.effect.spec.ts
This file contains 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,77 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { provideMockActions } from '@ngrx/effects/testing'; | ||
import { Subject, Observable, of, ReplaySubject } from 'rxjs'; | ||
import { StoreModule, combineReducers } from '@ngrx/store'; | ||
|
||
import { MetadataCollectionEffects } from './metadata-collection.effect'; | ||
import { LoadMetadataRequest, LoadMetadataSuccess } from '../action/metadata-collection.action'; | ||
import { ResolverService } from '../../metadata/domain/service/resolver.service'; | ||
import { Metadata } from '../../metadata/domain/domain.type'; | ||
import { MetadataResolver } from '../../metadata/domain/model'; | ||
import * as fromI18n from '../../i18n/reducer'; | ||
import { I18nService } from '../../i18n/service/i18n.service'; | ||
|
||
describe('Metadata Collection Effects', () => { | ||
let effects: MetadataCollectionEffects; | ||
let actions: Subject<any>; | ||
|
||
let md: Metadata = { | ||
serviceProviderName: 'foo', | ||
name: 'foo', | ||
type: 'bar', | ||
resourceId: 'foo', | ||
createdBy: 'admin' | ||
}; | ||
|
||
let resolverService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
StoreModule.forRoot({ | ||
'i18n': combineReducers(fromI18n.reducers), | ||
}) | ||
], | ||
providers: [ | ||
{ | ||
provide: ResolverService, | ||
useValue: jasmine.createSpyObj( | ||
'ResolverService', | ||
[ | ||
'queryForAdmin', | ||
'update', | ||
'remove' | ||
] | ||
) | ||
}, | ||
{ | ||
provide: I18nService, | ||
useValue: jasmine.createSpyObj( | ||
'I18nService', | ||
[ | ||
'translate' | ||
] | ||
) | ||
}, | ||
MetadataCollectionEffects, | ||
provideMockActions(() => actions), | ||
], | ||
}); | ||
|
||
effects = TestBed.get(MetadataCollectionEffects); | ||
resolverService = TestBed.get(ResolverService); | ||
}); | ||
|
||
describe(`loadMetadatas$ effect`, () => { | ||
it('should load admins and fire a success action', () => { | ||
resolverService.queryForAdmin.and.returnValue(of([md])); | ||
actions = new ReplaySubject(1); | ||
|
||
actions.next(new LoadMetadataRequest()); | ||
|
||
effects.loadMetadatas$.subscribe(result => { | ||
expect(result).toEqual(new LoadMetadataSuccess([md] as MetadataResolver[])); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 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 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,23 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { StoreModule } from '@ngrx/store'; | ||
import { EffectsModule } from '@ngrx/effects'; | ||
import { CoreModule } from './core.module'; | ||
import { UserService } from './service/user.service'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
|
||
describe('Core Module', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
StoreModule.forRoot({}), | ||
EffectsModule.forRoot([]), | ||
CoreModule.forRoot(), | ||
HttpClientModule | ||
] | ||
}); | ||
}); | ||
|
||
it('should compile', () => { | ||
expect(TestBed.get(UserService)).toBeDefined(); | ||
}); | ||
}); |
This file contains 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 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.