-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MAS-129_121__112_Daily_Email' of https://github.com/nhs…
…evidence/MAS into MAS-129_121__112_Daily_Email
- Loading branch information
Showing
6 changed files
with
183 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bbe0299
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TeamCity MAS / MAS Build 1.1.0.578 outcome was FAILURE
Summary: Artifacts size 187.2 KB is 95% different from 3.6 MB in build #1.1.0.557-r893BC73; exit code 1 (Step: Set build number (Command Line)) (new) Build time: 00:00:11
bbe0299
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TeamCity MAS / MAS Build 1.1.0.579-MAS-129_121__112_Dai outcome was FAILURE
Summary: Tests failed: 1, passed: 8; artifacts size 187.2 KB is 95% different from 3.6 MB in build #1.1.0.557-r893BC73 Build time: 00:00:41
Failed tests