Skip to content

Commit 2bf1ed5

Browse files
authored
fix: fix download center json and add tests (#324)
1 parent 8cadb8e commit 2bf1ed5

File tree

5 files changed

+152
-1
lines changed

5 files changed

+152
-1
lines changed

packages/build/package-lock.json

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/build/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
]
3131
},
3232
"devDependencies": {
33+
"ajv": "^6.12.5",
3334
"nock": "^13.0.4",
3435
"sinon-chai": "^3.5.0"
3536
},
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
const downloadCenterSchema = {
2+
'type': 'object',
3+
'required': [
4+
'versions',
5+
'manual_link',
6+
'release_notes_link',
7+
'previous_releases_link',
8+
'development_releases_link',
9+
'supported_browsers_link',
10+
'tutorial_link'
11+
],
12+
'properties': {
13+
'versions': {
14+
'type': 'array',
15+
'additionalItems': false,
16+
'items': {
17+
'type': 'object',
18+
'required': [
19+
'_id',
20+
'version',
21+
'platform'
22+
],
23+
'properties': {
24+
'_id': {
25+
'type': 'string'
26+
},
27+
'version': {
28+
'type': 'string'
29+
},
30+
'platform': {
31+
'type': 'array',
32+
'additionalItems': false,
33+
'items': {
34+
'type': 'object',
35+
'required': [
36+
'arch',
37+
'os',
38+
'name',
39+
'download_link'
40+
],
41+
'properties': {
42+
'arch': {
43+
'type': 'string'
44+
},
45+
'os': {
46+
'type': 'string'
47+
},
48+
'name': {
49+
'type': 'string'
50+
},
51+
'download_link': {
52+
'type': 'string'
53+
}
54+
},
55+
'additionalProperties': false
56+
}
57+
}
58+
},
59+
'additionalProperties': false
60+
}
61+
},
62+
'manual_link': {
63+
'type': 'string'
64+
},
65+
'release_notes_link': {
66+
'type': 'string'
67+
},
68+
'previous_releases_link': {
69+
'type': 'string'
70+
},
71+
'development_releases_link': {
72+
'type': 'string'
73+
},
74+
'supported_browsers_link': {
75+
'type': 'string'
76+
},
77+
'tutorial_link': {
78+
'type': 'string'
79+
}
80+
},
81+
'additionalProperties': false
82+
};
83+
84+
export default downloadCenterSchema;

packages/build/src/download-center.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
import { expect } from 'chai';
22
import nock from 'nock';
33

4+
import Ajv from 'ajv';
5+
6+
import downloadCenterSchema from './download-center-schema';
7+
48
import {
59
createDownloadCenterConfig,
610
verifyDownloadCenterConfig
711
} from './download-center';
812

13+
function validateWithSchema(obj, schema): void {
14+
const ajv = new Ajv();
15+
const validate = ajv.compile(schema);
16+
const valid = validate(obj);
17+
if (!valid) {
18+
throw new Error(ajv.errorsText(validate.errors));
19+
}
20+
}
21+
922
describe('download center module', () => {
1023
describe('.createDownloadCenterConfig', () => {
1124
let config;
@@ -25,6 +38,14 @@ describe('download center module', () => {
2538
it('returns the string with the win version injected', () => {
2639
expect(config).to.include('mongosh-1.2.2-win32.zip');
2740
});
41+
42+
it('produces a well formed json', () => {
43+
expect(() => { JSON.parse(config); }).not.to.throw();
44+
});
45+
46+
it('produces a json valid for the download center', () => {
47+
validateWithSchema(JSON.parse(config), downloadCenterSchema);
48+
});
2849
});
2950

3051
describe('.verifyDownloadCenterConfig', () => {

packages/build/src/download-center.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const CONFIG = `
7171
"os": "debian",
7272
"name": "Debian 64-bit",
7373
"download_link": "https://downloads.mongodb.com/compass/mongosh_{{version}}_amd64.deb"
74-
}
74+
},
7575
{
7676
"arch": "x64",
7777
"os": "rhel",

0 commit comments

Comments
 (0)