mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[AAE-12501] Fix process-services-cloud unit tests
This commit is contained in:
@@ -16,8 +16,6 @@
|
||||
*/
|
||||
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { throwError } from 'rxjs';
|
||||
import { IdentityGroupModel } from '../models/identity-group.model';
|
||||
import { IdentityGroupFilterInterface } from '../services/identity-group-filter.interface';
|
||||
|
||||
export const mockSearchGroupByRoles: IdentityGroupFilterInterface = {
|
||||
@@ -35,23 +33,7 @@ export const mockSearchGroupByApp: IdentityGroupFilterInterface = {
|
||||
withinApplication: 'fake-app-name'
|
||||
};
|
||||
|
||||
export function oAuthMockApiWithIdentityGroups(groups: IdentityGroupModel[]) {
|
||||
return {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => Promise.resolve(groups)
|
||||
},
|
||||
reply: jasmine.createSpy('reply')
|
||||
};
|
||||
}
|
||||
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
export const mockHttpErrorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
});
|
||||
|
||||
export const oAuthMockApiWithError = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => throwError(errorResponse)
|
||||
},
|
||||
reply: jasmine.createSpy('reply')
|
||||
};
|
||||
|
||||
@@ -17,22 +17,23 @@
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { AlfrescoApiService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module';
|
||||
import { IdentityGroupService } from './identity-group.service';
|
||||
import {
|
||||
mockHttpErrorResponse,
|
||||
mockSearchGroupByApp,
|
||||
mockSearchGroupByRoles,
|
||||
mockSearchGroupByRolesAndApp,
|
||||
oAuthMockApiWithError,
|
||||
oAuthMockApiWithIdentityGroups
|
||||
mockSearchGroupByRolesAndApp
|
||||
} from '../mock/identity-group.service.mock';
|
||||
import { mockFoodGroups } from '../mock/group-cloud.mock';
|
||||
import { AdfHttpClient } from '@alfresco/adf-core/api';
|
||||
|
||||
describe('IdentityGroupService', () => {
|
||||
|
||||
let service: IdentityGroupService;
|
||||
let alfrescoApiService: AlfrescoApiService;
|
||||
let adfHttpClient: AdfHttpClient;
|
||||
let requestSpy: jasmine.Spy;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
@@ -43,13 +44,14 @@ describe('IdentityGroupService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.inject(IdentityGroupService);
|
||||
alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||
adfHttpClient = TestBed.inject(AdfHttpClient);
|
||||
requestSpy = spyOn(adfHttpClient, 'request');
|
||||
});
|
||||
|
||||
describe('Search', () => {
|
||||
|
||||
it('should fetch groups', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithIdentityGroups(mockFoodGroups )as any);
|
||||
requestSpy.and.returnValue(Promise.resolve(mockFoodGroups));
|
||||
const searchSpy = spyOn(service, 'search').and.callThrough();
|
||||
|
||||
service.search('fake').subscribe(
|
||||
@@ -65,7 +67,7 @@ describe('IdentityGroupService', () => {
|
||||
});
|
||||
|
||||
it('should not fetch groups if error occurred', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithError as any);
|
||||
requestSpy.and.returnValue(Promise.reject(mockHttpErrorResponse));
|
||||
|
||||
const searchSpy = spyOn(service, 'search').and.callThrough();
|
||||
|
||||
@@ -85,7 +87,7 @@ describe('IdentityGroupService', () => {
|
||||
});
|
||||
|
||||
it('should fetch groups by roles', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithIdentityGroups(mockFoodGroups) as any);
|
||||
requestSpy.and.returnValue(Promise.resolve(mockFoodGroups));
|
||||
const searchSpy = spyOn(service, 'search').and.callThrough();
|
||||
|
||||
service.search('fake', mockSearchGroupByRoles).subscribe(
|
||||
@@ -102,7 +104,7 @@ describe('IdentityGroupService', () => {
|
||||
});
|
||||
|
||||
it('should not fetch groups by roles if error occurred', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithError as any);
|
||||
requestSpy.and.returnValue(Promise.reject(mockHttpErrorResponse));
|
||||
const searchSpy = spyOn(service, 'search').and.callThrough();
|
||||
|
||||
service.search('fake', mockSearchGroupByRoles)
|
||||
@@ -125,7 +127,7 @@ describe('IdentityGroupService', () => {
|
||||
});
|
||||
|
||||
it('should fetch groups within app', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithIdentityGroups(mockFoodGroups) as any);
|
||||
requestSpy.and.returnValue(Promise.resolve(mockFoodGroups));
|
||||
|
||||
service.search('fake', mockSearchGroupByApp).subscribe(
|
||||
res => {
|
||||
@@ -140,7 +142,7 @@ describe('IdentityGroupService', () => {
|
||||
});
|
||||
|
||||
it('should fetch groups within app with roles', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithIdentityGroups(mockFoodGroups) as any);
|
||||
requestSpy.and.returnValue(Promise.resolve(mockFoodGroups));
|
||||
|
||||
service.search('fake', mockSearchGroupByRolesAndApp).subscribe(
|
||||
res => {
|
||||
@@ -156,7 +158,7 @@ describe('IdentityGroupService', () => {
|
||||
});
|
||||
|
||||
it('should not fetch groups within app if error occurred', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithError as any);
|
||||
requestSpy.and.returnValue(Promise.reject(mockHttpErrorResponse));
|
||||
const searchSpy = spyOn(service, 'search').and.callThrough();
|
||||
|
||||
service.search('fake', mockSearchGroupByApp)
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
*/
|
||||
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { throwError } from 'rxjs';
|
||||
import { IdentityUserModel } from '../models/identity-user.model';
|
||||
import { IdentityUserFilterInterface } from '../services/identity-user-filter.interface';
|
||||
|
||||
export const mockSearchUserEmptyFilters: IdentityUserFilterInterface = {
|
||||
@@ -68,23 +66,7 @@ export const mockSearchUserByAppAndGroups: IdentityUserFilterInterface = {
|
||||
withinApplication: 'fake-app-name'
|
||||
};
|
||||
|
||||
export function oAuthMockApiWithIdentityUsers(users: IdentityUserModel[]) {
|
||||
return {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => Promise.resolve(users)
|
||||
},
|
||||
reply: jasmine.createSpy('reply')
|
||||
} as any;
|
||||
}
|
||||
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
export const mockHttpErrorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
});
|
||||
|
||||
export const oAuthMockApiWithError = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => throwError(errorResponse)
|
||||
},
|
||||
reply: jasmine.createSpy('reply')
|
||||
} as any;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { AlfrescoApiService, JwtHelperService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { JwtHelperService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { IdentityUserService } from './identity-user.service';
|
||||
import { mockToken } from '../mock/jwt-helper.service.spec';
|
||||
import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module';
|
||||
@@ -28,16 +28,17 @@ import {
|
||||
mockSearchUserByGroupsAndRoles,
|
||||
mockSearchUserByGroupsAndRolesAndApp,
|
||||
mockSearchUserByRoles,
|
||||
mockSearchUserByRolesAndApp,
|
||||
oAuthMockApiWithError,
|
||||
oAuthMockApiWithIdentityUsers
|
||||
mockSearchUserByRolesAndApp
|
||||
} from '../mock/identity-user.service.mock';
|
||||
import { mockFoodUsers } from '../mock/people-cloud.mock';
|
||||
import { AdfHttpClient } from '@alfresco/adf-core/api';
|
||||
import { mockHttpErrorResponse } from '../../group/mock/identity-group.service.mock';
|
||||
|
||||
describe('IdentityUserService', () => {
|
||||
|
||||
let service: IdentityUserService;
|
||||
let alfrescoApiService: AlfrescoApiService;
|
||||
let adfHttpClient: AdfHttpClient;
|
||||
let requestSpy: jasmine.Spy;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
@@ -48,7 +49,8 @@ describe('IdentityUserService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.inject(IdentityUserService);
|
||||
alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||
adfHttpClient = TestBed.inject(AdfHttpClient);
|
||||
requestSpy = spyOn(adfHttpClient, 'request');
|
||||
});
|
||||
|
||||
describe('Current user info (JWT token)', () => {
|
||||
@@ -85,7 +87,7 @@ describe('IdentityUserService', () => {
|
||||
describe('Search', () => {
|
||||
|
||||
it('should fetch users', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithIdentityUsers(mockFoodUsers));
|
||||
requestSpy.and.returnValue(Promise.resolve(mockFoodUsers));
|
||||
const searchSpy = spyOn(service, 'search').and.callThrough();
|
||||
|
||||
service.search('fake').subscribe(
|
||||
@@ -101,7 +103,7 @@ describe('IdentityUserService', () => {
|
||||
});
|
||||
|
||||
it('should not fetch users if error occurred', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithError as any);
|
||||
requestSpy.and.returnValue(Promise.reject(mockHttpErrorResponse));
|
||||
|
||||
const searchSpy = spyOn(service, 'search').and.callThrough();
|
||||
|
||||
@@ -121,7 +123,7 @@ describe('IdentityUserService', () => {
|
||||
});
|
||||
|
||||
it('should fetch users by roles', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithIdentityUsers(mockFoodUsers));
|
||||
requestSpy.and.returnValue(Promise.resolve(mockFoodUsers));
|
||||
const searchSpy = spyOn(service, 'search').and.callThrough();
|
||||
|
||||
service.search('fake', mockSearchUserByRoles).subscribe(
|
||||
@@ -138,7 +140,7 @@ describe('IdentityUserService', () => {
|
||||
});
|
||||
|
||||
it('should not fetch users by roles if error occurred', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithError);
|
||||
requestSpy.and.returnValue(Promise.reject(mockHttpErrorResponse));
|
||||
|
||||
service.search('fake', mockSearchUserByRoles)
|
||||
.subscribe(
|
||||
@@ -155,7 +157,7 @@ describe('IdentityUserService', () => {
|
||||
});
|
||||
|
||||
it('should fetch users by groups', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithIdentityUsers(mockFoodUsers));
|
||||
requestSpy.and.returnValue(Promise.resolve(mockFoodUsers));
|
||||
const searchSpy = spyOn(service, 'search').and.callThrough();
|
||||
|
||||
service.search('fake', mockSearchUserByGroups).subscribe(
|
||||
@@ -172,7 +174,7 @@ describe('IdentityUserService', () => {
|
||||
});
|
||||
|
||||
it('should fetch users by roles with groups', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithIdentityUsers(mockFoodUsers));
|
||||
requestSpy.and.returnValue(Promise.resolve(mockFoodUsers));
|
||||
const searchSpy = spyOn(service, 'search').and.callThrough();
|
||||
|
||||
service.search('fake', mockSearchUserByGroupsAndRoles).subscribe(
|
||||
@@ -190,7 +192,7 @@ describe('IdentityUserService', () => {
|
||||
});
|
||||
|
||||
it('should fetch users by roles with groups and appName', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithIdentityUsers(mockFoodUsers));
|
||||
requestSpy.and.returnValue(Promise.resolve(mockFoodUsers));
|
||||
const searchSpy = spyOn(service, 'search').and.callThrough();
|
||||
|
||||
service.search('fake', mockSearchUserByGroupsAndRolesAndApp).subscribe(
|
||||
@@ -209,7 +211,7 @@ describe('IdentityUserService', () => {
|
||||
});
|
||||
|
||||
it('should not fetch users by groups if error occurred', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithError);
|
||||
requestSpy.and.returnValue(Promise.reject(mockHttpErrorResponse));
|
||||
|
||||
service.search('fake', mockSearchUserByGroups)
|
||||
.subscribe(
|
||||
@@ -226,7 +228,7 @@ describe('IdentityUserService', () => {
|
||||
});
|
||||
|
||||
it('should fetch users within app', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithIdentityUsers(mockFoodUsers));
|
||||
requestSpy.and.returnValue(Promise.resolve(mockFoodUsers));
|
||||
|
||||
service.search('fake', mockSearchUserByApp).subscribe(
|
||||
res => {
|
||||
@@ -241,7 +243,7 @@ describe('IdentityUserService', () => {
|
||||
});
|
||||
|
||||
it('should fetch users within app with roles', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithIdentityUsers(mockFoodUsers));
|
||||
requestSpy.and.returnValue(Promise.resolve(mockFoodUsers));
|
||||
|
||||
service.search('fake', mockSearchUserByRolesAndApp).subscribe(
|
||||
res => {
|
||||
@@ -257,7 +259,7 @@ describe('IdentityUserService', () => {
|
||||
});
|
||||
|
||||
it('should fetch users within app with groups', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithIdentityUsers(mockFoodUsers));
|
||||
requestSpy.and.returnValue(Promise.resolve(mockFoodUsers));
|
||||
const searchSpy = spyOn(service, 'search').and.callThrough();
|
||||
|
||||
service.search('fake', mockSearchUserByAppAndGroups).subscribe(
|
||||
@@ -275,7 +277,7 @@ describe('IdentityUserService', () => {
|
||||
});
|
||||
|
||||
it('should not fetch users within app if error occurred', (done) => {
|
||||
spyOn(alfrescoApiService, 'getInstance').and.returnValue(oAuthMockApiWithError);
|
||||
requestSpy.and.returnValue(Promise.reject(mockHttpErrorResponse));
|
||||
|
||||
service.search('fake', mockSearchUserByApp)
|
||||
.subscribe(
|
||||
|
||||
Reference in New Issue
Block a user