diff --git a/src/aims-client.ts b/src/aims-client.ts index d6d105e..868ff41 100644 --- a/src/aims-client.ts +++ b/src/aims-client.ts @@ -97,39 +97,65 @@ export class AIMSClientInstance { } /** + * @deprecated use getAccountsByRelationship * List managed accounts * GET * /aims/v1/:account_id/accounts/:relationship * "https://api.cloudinsight.alertlogic.com/aims/v1/12345678/accounts/managed" */ async getManagedAccounts(accountId: string, queryParams?):Promise { - const managedAccounts = await this.client.get({ + return this.getAccountsByRelationship(accountId, 'managed', queryParams ); + } + + /** + * @deprecated use getAccountIdsByRelationship + * List managed account IDs + * GET + * /aims/v1/:account_id/account_ids/:relationship + * "https://api.cloudinsight.alertlogic.com/aims/v1/12345678/account_ids/managed" + */ + async getManagedAccountIds(accountId: string, queryParams?):Promise { + return this.getAccountIdsByRelationship(accountId, 'managed', queryParams ); + } + + /** + * List account IDs, by relationship can be managing, managed and bills_to + * GET + * /aims/v1/:account_id/account_ids/:relationship + * "https://api.cloudinsight.alertlogic.com/aims/v1/12345678/account_ids/managing" + * "https://api.cloudinsight.alertlogic.com/aims/v1/12345678/account_ids/managed" + * "https://api.cloudinsight.alertlogic.com/aims/v1/12345678/account_ids/bills_to" + */ + async getAccountIdsByRelationship(accountId: string, relationship: string, queryParams?):Promise { + const accountIds = await this.client.get({ service_name: this.serviceName, account_id: accountId, - path: '/accounts/managed', + path: `/account_ids/${relationship}`, params: queryParams, retry_count: 5, ttl: 2 * 60 * 1000 }); - return managedAccounts.accounts as AIMSAccount[]; + return accountIds.account_ids as string[]; } /** - * List managed account IDs + * List accounts, by relationship can be managing, managed and bills_to * GET - * /aims/v1/:account_id/account_ids/:relationship - * "https://api.cloudinsight.alertlogic.com/aims/v1/12345678/account_ids/managed" + * /aims/v1/:account_id/accounts/:relationship + * "https://api.cloudinsight.alertlogic.com/aims/v1/12345678/accounts/managing" + * "https://api.cloudinsight.alertlogic.com/aims/v1/12345678/accounts/managed" + * "https://api.cloudinsight.alertlogic.com/aims/v1/12345678/accounts/bills_to" */ - async getManagedAccountIds(accountId: string, queryParams?):Promise { - const managedAccountIds = await this.client.get({ + async getAccountsByRelationship(accountId: string, relationship: string, queryParams?):Promise { + const managedAccounts = await this.client.get({ service_name: this.serviceName, account_id: accountId, - path: '/account_ids/managed', + path: `/accounts/${relationship}`, params: queryParams, retry_count: 5, ttl: 2 * 60 * 1000 }); - return managedAccountIds.account_ids as string[]; + return managedAccounts.accounts as AIMSAccount[]; } /** diff --git a/test/aims-client.spec.ts b/test/aims-client.spec.ts index e627a7b..385202a 100644 --- a/test/aims-client.spec.ts +++ b/test/aims-client.spec.ts @@ -97,6 +97,24 @@ describe('AIMS Client Test Suite:', () => { expect( payload.url ).to.equal( `${apiBaseURL}/aims/v1/${accountId}/account_ids/managed` ); }); }); + describe('when retrieving managing account Id', () => { + it('should call fetch() on the ALClient instance with a correctly constructed payload', async() => { + await AIMSClient.getAccountIdsByRelationship(accountId,'managing', queryParams); + expect(stub.callCount).to.equal(1); + const payload = stub.args[0][0]; + expect( payload.method ).to.equal( "GET" ); + expect( payload.url ).to.equal( `${apiBaseURL}/aims/v1/${accountId}/account_ids/managing` ); + }); + }); + describe('when retrieving managing accounts', () => { + it('should call fetch() on the ALClient instance with a correctly constructed payload', async() => { + await AIMSClient.getAccountsByRelationship(accountId,'managing', queryParams); + expect(stub.callCount).to.equal(1); + const payload = stub.args[0][0]; + expect( payload.method ).to.equal( "GET" ); + expect( payload.url ).to.equal( `${apiBaseURL}/aims/v1/${accountId}/accounts/managing` ); + }); + }); describe('when enabling MFA for a user account', () => { it('should call post() on the ALClient instance with a correctly constructed payload', async() => { await AIMSClient.requireMFA(accountId, true);