From e89cb2dadba229d5c78b2d8c8369c41d16a5d7db Mon Sep 17 00:00:00 2001 From: Alistair Brown Date: Thu, 8 Nov 2018 18:10:42 +0000 Subject: [PATCH] Update Eventbrite lambda to use new utils module --- lambdas/eventbrite/config.js | 2 +- lambdas/eventbrite/handlers/producer.js | 2 +- lambdas/eventbrite/handlers/transformer.js | 2 +- lambdas/eventbrite/package-lock.json | 8 ++++++ lambdas/eventbrite/package.json | 1 + lambdas/eventbrite/utils.js | 26 ------------------- .../eventbrite/handlers/producer.test.js | 2 +- .../eventbrite/handlers/tranformer.test.js | 2 +- lambdas/tests/eventbrite/test-utils.js | 11 +++++--- 9 files changed, 21 insertions(+), 35 deletions(-) delete mode 100644 lambdas/eventbrite/utils.js diff --git a/lambdas/eventbrite/config.js b/lambdas/eventbrite/config.js index f9062241..d3e89b3b 100644 --- a/lambdas/eventbrite/config.js +++ b/lambdas/eventbrite/config.js @@ -1,4 +1,4 @@ -const { convert } = require("./utils"); +const { convert } = require("@muxer/lambda-utils"); const EVENTBRITE_TECH_CATEGORY = 102; diff --git a/lambdas/eventbrite/handlers/producer.js b/lambdas/eventbrite/handlers/producer.js index 14047200..98b56468 100644 --- a/lambdas/eventbrite/handlers/producer.js +++ b/lambdas/eventbrite/handlers/producer.js @@ -1,8 +1,8 @@ "use strict"; +const { uploadTo } = require("@muxer/lambda-utils"); const { getFromWeb } = require("aws-lambda-data-utils"); const { buckets, getEventsUrl } = require("../config"); -const { uploadTo } = require("../utils"); const getErrors = function(eventsPages) { return eventsPages.reduce(function(errors, eventsPage) { diff --git a/lambdas/eventbrite/handlers/transformer.js b/lambdas/eventbrite/handlers/transformer.js index 48f51607..4fbe782d 100644 --- a/lambdas/eventbrite/handlers/transformer.js +++ b/lambdas/eventbrite/handlers/transformer.js @@ -1,10 +1,10 @@ "use strict"; const eventSchema = require("@muxer/event-schema"); +const { uploadTo } = require("@muxer/lambda-utils"); const { getFromS3 } = require("aws-lambda-data-utils"); const { validate } = require("jsonschema"); const { buckets } = require("../config"); -const { uploadTo } = require("../utils"); const getLogoFrom = function({ logo }) { if (!logo) return undefined; diff --git a/lambdas/eventbrite/package-lock.json b/lambdas/eventbrite/package-lock.json index 5abcd9a9..95801fc7 100644 --- a/lambdas/eventbrite/package-lock.json +++ b/lambdas/eventbrite/package-lock.json @@ -8,6 +8,14 @@ "resolved": "https://registry.npmjs.org/@muxer/event-schema/-/event-schema-1.0.0.tgz", "integrity": "sha512-Ne7Uaq8lCjCm5044w9322Ucl7TgmYvhKL9x9lDnoILpnz7VcneriD1/QnugLmar9lHp3RaVTY4MIZ9F/UHhtFg==" }, + "@muxer/lambda-utils": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@muxer/lambda-utils/-/lambda-utils-1.0.0.tgz", + "integrity": "sha512-4k9KBocnCHGC1S6RgatCzFrlau2EWwh/0hD8Q/dX3IT6wnYTRDF4R9hIpSKvj7Yd2bGuTWPBIpGAGT5ZQd50oA==", + "requires": { + "aws-lambda-data-utils": "^1.0.0" + } + }, "aws-lambda-data-utils": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/aws-lambda-data-utils/-/aws-lambda-data-utils-1.0.0.tgz", diff --git a/lambdas/eventbrite/package.json b/lambdas/eventbrite/package.json index 63166b48..90a005a6 100644 --- a/lambdas/eventbrite/package.json +++ b/lambdas/eventbrite/package.json @@ -9,6 +9,7 @@ "private": true, "dependencies": { "@muxer/event-schema": "^1.0.0", + "@muxer/lambda-utils": "^1.0.0", "aws-lambda-data-utils": "^1.0.0", "jsonschema": "^1.2.4" } diff --git a/lambdas/eventbrite/utils.js b/lambdas/eventbrite/utils.js deleted file mode 100644 index 2884e007..00000000 --- a/lambdas/eventbrite/utils.js +++ /dev/null @@ -1,26 +0,0 @@ -const { - createHash, - getDateTimePathFor, - setInS3 -} = require("aws-lambda-data-utils"); - -const uploadTo = function(bucketName, createFilename, data) { - const fileContents = JSON.stringify(data); - const today = new Date(); - const hash = createHash(fileContents); - const prefix = getDateTimePathFor(today); - const filename = createFilename(today, hash); - const filePath = `${prefix}/${filename}`; - - return setInS3(prefix, bucketName, filePath, fileContents); -}; - -const convert = params => - Object.entries(params) - .map(([key, val]) => `${key}=${val}`) - .join("&"); - -module.exports = { - uploadTo, - convert -}; diff --git a/lambdas/tests/eventbrite/handlers/producer.test.js b/lambdas/tests/eventbrite/handlers/producer.test.js index 0d8cb720..bda4d8fb 100644 --- a/lambdas/tests/eventbrite/handlers/producer.test.js +++ b/lambdas/tests/eventbrite/handlers/producer.test.js @@ -2,7 +2,7 @@ process.env.EVENTBRITE_API_TOKEN = "eventbrite-token-abc123"; const { prefix, resolved, resolvedResponse } = require("../test-utils"); const { getFromWeb } = require(`${prefix}/node_modules/aws-lambda-data-utils`); -const { uploadTo } = require(`${prefix}/utils`); +const { uploadTo } = require(`${prefix}/node_modules/@muxer/lambda-utils`); const producer = require(`${prefix}/handlers/producer`); const apiCallPage = page => diff --git a/lambdas/tests/eventbrite/handlers/tranformer.test.js b/lambdas/tests/eventbrite/handlers/tranformer.test.js index fb4c0ebf..e0eba082 100644 --- a/lambdas/tests/eventbrite/handlers/tranformer.test.js +++ b/lambdas/tests/eventbrite/handlers/tranformer.test.js @@ -1,6 +1,6 @@ const { prefix, resolved } = require("../test-utils"); const { getFromS3 } = require(`${prefix}/node_modules/aws-lambda-data-utils`); -const { uploadTo } = require(`${prefix}/utils`); +const { uploadTo } = require(`${prefix}/node_modules/@muxer/lambda-utils`); const transformer = require(`${prefix}/handlers/transformer`); const requireData = filename => diff --git a/lambdas/tests/eventbrite/test-utils.js b/lambdas/tests/eventbrite/test-utils.js index 230ab935..dc7be63c 100644 --- a/lambdas/tests/eventbrite/test-utils.js +++ b/lambdas/tests/eventbrite/test-utils.js @@ -3,10 +3,13 @@ jest.mock("../../eventbrite/node_modules/aws-lambda-data-utils", () => ({ getFromS3: jest.fn() })); -jest.mock("../../eventbrite/utils", () => - Object.assign(require.requireActual("../../eventbrite/utils"), { - uploadTo: jest.fn() - }) +jest.mock("../../eventbrite/node_modules/@muxer/lambda-utils", () => + Object.assign( + require.requireActual("../../eventbrite/node_modules/@muxer/lambda-utils"), + { + uploadTo: jest.fn() + } + ) ); const prefix = "../../../eventbrite";