diff --git a/lib/clients/actionkit/resources/__mocks__/akSubjectAccessData.js b/lib/clients/actionkit/resources/__mocks__/akSubjectAccessData.js new file mode 100644 index 0000000..d36afdd --- /dev/null +++ b/lib/clients/actionkit/resources/__mocks__/akSubjectAccessData.js @@ -0,0 +1,8 @@ +const AKMockData = { + actions: [{ page_id: 213, member_id: 123 }, { page_id: 234, member_id: 435 }], +}; + +export function AKSubjectAccessData(email) { + console.log('Im in the ak subject access data mock function'); + return Promise.resolve(AKMockData); +} diff --git a/lib/util/__mocks__/processSubjectAccessRequest.js b/lib/util/__mocks__/processSubjectAccessRequest.js new file mode 100644 index 0000000..76e10fe --- /dev/null +++ b/lib/util/__mocks__/processSubjectAccessRequest.js @@ -0,0 +1,6 @@ +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}` + ); +} diff --git a/lib/util/__mocks__/shipToS3.js b/lib/util/__mocks__/shipToS3.js new file mode 100644 index 0000000..07f7765 --- /dev/null +++ b/lib/util/__mocks__/shipToS3.js @@ -0,0 +1,3 @@ +export function shipToS3(file, bucket) { + return Promise.resolve('www.bogus-url.com'); +} diff --git a/lib/util/__mocks__/zipCSVFiles.js b/lib/util/__mocks__/zipCSVFiles.js new file mode 100644 index 0000000..a748f21 --- /dev/null +++ b/lib/util/__mocks__/zipCSVFiles.js @@ -0,0 +1,3 @@ +export function zipCSVFiles(dir, filename) { + return Promise.resolve('/path/to/zip/file.zip'); +} diff --git a/lib/util/basicAuthToken.test.js b/lib/util/__tests__/basicAuthToken.test.js similarity index 78% rename from lib/util/basicAuthToken.test.js rename to lib/util/__tests__/basicAuthToken.test.js index 509d7fa..55f334e 100644 --- a/lib/util/basicAuthToken.test.js +++ b/lib/util/__tests__/basicAuthToken.test.js @@ -1,5 +1,5 @@ // @flow -import { basicAuthToken } from './basicAuthToken'; +import { basicAuthToken } from '../basicAuthToken'; test('converts a user:password combo to an Authorization compatible value', () => { expect(basicAuthToken('user', 'password')).toEqual( diff --git a/lib/util/processSubjectAccessRequest.test.js b/lib/util/processSubjectAccessRequest.test.js index c929111..b1c7403 100644 --- a/lib/util/processSubjectAccessRequest.test.js +++ b/lib/util/processSubjectAccessRequest.test.js @@ -1,3 +1,30 @@ -// test in the process method test file - marshals to csv -// test in the process method test file - uploads a zip file to s3 -// test in the process method test file - emails member services +jest.mock('./shipToS3'); +jest.mock('./zipCSVFiles'); + +import { shipToS3 } from './shipToS3'; +import { zipCSVFiles } from './zipCSVFiles'; +import { processSubjectAccessRequest } from './processSubjectAccessRequest'; + +describe('process subject access requests', function() { + const champaignMockData = { + data: { + actions: [{ id: 213, member_id: 123 }, { id: 234, member_id: 435 }], + }, + }; + + test('marshals json results to csv format', function() { + processSubjectAccessRequest( + champaignMockData, + 'champaign', + 'foo@example.com' + ).then(function(res) { + expect(zipCSVFiles).toHaveBeenCalledWith( + 'path', + 'foo@example.com-champaign.zip' + ); + }); + }); + test('zips the csv files', function() {}); + test('sends the zip file to s3', function() {}); + test('emails member services', function() {}); +}); diff --git a/members-service/akSubjectAccessData.test.js b/members-service/akSubjectAccessData.test.js index c183740..b99c859 100644 --- a/members-service/akSubjectAccessData.test.js +++ b/members-service/akSubjectAccessData.test.js @@ -1,5 +1,8 @@ jest.mock('../lib/util/processSubjectAccessRequest'); jest.mock('../lib/clients/actionkit/resources/akSubjectAccessData'); +jest.mock( + '../lib/clients/actionkit/resources/subjectAccessQueries/subjectAccessQueries' +); import { handlerFunc as handler } from './akSubjectAccessData'; import { marshall, unmarshall } from 'aws-sdk/lib/dynamodb/converter'; @@ -16,54 +19,56 @@ const updateSpy = jest .spyOn(DocumentClient.prototype, 'update') .mockImplementation(opts => ({ promise: () => Promise.resolve(opts) })); -const AKMockData = { - actions: [{ page_id: 213, member_id: 123 }, { page_id: 234, member_id: 435 }], -}; - describe('actionkit subject access data handler', function() { - AKSubjectAccessData.mockImplementation(email => Promise.resolve(AKMockData)); - const cb = jest.fn(); + const AKMockData = { + actions: [ + { page_id: 213, member_id: 123 }, + { page_id: 234, member_id: 435 }, + ], + }; test('returns if the event is not a subject access event', function() { const event = invalidEvent(new Date().toISOString()); - handler(event, null, cb, () => Promise.resolve(AKMockData)); + handler(event, null, cb, AKSubjectAccessData); expect(cb).toHaveBeenCalledWith( null, 'Not a pending subject access request event.' ); }); - //test(`[on success], updates the operations log status with 'SUCCESS' (replayer)`, function() { - // const event = validEvent(new Date().toISOString()); - // const record = unmarshall(event.Records[0].dynamodb.NewImage); - // processSubjectAccessRequest.mockImplementation((data, processor, email) => Promise.resolve(`Subject Access Data for ${processor} successfully sent for ${email}`)) - // - // handler(event, null, cb, () => Promise.resolve(AKMockData)) - // .then(function(res) { - // expect(processSubjectAccessRequest).toHaveBeenCalledWith(AKMockData, 'actionkit', record.data.email); - // expect(statusSpy).toHaveBeenCalledWith(record, { - // actionkit: 'SUCCESS', - // }); - // expect(cb).toHaveBeenCalledWith( - // null, - // 'Subject Access Data for actionkit successfully sent for tuuli@sumofus.org' - // ); - // }) - //}); - // - //test(`[on failure], updates the operations log status with 'FAILURE' (replayer)`, function() { - // const event = memberNotFoundEvent(new Date().toISOString()); - // const record = unmarshall(event.Records[0].dynamodb.NewImage); - // - // handler(event, null, cb, () => Promise.reject('oh no member not found')) - // .then(function(_) { - // expect(statusSpy).toHaveBeenCalledWith(record, { - // actionkit: 'FAILURE', - // }); - // expect(cb).toHaveBeenCalledWith('oh no member not found'); - // }) - //}); + test(`[on success], updates the operations log status with 'SUCCESS' (replayer)`, function() { + const event = validEvent(new Date().toISOString()); + const record = unmarshall(event.Records[0].dynamodb.NewImage); + handler(event, null, cb, AKSubjectAccessData).then(function(res) { + expect(processSubjectAccessRequest).toHaveBeenCalledWith( + AKMockData, + 'actionkit', + record.data.email + ); + expect(statusSpy).toHaveBeenCalledWith(record, { + actionkit: 'SUCCESS', + }); + expect(cb).toHaveBeenCalledWith( + null, + 'Subject Access Data for actionkit successfully sent for tuuli@sumofus.org' + ); + }); + }); + + test(`[on failure], updates the operations log status with 'FAILURE' (replayer)`, function() { + const event = memberNotFoundEvent(new Date().toISOString()); + const record = unmarshall(event.Records[0].dynamodb.NewImage); + + handler(event, null, cb, () => + Promise.reject('oh no member not found') + ).then(function(_) { + expect(statusSpy).toHaveBeenCalledWith(record, { + actionkit: 'FAILURE', + }); + expect(cb).toHaveBeenCalledWith('oh no member not found'); + }); + }); }); function validEvent(date) { diff --git a/members-service/champaignSubjectAccessData.test.js b/members-service/champaignSubjectAccessData.test.js index 275631c..13a0290 100644 --- a/members-service/champaignSubjectAccessData.test.js +++ b/members-service/champaignSubjectAccessData.test.js @@ -32,11 +32,6 @@ describe('Champaign subject access data handler', function() { test(`[on success], updates the operations log status with 'SUCCESS' (replayer)`, function() { const event = validEvent(new Date().toISOString()); const record = unmarshall(event.Records[0].dynamodb.NewImage); - processSubjectAccessRequest.mockImplementation((data, processor, email) => - Promise.resolve( - `Subject Access Data for ${processor} successfully sent for ${email}` - ) - ); handler(event, null, cb, () => Promise.resolve(champaignMockData)).then( function(res) { diff --git a/members-service/subjectAccessDynamoEvent.json b/members-service/events/subjectAccessDynamoEvent.json similarity index 100% rename from members-service/subjectAccessDynamoEvent.json rename to members-service/events/subjectAccessDynamoEvent.json diff --git a/members-service/subjectAccessTrigger.json b/members-service/events/subjectAccessTrigger.json similarity index 100% rename from members-service/subjectAccessTrigger.json rename to members-service/events/subjectAccessTrigger.json