Skip to content

Commit

Permalink
Merge pull request #17 from coveo/ADUI-4776/add-organizations-resource
Browse files Browse the repository at this point in the history
feat(organizations): implement the base paths for the organizations resource
  • Loading branch information
GermainBergeron authored Oct 3, 2019
2 parents 1c36b7f + 0e4c62d commit 396e1f8
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/resources/License/LicenseInterfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export interface LicenseConnectorScheduleModel {
refreshType: string;
scheduleFrequencies: string[];
}

export interface LicenseConnectorModel {
allowed: boolean;
allowedSchedules: LicenseConnectorScheduleModel[];
sourceVisibilities: string[];
type: string;
}

export interface LicenseModel {
accountId: string;
accountName: string;
connectors: LicenseConnectorModel[];
department: string;
indexBackupType: string;
indexType: string;
monitoringLevel: string;
productEdition: string;
productName: string;
productType: string;
properties: any;
expirationDate: number;
type: string;
}
1 change: 1 addition & 0 deletions src/resources/License/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './LicenseInterfaces';
26 changes: 26 additions & 0 deletions src/resources/Organizations/Organization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Resource from '../Resource';
import {CreateOrganizationOptions, ListOrganizationOptions, OrganizationModel} from './OrganizationInterfaces';

export default class Organization extends Resource {
static baseUrl = '/rest/organizations/';

list(options?: ListOrganizationOptions) {
return this.api.get<OrganizationModel[]>(this.buildPath(Organization.baseUrl, options));
}

create(options: CreateOrganizationOptions) {
return this.api.post<OrganizationModel>(this.buildPath(Organization.baseUrl, options), {});
}

delete(organizationId: string) {
return this.api.delete(`${Organization.baseUrl}/${organizationId}`);
}

get(organizationId: string) {
return this.api.get<OrganizationModel>(`${Organization.baseUrl}/${organizationId}`);
}

update(organization: Partial<OrganizationModel>) {
return this.api.put<OrganizationModel>(`${Organization.baseUrl}/${organization.id}`, organization);
}
}
46 changes: 46 additions & 0 deletions src/resources/Organizations/OrganizationInterfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {LicenseModel} from '../License';

export interface OrganizationsStatusModel {
errorCodes: string[];
lifeCycleState: string;
pauseState: string;
paused: boolean;
provisioningStatus: {
currentProvisioningProgress: number;
initialProvisioningDone: boolean;
lastProvisioningCompletedDate: number;
ongoing: boolean;
status: string;
};
status: string;
supportActivated: boolean;
}

export interface OrganizationModel {
id: string;
displayName: string;
createdDate: number;
license: LicenseModel;
organizationStatusModel: OrganizationsStatusModel;
publicContentOnly: boolean;
type: string;
owner: {
email: string;
};
readOnly: boolean;
}

export interface ListOrganizationOptions {
additionalFields?: string[];
filter?: string;
order?: 'ASC' | 'DESC';
page?: number;
perPage?: number;
sortBy?: string;
}

export interface CreateOrganizationOptions {
name: string;
organizationTemplate?: string;
owner?: string;
}
2 changes: 2 additions & 0 deletions src/resources/Organizations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Organization';
export * from './OrganizationInterfaces';
65 changes: 65 additions & 0 deletions src/resources/Organizations/tests/Organizations.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import API from '../../../APICore';
import Organization from '../Organization';

jest.mock('../../../APICore');

const APIMock: jest.Mock<API> = API as any;

describe('Organization', () => {
let organization: Organization;
const api = new APIMock() as jest.Mocked<API>;

beforeEach(() => {
jest.clearAllMocks();
organization = new Organization(api);
});

describe('list', () => {
it('should make a GET call to the Organization base url', () => {
organization.list();
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(Organization.baseUrl);
});
});

describe('create', () => {
it('should make a POST call to the Organization base url with the parameters', () => {
const name = 'OrgName';

organization.create({name});
expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(`${Organization.baseUrl}?name=${name}`, {});
});
});

describe('delete', () => {
it('should make a DELETE call to the specific Organization url', () => {
const organizationToDeleteId = 'Organization-to-be-deleted';
organization.delete(organizationToDeleteId);
expect(api.delete).toHaveBeenCalledTimes(1);
expect(api.delete).toHaveBeenCalledWith(`${Organization.baseUrl}/${organizationToDeleteId}`);
});
});

describe('get', () => {
it('should make a GET call to the specific Organization url', () => {
const organizationToGetId = 'Organization-to-be-fetched';
organization.get(organizationToGetId);
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${Organization.baseUrl}/${organizationToGetId}`);
});
});

describe('update', () => {
it('should make a PUT call to the specific Organization url', () => {
const organizationModel = {
id: 'organization-to-update-id',
displayName: 'new name',
};

organization.update(organizationModel);
expect(api.put).toHaveBeenCalledTimes(1);
expect(api.put).toHaveBeenCalledWith(`${Organization.baseUrl}/${organizationModel.id}`, organizationModel);
});
});
});
3 changes: 3 additions & 0 deletions src/resources/PlatformResources.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import API from '../APICore';
import Catalog from './Catalogs/Catalog';
import Group from './Groups/Groups';
import Organization from './Organizations/Organization';
import Resource from './Resource';

const resourcesMap: Array<{key: string; resource: typeof Resource}> = [
{key: 'catalog', resource: Catalog},
{key: 'group', resource: Group},
{key: 'organization', resource: Organization},
];

class PlatformResources {
protected API: API;

catalog: Catalog;
group: Group;
organization: Organization;

registerAll() {
resourcesMap.forEach(({key, resource}) => {
Expand Down
2 changes: 2 additions & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export * from './BaseInterfaces';
export * from './PlatformResources';
export * from './Catalogs';
export * from './Groups';
export * from './Organizations';
export * from './License';
9 changes: 9 additions & 0 deletions src/resources/tests/PlatformResources.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Catalog from '../Catalogs/Catalog';
import Group from '../Groups/Groups';
import Organization from '../Organizations/Organization';
import PlatformResources from '../PlatformResources';

describe('PlatformResources', () => {
Expand All @@ -19,5 +20,13 @@ describe('PlatformResources', () => {
expect(platformResources.group).toBeDefined();
expect(platformResources.group).toBeInstanceOf(Group);
});

it('should register the organization resource on the platform instance', () => {
const platformResources = new PlatformResources();
platformResources.registerAll();

expect(platformResources.organization).toBeDefined();
expect(platformResources.organization).toBeInstanceOf(Organization);
});
});
});

0 comments on commit 396e1f8

Please sign in to comment.