Skip to content

Commit f469de0

Browse files
author
dylan
committed
Merge branch 'MAS-121-SendEmailWithPreferences-2' of https://github.com/nhsevidence/MAS into MAS-121-SendEmailWithPreferences-2
2 parents 2f939be + db6887b commit f469de0

25 files changed

+11472
-6970
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto
2+
/cms/** eol=lf

cms/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!.eslintrc.js

cms/.eslintrc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
parser: "babel-eslint",
3+
extends: [
4+
"@nice-digital/eslint-config/es6",
5+
"plugin:prettier/recommended",
6+
"prettier/standard"
7+
],
8+
parserOptions: {
9+
ecmaFeatures: {
10+
jsx: true,
11+
modules: true
12+
}
13+
},
14+
env: {
15+
es6: true,
16+
jest: true
17+
}
18+
};

cms/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package.json

cms/.prettierrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"semi": true,
3+
"singleQuote": false,
4+
"trailingComma": "none",
5+
"useTabs": true,
6+
"printWidth": 80,
7+
"endOfLine": "lf",
8+
"overrides": [
9+
{
10+
"files": ["**/*.scss"],
11+
"options": {
12+
"useTabs": false,
13+
"tabWidth": 2,
14+
"singleQuote": true
15+
}
16+
}
17+
]
18+
}

cms/.vscode/extensions.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"recommendations": [
3+
"EditorConfig.EditorConfig",
4+
"dbaeumer.vscode-eslint",
5+
"andys8.jest-snippets",
6+
"eg2.vscode-npm-script",
7+
"christian-kohler.npm-intellisense",
8+
"christian-kohler.path-intellisense",
9+
"esbenp.prettier-vscode",
10+
"hex-ci.stylelint-plus"
11+
]
12+
}

cms/.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.rulers": [80],
4+
"files.eol": "\n"
5+
}

cms/MAS.CMS.nuspec

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
3+
<metadata>
4+
<id>MAS.CMS</id>
5+
<version>1.0.0</version>
6+
<title>MAS CMS</title>
7+
<authors>NICE Digital Services,Ian Routledge</authors>
8+
<owners>nice-digital</owners>
9+
<projectUrl>https://github.com/nice-digital/MAS</projectUrl>
10+
<iconUrl>https://cdn.nice.org.uk/V3/Content/nice/favicon-120.png</iconUrl>
11+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
12+
<description>Keystone CMS for Medicines Awareness Service</description>
13+
<tags>keystonejs cms</tags>
14+
<dependencies></dependencies>
15+
</metadata>
16+
<files>
17+
<file src="models\**\*" target="models" />
18+
<file src="public\**\*" target="public" />
19+
<file src="routes\**\*" target="routes" />
20+
<file src="updates\**\*" target="updates" />
21+
<file src="dotenv.config" />
22+
<file src="keystone.js" />
23+
<file src="package-lock.json" />
24+
<file src="package.json" />
25+
</files>
26+
</package>

cms/README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,36 @@ Configure the CMS through environment variables.
1212

1313
Running the CMS as part of the Docker stack from the root of this repo will automatically set these for you.
1414

15-
- `MONGO_URL` - The URL for connecting to Mongo. Defaults to *mongodb://localhost:27017*
16-
- `PORT` - The port to run under. Defaults to *3010*.
17-
- `COOKIE_SECRET`
15+
- `MONGO_URL` - The URL for connecting to Mongo. Defaults to _mongodb://localhost:27017_
16+
- `PORT` - The port to run under. Defaults to _3010_.
17+
- `COOKIE_SECRET`
18+
19+
# Tests
20+
21+
There are unit tests for custom logic and validation within the CMS. These use Jest under the hood.
22+
23+
Run the tests (and linting) on the command line with:
24+
25+
```
26+
npm test
27+
```
28+
29+
Alternatively, run `npm run test:unit` to just run the unit tests without linting.
30+
31+
## Watch mode
32+
33+
Run the tests in watch mode when developing to automatically re-run changed tests:
34+
35+
```
36+
npm run test:unit:watch
37+
```
38+
39+
## Coverage
40+
41+
Collect coverage by running the following command:
42+
43+
```
44+
npm run test:unit:coverage
45+
```
46+
47+
This reports coverage on the command line, and as HTML within the _coverage_ folder. It also reports coverage to TeamCity automatically when run on a build agent (or when the `TEAMCITY_VERSION` environment variable is set).
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
jest.mock("keystone", () => {
2+
const list = {
3+
add: jest.fn(),
4+
schema: {
5+
pre: jest.fn()
6+
},
7+
relationship: jest.fn(),
8+
register: jest.fn()
9+
};
10+
11+
return {
12+
// Use a normal func and not an arrow so it can be used as a constructor
13+
List: function() {
14+
return list;
15+
},
16+
Field: {
17+
Types: {}
18+
}
19+
};
20+
});
21+
22+
describe("Weekly", () => {
23+
let keystone, pre;
24+
25+
beforeEach(() => {
26+
jest.resetModules();
27+
require("../../models/Weekly");
28+
keystone = require("keystone");
29+
30+
pre = keystone.List("Weekly").schema.pre;
31+
});
32+
33+
it("should set up a pre-validate function", () => {
34+
expect(pre).toHaveBeenCalledWith("validate", expect.any(Function));
35+
});
36+
37+
it("should call next with no errors when validation succeeds", () => {
38+
const validatorFn = pre.mock.calls[0][1];
39+
40+
const next = jest.fn();
41+
validatorFn.call({}, next);
42+
43+
expect(next).toHaveBeenCalledWith();
44+
});
45+
46+
it.each`
47+
field | filledIn | emptyFields
48+
${"commentaryTitle"} | ${"title"} | ${"summary and body"}
49+
${"commentarySummary"} | ${"summary"} | ${"title and body"}
50+
${"commentaryBody"} | ${"body"} | ${"title and summary"}
51+
`(
52+
"should validate commentary $emptyFields when $filledIn is set",
53+
({ field, filledIn, emptyFields }) => {
54+
const pre = keystone.List("Weekly").schema.pre;
55+
56+
expect(pre).toHaveBeenCalledWith("validate", expect.any(Function));
57+
58+
const validatorFn = pre.mock.calls[0][1];
59+
60+
const next = jest.fn();
61+
validatorFn.call(
62+
{
63+
[field]: "Test content"
64+
},
65+
next
66+
);
67+
68+
const errorMessage = `Commentary ${emptyFields} are both required if commentary ${filledIn} is set`;
69+
70+
expect(next).toHaveBeenCalledWith(Error(errorMessage));
71+
}
72+
);
73+
});

0 commit comments

Comments
 (0)