-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidateQueryStringParameters.js
More file actions
60 lines (53 loc) · 1.68 KB
/
validateQueryStringParameters.js
File metadata and controls
60 lines (53 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const { OPTIONS, SCREENSHOTS } = require('./screenshots');
// todo validate hover index if it's possible
module.exports = (type = '', screen = '', custom = '', hoverIndex = '') => {
const upperCaseType = type.toUpperCase();
const options = OPTIONS[upperCaseType];
const screenshots = SCREENSHOTS[upperCaseType];
if (!options) {
return new Error(
`Missing options for type: ${type}. Possible: ${Object.keys(OPTIONS)}`
);
}
if (!screenshots) {
return new Error(
`Missing screenshots for type: ${type}. Possible: ${Object.keys(
SCREENSHOTS
)}`
);
}
console.log(`Query param "type": ${type} is OK!`);
const screenshot = screenshots[screen];
if (!screenshot) {
return new Error(
`Missing screenshot for screen: ${screen}. Possible: ${Object.keys(
screenshots
)}`
);
}
console.log(`Query param "screen": ${screen} is OK!`);
if (upperCaseType === 'CHART' && custom) {
const { customChart } = screenshot;
if (!customChart) {
const chartsWithCustomCharts = Object.values(SCREENSHOTS.CHART)
.filter(item => item.customChart)
.map(item => item.name);
return new Error(
`No custom chart for screen: ${screen}; Possible: ${chartsWithCustomCharts}`
);
}
const stepsToReproduce = customChart[custom];
if (!stepsToReproduce) {
return new Error(
`Missing custom chart: ${custom} for screen: ${screen}. Possible: ${Object.keys(
customChart
)}`
);
}
console.log(`Query param "custom": ${custom} is OK!`);
}
if (upperCaseType !== 'CHART' && custom) {
return new Error('Only CHART has custom property!');
}
return null;
};