Skip to content

Commit

Permalink
SHIBUI-1031 Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jan 8, 2019
1 parent de4774a commit 64b6a11
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 75 deletions.
29 changes: 13 additions & 16 deletions ui/src/app/core/effect/user.effect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import { provideMockActions } from '@ngrx/effects/testing';
import { ReplaySubject } from 'rxjs/ReplaySubject';

import { UserEffects } from './user.effect';
import {
UserLoadRequestAction,
UserLoadSuccessAction,
UserLoadErrorAction
} from '../action/user.action';
import { Subject, of, throwError } from 'rxjs';
import { UserService } from '../service/user.service';
import { User } from '../model/user';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { LoadRoleSuccess, LoadRoleFail, LoadRoleRequest } from '../action/configuration.action';

describe('User Effects', () => {
let effects: UserEffects;
Expand All @@ -19,7 +15,9 @@ describe('User Effects', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [],
imports: [
HttpClientTestingModule
],
providers: [
UserEffects,
UserService,
Expand All @@ -32,26 +30,25 @@ describe('User Effects', () => {
});

it('should fire a success action', () => {
let user = {};
spyOn(userService, 'get').and.returnValue(of(user));
spyOn(userService, 'getRoles').and.returnValue(of(['ROLE_ADMIN']));
actions = new ReplaySubject(1);

actions.next(new UserLoadRequestAction());
actions.next(new LoadRoleRequest());

effects.loadUser$.subscribe(result => {
expect(result).toEqual(new UserLoadSuccessAction(user as User));
effects.loadRoles$.subscribe(result => {
expect(result).toEqual(new LoadRoleSuccess(['ROLE_ADMIN']));
});
});

it('should fire an error action', () => {
let err = new Error('404');
spyOn(userService, 'get').and.returnValue(throwError(err));
spyOn(userService, 'getRoles').and.returnValue(throwError(err));
actions = new ReplaySubject(1);

actions.next(new UserLoadRequestAction());
actions.next(new LoadRoleRequest());

effects.loadUser$.subscribe(result => {
expect(result).toEqual(new UserLoadErrorAction(err));
effects.loadRoles$.subscribe(result => {
expect(result).toEqual(new LoadRoleFail());
});
});
});
12 changes: 0 additions & 12 deletions ui/src/app/core/effect/user.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ import { UserService } from '../service/user.service';
@Injectable()
export class UserEffects {

@Effect()
loadUser$ = this.actions$.pipe(
ofType(user.USER_LOAD_REQUEST),
switchMap(() =>
this.userService.get()
.pipe(
map(u => new user.UserLoadSuccessAction({ ...u })),
catchError(error => of(new user.UserLoadErrorAction(error)))
)
)
);

@Effect()
loadRoles$ = this.actions$.pipe(
ofType<LoadRoleRequest>(ConfigurationActionTypes.LOAD_ROLE_REQUEST),
Expand Down
4 changes: 3 additions & 1 deletion ui/src/app/core/reducer/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as fromIndex from './index';
import * as fromUser from './user.reducer';
import * as fromVersion from './version.reducer';
import * as fromConfig from './configuration.reducer';
import { VersionInfo } from '../model/version';

describe('Core index reducers', () => {
const state: fromIndex.CoreState = {
user: fromUser.initialState as fromUser.UserState,
version: fromVersion.initialState as fromVersion.VersionState
version: fromVersion.initialState as fromVersion.VersionState,
config: fromConfig.initialState as fromConfig.ConfigState
};

describe('getUserStateFn function', () => {
Expand Down
5 changes: 4 additions & 1 deletion ui/src/app/core/service/user.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { TestBed, async, inject } from '@angular/core/testing';
import { HttpModule } from '@angular/http';
import { UserService } from './user.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';

describe('User Service', () => {
let service: UserService;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpModule],
imports: [
HttpClientTestingModule
],
providers: [
UserService
]
Expand Down
12 changes: 0 additions & 12 deletions ui/src/app/core/service/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ export class UserService {
private http: HttpClient
) { }

get(): Observable<User> {
const defUser = Object.assign({}, {
id: 'foo',
role: 'admin',
name: {
first: 'Ryan',
last: 'Mathis'
}
});
return of(defUser);
}

getRoles(): Observable<string[]> {
return this.http.get<string[]>(
`${this.base}/supportedRoles`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ describe('DynamicHttpMetadataProviderWizard', () => {
'/',
'/name',
'/xmlId',
'/metadataURL'
'/metadataRequestURLConstructionScheme',
'/metadataRequestURLConstructionScheme/content',
'/metadataRequestURLConstructionScheme/@type',
'/metadataRequestURLConstructionScheme/match'
]);
});
});
Expand Down
24 changes: 10 additions & 14 deletions ui/src/app/user/admin/reducer/collection.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ import { Admin } from '../model/admin';

let users = <Admin[]>[
{
resourceId: 'abc',
role: 'SUPER_ADMIN',
email: 'foo@bar.com',
name: {
first: 'Jane',
last: 'Doe'
}
username: 'abc',
role: 'ROLE_ADMIN',
emailAddress: 'foo@bar.com',
firstName: 'Jane',
lastName: 'Doe'
},
{
resourceId: 'def',
role: 'DELEGATED_ADMIN',
email: 'bar@baz.com',
name: {
first: 'John',
last: 'Doe'
}
username: 'def',
role: 'ROLE_USER',
emailAddress: 'bar@baz.com',
firstName: 'John',
lastName: 'Doe'
}
];

Expand Down
32 changes: 14 additions & 18 deletions ui/src/app/user/admin/service/admin.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@ import { Admin } from '../model/admin';

let users = <Admin[]>[
{
resourceId: 'abc',
role: 'SUPER_ADMIN',
email: 'foo@bar.com',
name: {
first: 'Jane',
last: 'Doe'
}
username: 'abc',
role: 'ROLE_ADMIN',
emailAddress: 'foo@bar.com',
firstName: 'Jane',
lastName: 'Doe'
},
{
resourceId: 'def',
role: 'DELEGATED_ADMIN',
email: 'bar@baz.com',
name: {
first: 'John',
last: 'Doe'
}
username: 'def',
role: 'ROLE_USER',
emailAddress: 'bar@baz.com',
firstName: 'John',
lastName: 'Doe'
}
];

Expand All @@ -47,7 +43,7 @@ describe('Admin Service', () => {
service.query().subscribe();

backend.expectOne((req: HttpRequest<any>) => {
return req.url === '/api/users'
return req.url === '/api/admin/users'
&& req.method === 'GET';
}, `GET admin collection`);
}
Expand All @@ -59,7 +55,7 @@ describe('Admin Service', () => {
service.update({...users[0]}).subscribe();

backend.expectOne((req: HttpRequest<any>) => {
return req.url === '/api/users/abc'
return req.url === '/api/admin/users/abc'
&& req.method === 'PUT';
}, `PUT admin user`);
}
Expand All @@ -68,10 +64,10 @@ describe('Admin Service', () => {
describe('remove method', () => {
it(`should send an expected delete request`, async(inject([AdminService, HttpTestingController],
(service: AdminService, backend: HttpTestingController) => {
service.remove(users[0].resourceId).subscribe();
service.remove(users[0].username).subscribe();

backend.expectOne((req: HttpRequest<any>) => {
return req.url === '/api/users/abc'
return req.url === '/api/admin/users/abc'
&& req.method === 'DELETE';
}, `DELETE admin user`);
}
Expand Down

0 comments on commit 64b6a11

Please sign in to comment.