Skip to content
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

[AAE-2718] List available roles for a group #5954

Merged
merged 5 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
84 changes: 18 additions & 66 deletions lib/core/mock/identity-group.service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,146 +18,98 @@
import { IdentityGroupModel, IdentityGroupCountModel } from '../models/identity-group.model';
import { IdentityRoleModel } from '../models/identity-role.model';

export let mockIdentityGroup1 = <IdentityGroupModel> {
export const mockIdentityGroup1 = <IdentityGroupModel> {
id: 'mock-group-id-1', name: 'Mock Group 1', path: '/mock', subGroups: []
};

export let mockIdentityGroup2 = <IdentityGroupModel> {
export const mockIdentityGroup2 = <IdentityGroupModel> {
id: 'mock-group-id-2', name: 'Mock Group 2', path: '', subGroups: []
};

export let mockIdentityGroup3 = <IdentityGroupModel> {
export const mockIdentityGroup3 = <IdentityGroupModel> {
id: 'mock-group-id-3', name: 'Mock Group 3', path: '', subGroups: []
};

export let mockIdentityGroup4 = <IdentityGroupModel> {
export const mockIdentityGroup4 = <IdentityGroupModel> {
id: 'mock-group-id-4', name: 'Mock Group 4', path: '', subGroups: []
};

export let mockIdentityGroup5 = <IdentityGroupModel> {
export const mockIdentityGroup5 = <IdentityGroupModel> {
id: 'mock-group-id-5', name: 'Mock Group 5', path: '', subGroups: []
};

export let mockIdentityGroupsCount = <IdentityGroupCountModel> { count: 10 };
export const mockIdentityGroupsCount = <IdentityGroupCountModel> { count: 10 };

export let mockIdentityGroups = [
export const mockIdentityGroups = [
mockIdentityGroup1, mockIdentityGroup2, mockIdentityGroup3, mockIdentityGroup4, mockIdentityGroup5
];

export let mockApplicationDetails = {id: 'mock-app-id', name: 'mock-app-name'};
export const mockApplicationDetails = {id: 'mock-app-id', name: 'mock-app-name'};

export let groupAPIMockError = {
error: {
errorKey: 'failed',
statusCode: 400,
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.'
}
};

export let mockApiError = {
oauth2Auth: {
callCustomApi: () => {
return Promise.reject(groupAPIMockError);
}
}
};

export let roleMappingMock = [
export const roleMappingMock = [
{ id: 'role-id-1', name: 'role-name-1' }, { id: 'role-id-2', name: 'role-name-2' }
];

export let roleMappingApi = {
export const roleMappingApi = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve(roleMappingMock);
}
}
};

export let noRoleMappingApi = {
export const noRoleMappingApi = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve([]);
}
}
};

export let groupsMockApi = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve(mockIdentityGroups);
}
}
};

export let getGroupsCountMockApi = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve(10);
}
}
};

export let queryGroupsMockApi = {
export const groupsMockApi = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve(mockIdentityGroups);
}
}
};

export let createGroupMappingApi = {
export const createGroupMappingApi = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve();
}
}
};

export let updateGroupMappingApi = {
export const updateGroupMappingApi = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve();
}
}
};

export let deleteGroupMappingApi = {
export const deleteGroupMappingApi = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve();
}
}
};

export let returnCallQueryParameters = {
oauth2Auth: {
callCustomApi: (_queryUrl, _operation, _context, queryParams) => {
return Promise.resolve(queryParams);
}
}
};

export let returnCallUrl = {
oauth2Auth: {
callCustomApi: (queryUrl) => {
return Promise.resolve(queryUrl);
}
}
};

export let applicationDetailsMockApi = {
export const applicationDetailsMockApi = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve([mockApplicationDetails]);
}
}
};

export let mockIdentityRoles = [
export const mockIdentityRoles = [
new IdentityRoleModel({id: 'mock-role-id', name: 'MOCK-ADMIN-ROLE'}),
new IdentityRoleModel({id: 'mock-role-id', name: 'MOCK-USER-ROLE'}),
new IdentityRoleModel({id: 'mock-role-id', name: 'MOCK-ROLE-1'})
];

export let clientRoles = [ 'MOCK-ADMIN-ROLE', 'MOCK-USER-ROLE'];
export const clientRoles = [ 'MOCK-ADMIN-ROLE', 'MOCK-USER-ROLE'];
40 changes: 1 addition & 39 deletions lib/core/services/identity-group.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@
*/

import { async, TestBed } from '@angular/core/testing';
import {
setupTestBed,
AlfrescoApiService,
LogService,
IdentityGroupService,
IdentityGroupSearchParam,
groupAPIMockError
} from '@alfresco/adf-core';
import { setupTestBed, AlfrescoApiService, IdentityGroupService, IdentityGroupSearchParam } from '@alfresco/adf-core';
import { HttpErrorResponse } from '@angular/common/http';
import { throwError, of } from 'rxjs';
import {
Expand All @@ -33,7 +26,6 @@ import {
roleMappingApi,
clientRoles,
applicationDetailsMockApi,
mockApiError,
mockIdentityGroup1,
createGroupMappingApi,
updateGroupMappingApi,
Expand All @@ -46,7 +38,6 @@ import { TranslateModule } from '@ngx-translate/core';
describe('IdentityGroupService', () => {
let service: IdentityGroupService;
let apiService: AlfrescoApiService;
let logService: LogService;

setupTestBed({
imports: [
Expand All @@ -58,7 +49,6 @@ describe('IdentityGroupService', () => {
beforeEach(async(() => {
service = TestBed.inject(IdentityGroupService);
apiService = TestBed.inject(AlfrescoApiService);
logService = TestBed.inject(LogService);
}));

it('should be able to fetch groups based on group name', (done) => {
Expand Down Expand Up @@ -231,18 +221,6 @@ describe('IdentityGroupService', () => {
);
});

it('should return only the properties of IdentityGroupSearchParam', (done) => {
spyOn(apiService, 'getInstance').and.returnValue(groupsMockApi);
service.findGroupsByName(<IdentityGroupSearchParam> {name: 'mock'}).subscribe((groups) => {
expect(groups).toBeDefined();
expect(groups).toBeDefined();
expect(groups[0].id).toEqual('mock-group-id-1');
expect(groups[0].name).toEqual('Mock Group 1');
expect(groups[0]['subGroups']).not.toBeDefined();
done();
});
});

it('should be able to fetch the client id', (done) => {
spyOn(apiService, 'getInstance').and.returnValue(applicationDetailsMockApi);
service.getClientIdByApplicationName('mock-app-name').subscribe((clientId) => {
Expand All @@ -253,25 +231,9 @@ describe('IdentityGroupService', () => {
});
});

it('should notify errors returned from the API', (done) => {
const logServiceSpy = spyOn(logService, 'error').and.callThrough();
spyOn(apiService, 'getInstance').and.returnValue(mockApiError);
service.findGroupsByName(<IdentityGroupSearchParam> {name: 'mock'}).subscribe(
() => {},
(res: any) => {
expect(res).toBeDefined();
expect(res).toEqual(groupAPIMockError);
expect(logServiceSpy).toHaveBeenCalled();
done();
}
);
});

it('should be able to all fetch groups', (done) => {
spyOn(apiService, 'getInstance').and.returnValue(groupsMockApi);
service.getGroups().subscribe((res) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
expect(res.length).toBe(5);
expect(res[0].id).toBe('mock-group-id-1');
expect(res[0].name).toBe('Mock Group 1');
Expand Down