forked from kamranahmedse/aws-cost-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Allow users to choose aggregation unit for Breakdown by service
#22
Merged
+250
−98
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e01424d
Move function for generating mocked cost data to `testUtils.ts`
Rindrics 115a2b2
Rename `mockPricingData` to `mockedPricingData`
Rindrics 11674a8
Format codes
Rindrics 38b8624
Express 'specific-period summary' function as test
Rindrics cbbdadb
Add 'specific-period summary' function
Rindrics 152ee56
Use 'specific-period summary' function with default (='yesterday')
Rindrics a21584f
Add period notation to notify message header
Rindrics a376d43
Remove indent from `readme.md`
Rindrics 87083ae
Unify parens into curly braces
Rindrics File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import AWS from 'aws-sdk'; | ||
import { AWSConfig } from './config'; | ||
import { formatServiceBreakdown } from './slack'; | ||
import { generateMockedCostByService } from '../testUtils'; | ||
import { getTotalCosts } from '../cost'; | ||
import AWSMock from 'aws-sdk-mock'; | ||
|
||
const costDataLength = 65; | ||
const fixedToday = '2024-05-11'; // cost of 'this month' will be sum of 10 days from May 1 to May 10 ('today' is omitted because its cost is incomplete) | ||
|
||
const awsConfig: AWSConfig = { | ||
credentials: { | ||
accessKeyId: 'testAccessKeyId', | ||
secretAccessKey: 'testSecretAccessKey', | ||
sessionToken: 'testSessionToken', | ||
}, | ||
region: 'us-east-1', | ||
}; | ||
|
||
const mockedCostByService = generateMockedCostByService( | ||
fixedToday, | ||
costDataLength, | ||
); | ||
|
||
beforeAll(() => { | ||
AWSMock.setSDKInstance(AWS); | ||
}); | ||
|
||
afterAll(() => { | ||
AWSMock.restore(); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.useFakeTimers('modern'); | ||
jest.setSystemTime(new Date(fixedToday).getTime()); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
AWSMock.mock('CostExplorer', 'getCostAndUsage', (params, callback) => { | ||
callback(null, mockedCostByService); | ||
}); | ||
|
||
describe('formatServiceBreakdown', () => { | ||
it('should return service breakdown of "yesterday"', async () => { | ||
const totalCosts = await getTotalCosts(awsConfig); | ||
const result = formatServiceBreakdown(totalCosts, 'yesterday'); | ||
|
||
// cost value is defined in generateMockedCostByService | ||
expect(result).toEqual('> service2: `$110.00`\n' + '> service1: `$1.10`'); | ||
}); | ||
|
||
it('should return service breakdown of "Last 7 days"', async () => { | ||
const totalCosts = await getTotalCosts(awsConfig); | ||
const result = formatServiceBreakdown(totalCosts, 'last7Days'); | ||
|
||
// cost value is defined in generateMockedCostByService | ||
expect(result).toEqual('> service2: `$770.00`\n' + '> service1: `$7.70`'); | ||
}); | ||
|
||
it('should return service breakdown of "This Month"', async () => { | ||
const totalCosts = await getTotalCosts(awsConfig); | ||
const result = formatServiceBreakdown(totalCosts, 'thisMonth'); | ||
|
||
// cost value is defined in generateMockedCostByService | ||
expect(result).toEqual('> service2: `$1100.00`\n' + '> service1: `$11.00`'); | ||
}); | ||
|
||
it('should return service breakdown of "Last Month"', async () => { | ||
const totalCosts = await getTotalCosts(awsConfig); | ||
const result = formatServiceBreakdown(totalCosts, 'lastMonth'); | ||
|
||
// cost value is defined in generateMockedCostByService | ||
expect(result).toEqual('> service2: `$3000.00`\n' + '> service1: `$30.00`'); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍