-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Constructor pattern for subject access requests processor in order to…
… enable injecting mocks
- Loading branch information
Showing
13 changed files
with
160 additions
and
120 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export function processSubjectAccessRequest(data, processor, email) { | ||
console.log('mock process subject access request', data); | ||
return Promise.resolve( | ||
`Subject Access Data for ${processor} successfully sent for ${email}` | ||
); | ||
export function SARconstructor() { | ||
return function(data, processor, email) { | ||
return Promise.resolve( | ||
`Subject Access Data for ${processor} successfully sent for ${email}` | ||
); | ||
}; | ||
} |
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,5 @@ | ||
export function sendEmail(url, recipient, email, processor) { | ||
return Promise.resolve({ | ||
MessageId: 'EXAMPLE78603177f-7a5433e7-8edb-42ae-af10-f0181f34d6ee-000000', | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export function zipCSVFiles(dir, filename) { | ||
console.log('Mock zip csv files'); | ||
return Promise.resolve('/path/to/zip/file.zip'); | ||
} |
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,53 @@ | ||
import { SARconstructor } from '../processSubjectAccessRequest'; | ||
import path from 'path'; | ||
|
||
const zipCSVFiles = jest.fn(); | ||
const sendEmail = jest.fn(); | ||
const shipToS3 = jest.fn(); | ||
|
||
describe('process subject access requests', function() { | ||
zipCSVFiles.mockReturnValue(Promise.resolve('/path/to/zip/file.zip')); | ||
|
||
sendEmail.mockReturnValue( | ||
Promise.resolve({ | ||
MessageId: 'EXAMPLE78603177f-7a5433e7-8edb-42ae-af10-f0181f34d6ee-000000', | ||
}) | ||
); | ||
|
||
shipToS3.mockReturnValue(Promise.resolve('www.bogus-url.com')); | ||
|
||
const champaignMockData = { | ||
data: { | ||
actions: [{ id: 213, member_id: 123 }, { id: 234, member_id: 435 }], | ||
}, | ||
}; | ||
|
||
const processSubjectAccessRequest = SARconstructor( | ||
zipCSVFiles, | ||
shipToS3, | ||
sendEmail | ||
); | ||
|
||
test('zips the csv files, sends the zip file to s3 and emails member services', function() { | ||
processSubjectAccessRequest( | ||
champaignMockData, | ||
'champaign', | ||
'foo@example.com' | ||
).then(function(res) { | ||
expect(zipCSVFiles).toHaveBeenCalledWith( | ||
path.join(__dirname, '../tmp'), | ||
'foo@example.com-champaign.zip' | ||
); | ||
expect(shipToS3).toHaveBeenCalledWith( | ||
'/path/to/zip/file.zip', | ||
'subject-access-requests' | ||
); | ||
expect(sendEmail).toHaveBeenCalledWith( | ||
'www.bogus-url.com', | ||
'info@example.com', | ||
'foo@example.com', | ||
'champaign' | ||
); | ||
}); | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
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,31 @@ | ||
import AWS from 'aws-sdk'; | ||
|
||
export function sendEmail(url, recipient, email, processor) { | ||
const ses = new AWS.SES({ region: 'us-west-2' }); | ||
|
||
const params = { | ||
Destination: { | ||
ToAddresses: [recipient], | ||
}, | ||
Message: { | ||
Body: { | ||
Html: { | ||
Data: `<p>Click the link below to download the ${ | ||
processor | ||
} subject access data for ${ | ||
} (link will expire in 10 minutes):</p><p><a href="${ | ||
url | ||
}">Click here to download</a></p>`, | ||
Charset: 'UTF-8', | ||
}, | ||
}, | ||
Subject: { | ||
Data: `${processor} subject access data for ${email}`, | ||
Charset: 'UTF-8', | ||
}, | ||
}, | ||
Source: 'no-reply@sumofus.awsapps.com', | ||
}; | ||
return ses.sendEmail(params).promise(); | ||
} |
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