-
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 (#839)
* feat(UA-9179): add properties endpoints to client * feat(UA-9179): add filter to list endpoint + apply review * feat(UA-9179): fix path to BaseInterfaces * feat(UA-9179): fix import path (again)
- Loading branch information
1 parent
bd581dc
commit b744a5b
Showing
7 changed files
with
171 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} from '../../BaseInterfaces.js'; | ||
import {ListPropertiesParams, 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>> | ||
*/ | ||
list(params?: ListPropertiesParams): Promise<PageModel<PropertyModel>> { | ||
return this.api.get<PageModel<PropertyModel>>( | ||
this.buildPathWithOrg(`${Properties.baseUrl}/properties/list`, params), | ||
); | ||
} | ||
|
||
/** | ||
* Get a property | ||
* | ||
* @returns Promise<PropertyModel> | ||
*/ | ||
get(trackingId: string): Promise<PropertyModel> { | ||
return this.api.get<PropertyModel>(this.buildPathWithOrg(`${Properties.baseUrl}/properties/${trackingId}`)); | ||
} | ||
|
||
/** | ||
* Create a property | ||
* | ||
* @returns Promise<PropertiesResponseMessage> | ||
*/ | ||
create(trackingId: string, displayName: string): Promise<PropertiesResponseMessage> { | ||
return this.api.post<PropertiesResponseMessage>( | ||
this.buildPathWithOrg(`${Properties.baseUrl}/properties/${trackingId}`, {displayName}), | ||
); | ||
} | ||
|
||
/** | ||
* Edit a property | ||
* | ||
* @returns Promise<PropertiesResponseMessage> | ||
*/ | ||
update(trackingId: string, displayName: string): Promise<PropertiesResponseMessage> { | ||
return this.api.put<PropertiesResponseMessage>( | ||
this.buildPathWithOrg(`${Properties.baseUrl}/properties/${trackingId}`, {displayName}), | ||
); | ||
} | ||
|
||
/** | ||
* Delete a property | ||
* | ||
* @returns Promise<PropertiesResponseMessage> | ||
*/ | ||
delete(trackingId: string): Promise<PropertiesResponseMessage> { | ||
return this.api.delete<PropertiesResponseMessage>( | ||
this.buildPathWithOrg(`${Properties.baseUrl}/properties/${trackingId}`), | ||
); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
import {Paginated} from '../../BaseInterfaces.js'; | ||
|
||
export interface PropertyModel { | ||
trackingId: string; | ||
displayName: string; | ||
} | ||
|
||
export interface PropertiesResponseMessage { | ||
message: string; | ||
} | ||
|
||
export interface ListPropertiesParams extends Paginated { | ||
filter?: 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,78 @@ | ||
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 list path', () => { | ||
properties.list(); | ||
|
||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${Properties.baseUrl}/properties/list`); | ||
}); | ||
|
||
it('should make a GET call to the list path with pagination', () => { | ||
properties.list({page: 1, perPage: 2}); | ||
|
||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${Properties.baseUrl}/properties/list?page=1&perPage=2`); | ||
}); | ||
|
||
it('should make a GET call to the list path with filter', () => { | ||
properties.list({filter: 'test'}); | ||
|
||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${Properties.baseUrl}/properties/list?filter=test`); | ||
}); | ||
}); | ||
|
||
describe('getProperty', () => { | ||
it('should make a GET call to the properties path', () => { | ||
properties.get('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.create('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.update('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.delete('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