-
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.
feat(UA-9179): add properties endpoints to client
- Loading branch information
1 parent
92d3e2b
commit b45fb12
Showing
7 changed files
with
158 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,72 @@ | ||
import Resource from '../../Resource.js'; | ||
import API from '../../../APICore.js'; | ||
import {PageModel, Paginated} from '../../BaseInterfaces.js'; | ||
import {PropertiesResponseMessage, PropertyModel} from './PropertiesInterfaces.js'; | ||
|
||
export default class Properties extends Resource { | ||
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/analyticsadmin/v1`; | ||
/** | ||
* Build the request path, handling the optional `org` query parameter. | ||
* | ||
* @param route The path part of the request. | ||
* @param queryParams Optional query parameters object. | ||
* If this object contains an `org` property, it will override the value from the configuration. | ||
* @returns The request path including formatted query parameters. | ||
*/ | ||
protected buildPathWithOrg(route: string, queryParams?: any): string { | ||
return super.buildPath(route, {org: this.api.organizationId, ...queryParams}); | ||
} | ||
|
||
/** | ||
* List all properties | ||
* | ||
* @returns Promise<PageModel<PropertyModel>> | ||
*/ | ||
listProperties(pagination?: Paginated): Promise<PageModel<PropertyModel>> { | ||
return this.api.get<PageModel<PropertyModel>>( | ||
this.buildPathWithOrg(`${Properties.baseUrl}/properties/list`, pagination), | ||
); | ||
} | ||
|
||
/** | ||
* Get a property | ||
* | ||
* @returns Promise<PropertyModel> | ||
*/ | ||
getProperty(trackingId: string): Promise<PropertyModel> { | ||
return this.api.get<PropertyModel>(this.buildPathWithOrg(`${Properties.baseUrl}/properties/${trackingId}`)); | ||
} | ||
|
||
/** | ||
* Create a property | ||
* | ||
* @returns Promise<PropertiesResponseMessage> | ||
*/ | ||
createProperty(trackingId: string, displayName: string): Promise<PropertiesResponseMessage> { | ||
return this.api.post<PropertiesResponseMessage>( | ||
this.buildPathWithOrg(`${Properties.baseUrl}/properties/${trackingId}`, {displayName}), | ||
); | ||
} | ||
|
||
/** | ||
* Edit a property | ||
* | ||
* @returns Promise<PropertiesResponseMessage> | ||
*/ | ||
updateProperty(trackingId: string, displayName: string): Promise<PropertiesResponseMessage> { | ||
return this.api.put<PropertiesResponseMessage>( | ||
this.buildPathWithOrg(`${Properties.baseUrl}/properties/${trackingId}`, {displayName}), | ||
); | ||
} | ||
|
||
/** | ||
* Delete a property | ||
* | ||
* @returns Promise<PropertiesResponseMessage> | ||
*/ | ||
deleteProperty(trackingId: string): Promise<PropertiesResponseMessage> { | ||
return this.api.delete<PropertiesResponseMessage>( | ||
this.buildPathWithOrg(`${Properties.baseUrl}/properties/${trackingId}`), | ||
); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/resources/AnalyticsAdmin/Properties/PropertiesInterfaces.ts
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,8 @@ | ||
export interface PropertyModel { | ||
trackingId: string; | ||
displayName: string; | ||
} | ||
|
||
export interface PropertiesResponseMessage { | ||
message: 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 './Properties.js'; | ||
export * from './PropertiesInterfaces.js'; |
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 './Properties/index.js'; |
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,71 @@ | ||
import API from '../../../APICore.js'; | ||
import Properties from '../Properties/Properties.js'; | ||
|
||
jest.mock('../../../APICore.js'); | ||
|
||
const APIMock: jest.Mock<API> = API as any; | ||
|
||
describe('Properties', () => { | ||
let properties: Properties; | ||
const api = new APIMock() as jest.Mocked<API>; | ||
const serverlessApi = new APIMock() as jest.Mocked<API>; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
properties = new Properties(api, serverlessApi); | ||
}); | ||
|
||
describe('listProperties', () => { | ||
it('should make a GET call to the Properties list path', () => { | ||
properties.listProperties(); | ||
|
||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${Properties.baseUrl}/properties/list`); | ||
}); | ||
|
||
it('should make a GET call to the Properties list path with pagination', () => { | ||
properties.listProperties({page: 1, perPage: 2}); | ||
|
||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${Properties.baseUrl}/properties/list?page=1&perPage=2`); | ||
}); | ||
}); | ||
|
||
describe('getProperty', () => { | ||
it('should make a GET call to the properties path', () => { | ||
properties.getProperty('trackingId'); | ||
|
||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${Properties.baseUrl}/properties/trackingId`); | ||
}); | ||
}); | ||
|
||
describe('createProperty', () => { | ||
it('should make a POST call to the properties path', () => { | ||
properties.createProperty('trackingId', 'displayName'); | ||
|
||
expect(api.post).toHaveBeenCalledTimes(1); | ||
expect(api.post).toHaveBeenCalledWith( | ||
`${Properties.baseUrl}/properties/trackingId?displayName=displayName`, | ||
); | ||
}); | ||
}); | ||
|
||
describe('updateProperty', () => { | ||
it('should make a PUT call to the properties path', () => { | ||
properties.updateProperty('trackingId', 'displayName'); | ||
|
||
expect(api.put).toHaveBeenCalledTimes(1); | ||
expect(api.put).toHaveBeenCalledWith(`${Properties.baseUrl}/properties/trackingId?displayName=displayName`); | ||
}); | ||
}); | ||
|
||
describe('deleteProperty', () => { | ||
it('should make a DELETE call to the properties path', () => { | ||
properties.deleteProperty('trackingId'); | ||
|
||
expect(api.delete).toHaveBeenCalledTimes(1); | ||
expect(api.delete).toHaveBeenCalledWith(`${Properties.baseUrl}/properties/trackingId`); | ||
}); | ||
}); | ||
}); |
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