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