Skip to content

Commit

Permalink
adding get account by relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
msanchezal committed Nov 7, 2019
1 parent 571b195 commit f803d48
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
46 changes: 36 additions & 10 deletions src/aims-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AIMSAccount[]> {
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<string[]> {
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<string[]> {
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<string[]> {
const managedAccountIds = await this.client.get({
async getAccountsByRelationship(accountId: string, relationship: string, queryParams?):Promise<AIMSAccount[]> {
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[];
}

/**
Expand Down
18 changes: 18 additions & 0 deletions test/aims-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f803d48

Please sign in to comment.