Skip to content

Commit

Permalink
Merge pull request #63 from coveo/organization-status
Browse files Browse the repository at this point in the history
Add organization status call and options for GET organization
  • Loading branch information
francoislg authored Jan 9, 2020
2 parents 770fceb + 9928651 commit 8ae4b11
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
16 changes: 13 additions & 3 deletions src/resources/Organizations/Organization.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import API from '../../APICore';
import {PageModel, PrivilegeModel} from '../BaseInterfaces';
import Resource from '../Resource';
import {CreateOrganizationOptions, ListOrganizationOptions, OrganizationModel} from './OrganizationInterfaces';
import {
CreateOrganizationOptions,
GetOrganizationOptions,
ListOrganizationOptions,
OrganizationModel,
OrganizationsStatusModel,
} from './OrganizationInterfaces';

export default class Organization extends Resource {
static baseUrl = '/rest/organizations';
Expand All @@ -18,14 +24,18 @@ export default class Organization extends Resource {
return this.api.delete(`${Organization.baseUrl}/${organizationId}`);
}

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

update(organization: Partial<OrganizationModel>) {
return this.api.put<OrganizationModel>(`${Organization.baseUrl}/${organization.id}`, organization);
}

status(organizationId: string = API.orgPlaceholder) {
return this.api.get<OrganizationsStatusModel>(`${Organization.baseUrl}/${organizationId}/status`);
}

listPrivileges() {
return this.api.get<PrivilegeModel[]>(`${Organization.baseUrl}/${API.orgPlaceholder}/privileges`);
}
Expand Down
12 changes: 9 additions & 3 deletions src/resources/Organizations/OrganizationInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ export interface OrganizationModel {
id: string;
displayName: string;
createdDate: number;
license: LicenseModel;
organizationStatusModel: OrganizationsStatusModel;
publicContentOnly: boolean;
type: string;
owner: {
email: string;
};
readOnly: boolean;
license?: LicenseModel;
organizationStatusModel?: OrganizationsStatusModel;
}

export type AdditionalOrganizationField = 'status' | 'license' | string;

export interface GetOrganizationOptions {
additionalFields?: AdditionalOrganizationField | AdditionalOrganizationField[];
}

export interface ListOrganizationOptions {
additionalFields?: string | string[];
additionalFields?: AdditionalOrganizationField | AdditionalOrganizationField[];
filter?: string;
order?: string;
page?: number;
Expand Down
37 changes: 37 additions & 0 deletions src/resources/Organizations/tests/Organizations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ describe('Organization', () => {
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${Organization.baseUrl}/${organizationToGetId}`);
});

it('should make a GET call with the specified options', () => {
const organizationToGetId = 'Organization-to-be-fetched';
organization.get(organizationToGetId, {
additionalFields: 'status',
});
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(
`${Organization.baseUrl}/${organizationToGetId}?additionalFields=status`
);
});

it('should make a GET call with the multiple additional fields', () => {
const organizationToGetId = 'Organization-to-be-fetched';
organization.get(organizationToGetId, {
additionalFields: ['status', 'license'],
});
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(
`${Organization.baseUrl}/${organizationToGetId}?additionalFields=status%2Clicense`
);
});
});

describe('update', () => {
Expand All @@ -63,6 +85,21 @@ describe('Organization', () => {
});
});

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

it('should make a GET call to /rest/organizations/{organizationName}/status if the orgId is not specified', () => {
organization.status();
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`/rest/organizations/{organizationName}/status`);
});
});

describe('listPrivileges', () => {
it('should make a GET call /rest/organizations/{organizationName}/privileges', () => {
organization.listPrivileges();
Expand Down

0 comments on commit 8ae4b11

Please sign in to comment.