Skip to content

Commit

Permalink
Add comments from PR and change S3 key format
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo committed May 2, 2019
1 parent 70817ab commit c5bc6ac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions __mocks__/cognito-fake.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Yes, this is gross, but this is the interface of the dependency we're faking.
export default class CognitoFake {
listUsers() {
return {
Expand Down
4 changes: 4 additions & 0 deletions __mocks__/cognito-pagination-fake.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Yes, this is gross, but this is the interface of the dependency we're faking.

export default class CognitoPaginationFake {
constructor() {
// This attr makes sure we can split a result set into paginated chunks
// without endless recursion.
this.calledAlready = false
}

Expand Down
4 changes: 3 additions & 1 deletion __tests__/CopyUsers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('CopyUsers', () => {
})
it('sets objectKey', () => {
// Matches: {ISO DATE}/{AWS_REGION}_{USER_POOL_ID}.json
expect(copier.objectKey).toMatch(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z\/my-region-1_uSeRPoOlId\.json/)
expect(copier.objectKey).toMatch(/\d{4}-\d{2}-\d{2}\/user-backup_\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z_my-region-1_uSeRPoOlId\.json/)
})
})

Expand All @@ -38,6 +38,8 @@ describe('CopyUsers', () => {
expect(s3Spy).toHaveBeenCalledWith({
Body: "[{\"Username\":\"user1\"},{\"Username\":\"user2\"}]",
Bucket: 'my-bucket-name',
// The key value includes an ISO representation of a timestamp, so
// without gnarly date/time mocking, this is the best I could do here.
Key: expect.any(String)
}, expect.any(Function))
expect(logSpy).toHaveBeenCalledWith('Users backed up to S3')
Expand Down
4 changes: 3 additions & 1 deletion src/CopyUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export default class CopyUsers {
AWS.config = configureAWS(AWS.config)
this.userListString = JSON.stringify(userList)
this.s3 = new AWS.S3()
this.objectKey = `${new Date().toISOString()}/${config.get('userPoolId')}.json`
const timestamp = new Date().toISOString()
const datestamp = timestamp.slice(0, 10)
this.objectKey = `${datestamp}/user-backup_${timestamp}_${config.get('userPoolId')}.json`
}

copy() {
Expand Down

0 comments on commit c5bc6ac

Please sign in to comment.