diff --git a/__mocks__/cognito-fake.js b/__mocks__/cognito-fake.js index 747aeb9..9f979ed 100644 --- a/__mocks__/cognito-fake.js +++ b/__mocks__/cognito-fake.js @@ -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 { diff --git a/__mocks__/cognito-pagination-fake.js b/__mocks__/cognito-pagination-fake.js index 1e1bc80..4a541ba 100644 --- a/__mocks__/cognito-pagination-fake.js +++ b/__mocks__/cognito-pagination-fake.js @@ -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 } diff --git a/__tests__/CopyUsers.test.js b/__tests__/CopyUsers.test.js index 0b64b0f..f862910 100644 --- a/__tests__/CopyUsers.test.js +++ b/__tests__/CopyUsers.test.js @@ -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/) }) }) @@ -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') diff --git a/src/CopyUsers.js b/src/CopyUsers.js index 1daa032..ac6455d 100644 --- a/src/CopyUsers.js +++ b/src/CopyUsers.js @@ -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() {