Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #606 from apoclyps/meetupcom-producer-lambda-tests
Browse files Browse the repository at this point in the history
Tests for Meetup.com producer lambda
  • Loading branch information
alistairjcbrown authored Nov 20, 2018
2 parents 8803ae2 + 856b7e9 commit 1f8d4c0
Show file tree
Hide file tree
Showing 10 changed files with 776 additions and 58 deletions.
82 changes: 40 additions & 42 deletions lambdas/tests/eventbrite/handlers/producer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("Eventbrite Producer", function() {
getFromWeb.mockImplementation(() => errorResponse());
});

it("returns an error", function(done) {
it("returns an error and no file paths", function(done) {
producer.produce(event, context, function(err, response) {
expect(err).toEqual([{ error: "test error" }]);
expect(response).toBe(null);
Expand Down Expand Up @@ -73,31 +73,30 @@ describe("Eventbrite Producer", function() {
getFromWeb.mockImplementation(() => singleResponse());
});

it("does not return an error and returns message", function(done) {
producer.produce(event, context, function(err, response) {
expect(err).toBe(null);
expect(response).toEqual({ message: ["path/to/new/file.json"] });
done();
});
});

it("makes a request to the API", function(done) {
producer.produce(event, context, function() {
producer.produce(event, context, function(err) {
expect(getFromWeb).toHaveBeenCalledTimes(1);
expect(getFromWeb).toHaveBeenCalledWith(apiCallPage(1));
done();
done(err);
});
});

it("uploads data", function(done) {
producer.produce(event, context, function() {
producer.produce(event, context, function(err) {
expect(uploadTo).toHaveBeenCalledTimes(1);
expect(uploadTo).toHaveBeenCalledWith(
"muxer-produced-events-eventbrite",
expect.any(Function),
{ pagination: { has_more_items: false, page_count: 1 } }
);
done();
done(err);
});
});

it("returns file paths", function(done) {
producer.produce(event, context, function(err, response) {
expect(response).toEqual({ message: ["path/to/new/file.json"] });
done(err);
});
});
});
Expand All @@ -114,32 +113,18 @@ describe("Eventbrite Producer", function() {
.mockReturnValue(finalResponse({ events: [{ name: "Last Event" }] }));
});

it("does not return an error and returns message", function(done) {
producer.produce(event, context, function(err, response) {
expect(err).toBe(null);
expect(response).toEqual({
message: [
"path/to/new/file.json",
"path/to/new/file.json",
"path/to/new/file.json"
]
});
done();
});
});

it("makes a request to the API", function(done) {
producer.produce(event, context, function() {
producer.produce(event, context, function(err) {
expect(getFromWeb).toHaveBeenCalledTimes(3);
expect(getFromWeb).toHaveBeenCalledWith(apiCallPage(1));
expect(getFromWeb).toHaveBeenCalledWith(apiCallPage(2));
expect(getFromWeb).toHaveBeenCalledWith(apiCallPage(3));
done();
done(err);
});
});

it("uploads data", function(done) {
producer.produce(event, context, function() {
producer.produce(event, context, function(err) {
expect(uploadTo).toHaveBeenCalledTimes(3);
expect(uploadTo).toHaveBeenCalledWith(
"muxer-produced-events-eventbrite",
Expand All @@ -165,7 +150,20 @@ describe("Eventbrite Producer", function() {
pagination: { has_more_items: false, page_count: 3 }
}
);
done();
done(err);
});
});

it("returns file paths", function(done) {
producer.produce(event, context, function(err, response) {
expect(response).toEqual({
message: [
"path/to/new/file.json",
"path/to/new/file.json",
"path/to/new/file.json"
]
});
done(err);
});
});
});
Expand All @@ -180,17 +178,6 @@ describe("Eventbrite Producer", function() {
.mockReturnValue(errorResponse({ page: 3 }));
});

it("return the errors", function(done) {
producer.produce(event, context, function(err, response) {
expect(err).toEqual([
{ error: "test error", page: 2 },
{ error: "test error", page: 3 }
]);
expect(response).toBe(null);
done();
});
});

it("makes a request to the API", function(done) {
producer.produce(event, context, function() {
expect(getFromWeb).toHaveBeenCalledTimes(3);
Expand All @@ -207,5 +194,16 @@ describe("Eventbrite Producer", function() {
done();
});
});

it("returns the errors and no file paths", function(done) {
producer.produce(event, context, function(err, response) {
expect(err).toEqual([
{ error: "test error", page: 2 },
{ error: "test error", page: 3 }
]);
expect(response).toBe(null);
done();
});
});
});
});
31 changes: 16 additions & 15 deletions lambdas/tests/farsetlabs/handlers/producer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ const { uploadTo } = require(`${prefix}/node_modules/@muxer/lambda-utils`);
const producer = require(`${prefix}/handlers/producer`);

const apicall =
"https://www.googleapis.com/calendar/v3/calendars/farsetlabs.org.uk_srmqnkn373auq51u00s2nijrq8%40group.calendar.google.com/events?maxResults=2500&singleEvents=true&orderBy=startTime&timeMin=2019-11-06T10:30:00.000Z&timeMax=2020-11-06T10:30:00.000Z&key=google-calendar-token-abc123";
"https://www.googleapis.com/calendar/v3/calendars/farsetlabs.org.uk_srmqnkn373auq51u00s2nijrq8%40group.calendar.google.com/events?maxResults=2500&singleEvents=true&orderBy=startTime&timeMin=2018-11-06T10:30:00.000Z&timeMax=2019-11-06T10:30:00.000Z&key=google-calendar-token-abc123";

const event = null;
const context = null;

describe("Farsetlabs Producer", function() {
beforeEach(function() {
const frozenDate = new Date("2018-11-06T10:30:00");
const NativeDate = Date;
global.Date = jest.fn(
input => new NativeDate(input || "2018-11-06T10:30:00")
);
jest.clearAllMocks();
global.Date = jest.fn(() => frozenDate);
uploadTo.mockImplementation(resolved({ key: "path/to/new/file.json" }));
});

Expand All @@ -29,31 +31,30 @@ describe("Farsetlabs Producer", function() {
getFromWeb.mockImplementation(() => resolvedResponse({ items: [] }));
});

it("does not return an error and returns message", function(done) {
producer.produce(event, context, function(err, response) {
expect(err).toBe(null);
expect(response).toEqual({ message: ["path/to/new/file.json"] });
done();
});
});

it("makes a request to the API", function(done) {
producer.produce(event, context, function() {
producer.produce(event, context, function(err) {
expect(getFromWeb).toHaveBeenCalledTimes(1);
expect(getFromWeb).toHaveBeenCalledWith(apicall);
done();
done(err);
});
});

it("uploads data", function(done) {
producer.produce(event, context, function() {
producer.produce(event, context, function(err) {
expect(uploadTo).toHaveBeenCalledTimes(1);
expect(uploadTo).toHaveBeenCalledWith(
"muxer-produced-events-farsetlabs",
expect.any(Function),
{ items: [] }
);
done();
done(err);
});
});

it("returns file paths", function(done) {
producer.produce(event, context, function(err, response) {
expect(response).toEqual({ message: ["path/to/new/file.json"] });
done(err);
});
});
});
Expand Down
Loading

0 comments on commit 1f8d4c0

Please sign in to comment.