Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Usage Reports): add billing snapshot config service to usage reports #222

Merged
merged 4 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions examples/usage-reports.v4.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const authHelper = require('../test/resources/auth-helper.js');
// USAGE_REPORTS_RESOURCE_GROUP_ID=<the id of the resource group whose usage info will be retrieved>
// USAGE_REPORTS_ORG_ID=<the id of the organization whose usage info will be retrieved>
// USAGE_REPORTS_BILLING_MONTH=<the billing month (yyyy-mm) for which usage info will be retrieved>
// USAGE_REPORTS_COS_BUCKET=<The name of the COS bucket to store the snapshot of the billing reports.>
// USAGE_REPORTS_COS_LOCATION=<Region of the COS instance.>
// USAGE_REPORTS_DATE_FROM=<Timestamp in milliseconds for which billing report snapshot is requested.>
// USAGE_REPORTS_DATE_TO=<Timestamp in milliseconds for which billing report snapshot is requested.>
//
// These configuration properties can be exported as environment variables, or stored
// in a configuration file and then:
Expand Down Expand Up @@ -66,6 +70,10 @@ describe('UsageReportsV4', () => {
let resourceGroupId = config.resourceGroupId;
let orgId = config.orgId;
let billingMonth = config.billingMonth;
let cosBucket = config.cosBucket;
let cosLocation = config.cosLocation;
let snapshotDateFrom = config.snapshotDateFrom;
let snapshotDateTo = config.snapshotDateTo;

test('getAccountSummary request example', async () => {

Expand Down Expand Up @@ -267,4 +275,146 @@ describe('UsageReportsV4', () => {

// end-get_resource_usage_org
});
test('createReportsSnapshotConfig request example', async () => {
consoleLogMock.mockImplementation((output) => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
expect(true).toBeFalsy();
});

originalLog('createReportsSnapshotConfig() result:');
// begin-create_reports_snapshot_config

const params = {
accountId,
interval: 'daily',
cosBucket,
cosLocation,
};

let res;
try {
res = await usageReportsService.createReportsSnapshotConfig(params);
console.log(JSON.stringify(res.result, null, 2));
} catch (err) {
console.warn(err);
}

// end-create_reports_snapshot_config
});

test('getReportsSnapshotConfig request example', async () => {
consoleLogMock.mockImplementation((output) => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
expect(true).toBeFalsy();
});

originalLog('getReportsSnapshotConfig() result:');
// begin-get_reports_snapshot_config

const params = {
accountId,
};

let res;
try {
res = await usageReportsService.getReportsSnapshotConfig(params);
console.log(JSON.stringify(res.result, null, 2));
} catch (err) {
console.warn(err);
}

// end-get_reports_snapshot_config
});

test('updateReportsSnapshotConfig request example', async () => {
consoleLogMock.mockImplementation((output) => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
expect(true).toBeFalsy();
});

originalLog('updateReportsSnapshotConfig() result:');
// begin-update_reports_snapshot_config

const params = {
accountId,
};

let res;
try {
res = await usageReportsService.updateReportsSnapshotConfig(params);
console.log(JSON.stringify(res.result, null, 2));
} catch (err) {
console.warn(err);
}

// end-update_reports_snapshot_config
});

test('getReportsSnapshot request example', async () => {
consoleLogMock.mockImplementation((output) => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
expect(true).toBeFalsy();
});

originalLog('getReportsSnapshot() result:');
// begin-get_reports_snapshot

const params = {
accountId,
month: billingMonth,
dateFrom: snapshotDateFrom,
dateTo: snapshotDateTo,
};

let res;
try {
res = await usageReportsService.getReportsSnapshot(params);
console.log(JSON.stringify(res.result, null, 2));
} catch (err) {
console.warn(err);
}

// end-get_reports_snapshot
});

test('deleteReportsSnapshotConfig request example', async () => {
consoleLogMock.mockImplementation((output) => {
originalLog(output);
});
consoleWarnMock.mockImplementation((output) => {
// if an error occurs, display the message and then fail the test
originalWarn(output);
expect(true).toBeFalsy();
});

// begin-delete_reports_snapshot_config

const params = {
accountId,
};

try {
await usageReportsService.deleteReportsSnapshotConfig(params);
} catch (err) {
console.warn(err);
}

// end-delete_reports_snapshot_config
});
});
82 changes: 82 additions & 0 deletions test/integration/usage-reports.v4.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ let accountId;
let resourceGroupId;
let orgId;
let billingMonth;
let cosBucket;
let cosLocation;
let snapshotDateFrom;
let snapshotDateTo;

describe('UsageReportsV4_integration', () => {
jest.setTimeout(timeout);
Expand All @@ -49,10 +53,18 @@ describe('UsageReportsV4_integration', () => {
resourceGroupId = config.resourceGroupId;
orgId = config.orgId;
billingMonth = config.billingMonth;
cosBucket = config.cosBucket;
cosLocation = config.cosLocation;
snapshotDateFrom = config.snapshotDateFrom;
snapshotDateTo = config.snapshotDateTo;
expect(accountId).not.toBeNull();
expect(resourceGroupId).not.toBeNull();
expect(orgId).not.toBeNull();
expect(billingMonth).not.toBeNull();
expect(cosBucket).not.toBeNull();
expect(cosLocation).not.toBeNull();
expect(snapshotDateFrom).not.toBeNull();
expect(snapshotDateTo).not.toBeNull();

// console.log('Finished setup.');
});
Expand Down Expand Up @@ -293,4 +305,74 @@ describe('UsageReportsV4_integration', () => {
// console.log(`getResourceUsageOrg() response contained ${numResources} total resources`);
expect(numResources).toBeGreaterThan(0);
});

test('createReportsSnapshotConfig()', async () => {
const params = {
accountId,
interval: 'daily',
cosBucket,
cosLocation,
cosReportsFolder: 'IBMCloud-Billing-Reports',
reportTypes: ['account_summary', 'enterprise_summary', 'account_resource_instance_usage'],
versioning: 'new',
};

const res = await usageReportsService.createReportsSnapshotConfig(params);
expect(res).toBeDefined();
expect(res.status).toBe(201);
expect(res.result).toBeDefined();
});

test('getReportsSnapshotConfig()', async () => {
const params = {
accountId,
};

const res = await usageReportsService.getReportsSnapshotConfig(params);
expect(res).toBeDefined();
expect(res.status).toBe(200);
expect(res.result).toBeDefined();
});

test('updateReportsSnapshotConfig()', async () => {
const params = {
accountId,
interval: 'daily',
cosBucket,
cosLocation,
cosReportsFolder: 'IBMCloud-Billing-Reports',
reportTypes: ['account_summary', 'enterprise_summary'],
versioning: 'new',
};

const res = await usageReportsService.updateReportsSnapshotConfig(params);
expect(res).toBeDefined();
expect(res.status).toBe(200);
expect(res.result).toBeDefined();
});

test('getReportsSnapshot()', async () => {
const params = {
accountId,
month: billingMonth,
dateFrom: snapshotDateFrom,
dateTo: snapshotDateTo,
};

const res = await usageReportsService.getReportsSnapshot(params);
expect(res).toBeDefined();
expect(res.status).toBe(200);
expect(res.result).toBeDefined();
});

test('deleteReportsSnapshotConfig()', async () => {
const params = {
accountId,
};

const res = await usageReportsService.deleteReportsSnapshotConfig(params);
expect(res).toBeDefined();
expect(res.status).toBe(204);
expect(res.result).toBeDefined();
});
});
Loading