Skip to content

Commit

Permalink
Add flow weak to lib files, fix some caught errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vincemtnz committed Jan 8, 2018
1 parent b9a743d commit 154548f
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 13 deletions.
1 change: 0 additions & 1 deletion lib/clients/actionkit/index.js

This file was deleted.

1 change: 1 addition & 0 deletions lib/clients/actionkit/recurringOrders.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow weak
import { AKClient } from './resources/client';

export function cancel(recurringId, client = AKClient) {
Expand Down
1 change: 1 addition & 0 deletions lib/clients/actionkit/resources/client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow weak
import axios from 'axios';
import { basicAuthToken } from '../../../util/basicAuthToken';

Expand Down
1 change: 1 addition & 0 deletions lib/clients/actionkit/resources/orderrecurring.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow weak
import { IAKClient as AKClient } from './client';
import { pick as _pick, filter as _filter } from 'lodash';

Expand Down
1 change: 1 addition & 0 deletions lib/clients/actionkit/resources/orderrecurring.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow weak
import { getOrderRecurrings, getGCOrderRecurrings } from './orderrecurring';

describe('getOrderRecurings', () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/clients/actionkit/resources/users.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @flow
// @flow weak
import { AKClient as client } from './client';
import { resolveProxyShape, rejectProxyShape } from '../helpers';
import type { ProxyShape } from '../helpers';
Expand All @@ -10,7 +10,7 @@ export type SearchFilters = { [key: string]: string | number | boolean };

export function search(f: ?SearchFilters = {}) {
return client
.get(`/user/`, { params: f })
.get(`/user/`, { params: f || {} })
.then(resolveProxyShape, rejectProxyShape);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/clients/champaign/champaign.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// @flow weak
import axios from 'axios';
import uuid from 'uuid/v1';
import crypto from 'crypto';

const nonce = uuid();

const signature = crypto
.createHmac('sha256', process.env.MEMBER_SERVICES_SECRET)
.createHmac('sha256', process.env.MEMBER_SERVICES_SECRET || '')
.update(nonce)
.digest('hex');

// FIXME: Use one client for all champaign files
const http = axios.create({
baseURL: `${process.env.CHAMPAIGN_URL}/api/member_services/`,
baseURL: `${process.env.CHAMPAIGN_URL || ''}/api/member_services/`,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Expand Down
1 change: 1 addition & 0 deletions lib/clients/champaign/member.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow weak
import axios from 'axios';
import { integrationHeaders } from './utils';

Expand Down
1 change: 1 addition & 0 deletions lib/clients/champaign/member.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow weak
import { updateMember } from './member';

const { objectContaining } = expect;
Expand Down
1 change: 1 addition & 0 deletions lib/clients/champaign/recurringDonation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow weak
import axios from 'axios';
import { integrationHeaders } from './utils';
import crypto from 'crypto';
Expand Down
3 changes: 2 additions & 1 deletion lib/clients/gocardless/gocardless.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow weak
import axios from 'axios';
import { pick as _pick } from 'lodash';

Expand All @@ -11,7 +12,7 @@ const http = axios.create({
baseURL,
headers: {
Accept: 'application/json',
Authorization: `Bearer ${process.env.GOCARDLESS_TOKEN}`,
Authorization: `Bearer ${process.env.GOCARDLESS_TOKEN || ''}`,
'GoCardless-Version': '2015-07-06',
},
});
Expand Down
1 change: 1 addition & 0 deletions lib/clients/gocardless/gocardless.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow weak
import { getSubscription } from './gocardless';

describe('getSubscription', () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/lambda-utils/responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export function notFound(options?: ResponseOptions = {}): ProxyResult {
// }

// 5xx Server Error responses
// export function serverError(options?: ResponseOptions = {}): ProxyResult {
// return response({ ...options, statusCode: 500 });
// }
export function serverError(options?: ResponseOptions = {}): ProxyResult {
return response({ ...options, statusCode: 500 });
}

// export function notImplemented(options?: ResponseOptions = {}): ProxyResult {
// return response({ ...options, statusCode: 501, body: '' });
Expand Down
15 changes: 14 additions & 1 deletion lib/lambda-utils/responses.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// @flow
import { body, badRequest, headers, ok, response } from './responses';
import {
body,
badRequest,
headers,
ok,
response,
serverError,
} from './responses';

describe('badRequest(...)', () => {
test('always returns a statusCode 400', () => {
Expand Down Expand Up @@ -56,6 +63,12 @@ describe('ok(...)', () => {
});
});

describe('serverError(...)', () => {
test('statusCode defaults to 500 OK', () => {
expect(serverError().statusCode).toEqual(500);
});
});

describe('response(...)', () => {
test('statusCode defaults to 200 OK', () => {
expect(response().statusCode).toEqual(200);
Expand Down
1 change: 1 addition & 0 deletions payments-service/gocardless_subscriptions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow weak
import { validateRequest } from '../lib/request-validator';
import { ok, badRequest, serverError } from '../lib/lambda-utils/responses';
import { searchGCSubscriptions } from '../lib/services/gocardless';
Expand Down
6 changes: 3 additions & 3 deletions payments-service/subscriptions-delete-actionkit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow weak
import AWS from 'aws-sdk';
import { cancelPaymentEvent } from '../lib/dynamodb/eventTypeChecker';
import { cancel as cancelRecurringOrder } from '../lib/clients/actionkit';
import { cancel as cancelRecurringOrders } from '../lib/clients/actionkit/recurringOrders';
import { OperationsLogger } from '../lib/dynamodb/operationsLogger';

const logger = new OperationsLogger({
Expand All @@ -10,14 +10,14 @@ const logger = new OperationsLogger({
tableName: process.env.DB_LOG_TABLE || 'OperationsTable',
});

export const handler = async (e, ctx, cb, cancel = cancelRecurringOrder) => {
export const handler = async (e, ctx, cb, fn = cancelRecurringOrders) => {
// Get first item
const [item] = e.Records;
const record = AWS.DynamoDB.Converter.unmarshall(item.dynamodb.NewImage);
if (!cancelPaymentEvent(record)) return cb(null, 'Not a cancel event');

try {
await cancel(record.data.recurringId);
await fn(record.data.recurringId);
logger.updateStatus(record, { actionkit: 'SUCCESS' });
} catch (error) {
logger.updateStatus(record, { actionkit: 'FAILURE' });
Expand Down
1 change: 1 addition & 0 deletions settings/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ environment:
CHAMPAIGN_URL: ${env:CHAMPAIGN_URL}
MEMBER_SERVICES_SECRET: ${env:MEMBER_SERVICES_SECRET}
DB_LOG_TABLE: ${env:DB_LOG_TABLE}
UNSUBSCRIBE_PAGE_NAME: ${env:UNSUBSCRIBE_PAGE_NAME}

0 comments on commit 154548f

Please sign in to comment.