-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from coveo/ADUI-4776/add-organizations-resource
feat(organizations): implement the base paths for the organizations resource
- Loading branch information
Showing
9 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './LicenseInterfaces'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './Organization'; | ||
export * from './OrganizationInterfaces'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters