Skip to content

Commit

Permalink
Passing AK and Champaign tests, working on specs for process subject …
Browse files Browse the repository at this point in the history
…access request
  • Loading branch information
Tuuleh committed Oct 15, 2018
1 parent d38fded commit bf1d568
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 6 additions & 0 deletions lib/util/__mocks__/processSubjectAccessRequest.js
Original file line number Diff line number Diff line change
@@ -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}`
);
}
3 changes: 3 additions & 0 deletions lib/util/__mocks__/shipToS3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function shipToS3(file, bucket) {
return Promise.resolve('www.bogus-url.com');
}
3 changes: 3 additions & 0 deletions lib/util/__mocks__/zipCSVFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function zipCSVFiles(dir, filename) {
return Promise.resolve('/path/to/zip/file.zip');
}
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
33 changes: 30 additions & 3 deletions lib/util/processSubjectAccessRequest.test.js
Original file line number Diff line number Diff line change
@@ -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() {});
});
79 changes: 42 additions & 37 deletions members-service/akSubjectAccessData.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions members-service/champaignSubjectAccessData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
File renamed without changes.

0 comments on commit bf1d568

Please sign in to comment.