Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mas-129 Mas-121 Mas-112 Daily email cards merge #48

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4e098d4
MAS-129 Add MAD fields without branding
d-lan1 Jan 14, 2020
0a12a63
MAS-129 Add Specialities to MAD
d-lan1 Jan 14, 2020
697face
MAS-129 Add tests
d-lan1 Jan 14, 2020
be26ac1
MAS-121 Add broader title to evidence type in item api
d-lan1 Jan 13, 2020
1b4a388
MAS-129 Fix test and pluralise Item.Speciality
d-lan1 Jan 14, 2020
fb9a9cc
MAS-121 Clean up and add mailcontroller tests
d-lan1 Jan 15, 2020
dda5c61
Working on mailservice integration tests
d-lan1 Jan 15, 2020
7804e5c
MAS-129 Reafctor tests
ediblecode Jan 16, 2020
c94036c
MASD-129 Add mailchimp template
d-lan1 Jan 16, 2020
ef4e6b2
MAS-129 Fix JS linting errors
ediblecode Jan 16, 2020
78f6c65
MAS-129 Test getting items for specific date
d-lan1 Jan 16, 2020
8b643c5
Merge branch 'MAS-129_121__112_Daily_Email' of https://github.com/nhs…
d-lan1 Jan 16, 2020
130f2b7
MAS-129 Add styling and branding to daily email
d-lan1 Jan 16, 2020
3261e88
MAS-129 Add 'send me everything' option to daily email
d-lan1 Jan 16, 2020
a8b6683
MAS-129 Layout template fixes
d-lan1 Jan 16, 2020
a367366
MAS-129 Add daily items endpoint in CMS
ediblecode Jan 16, 2020
e18952a
Merge branch 'MAS-129_121__112_Daily_Email' of github.com:nice-digita…
ediblecode Jan 16, 2020
8137313
MAS-129 Update mailchimp template daily
d-lan1 Jan 16, 2020
bbe0299
Merge branch 'MAS-129_121__112_Daily_Email' of https://github.com/nhs…
d-lan1 Jan 16, 2020
242f5e2
MAS-129 Update DailyEmail.cshtml
d-lan1 Jan 16, 2020
e2700db
MAS-129 DailyEmail generation
d-lan1 Jan 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions cms/__tests__/routes/api/items.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
jest.mock("keystone", () => {
const item = {
model: {
find: jest.fn()
}
};

return {
list: () => item
};
});

describe("items", () => {
let keystone, daily, Item, request, response, json;

beforeEach(() => {
jest.resetModules();

keystone = require("keystone");
Item = keystone.list("Item");
daily = require("../../../routes/api/items").daily;
request = { params: {} };
json = jest.fn();
response = {
json,
badRequest: jest.fn(),
error: jest.fn()
};
});

describe("daily", () => {});

it("should return a 400 bad request when the date format is invalid", async () => {
const date = "not a date";
await daily({ ...request, ...{ params: { date } } }, response);

expect(response.badRequest).toHaveBeenCalledWith(
"Couldn't get daily items",
"Date 'not a date' is not in the format YYYY-M-D",
true
);
});

it("should search for daily items between start and end of the given date", async () => {
const date = "2020-01-09";
await daily({ ...request, ...{ params: { date } } }, response);

expect(Item.model.find).toHaveBeenCalledWith({
createdAt: {
$gte: new Date(Date.parse("2020-01-09")),
$lt: new Date(Date.parse("2020-01-09 23:59:59.999Z"))
}
});
});

it("should return a 500 JSON error response when there's an error getting the daily items", async () => {
const error = new Error("An error getting daily items");

Item.model.find.mockImplementation(() => {
throw error;
});

await daily(
{ ...request, ...{ params: { date: "2020-01-09" } } },
response
);

expect(response.error).toHaveBeenCalledWith(error, true);
});

it("should return the found item as json with whitelist of fields", async () => {
const items = [{ title: "test", excludedField: "not used" }];

Item.model.find.mockImplementation(() => {
return {
populate: () => ({
populate: () => ({
populate: () => ({
exec: () => items
})
})
})
};
});

await daily(
{ ...request, ...{ params: { date: "2020-01-09" } } },
response
);

expect(json).toHaveBeenCalledWith([{ title: "test" }]);
});
});
Loading