forked from demisto/content
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript-VerifyTableToMarkDown.yml
86 lines (72 loc) · 2.78 KB
/
script-VerifyTableToMarkDown.yml
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
commonfields:
id: VerifyTableToMarkDown
version: -1
name: VerifyTableToMarkDown
script: |-
var simpleData = {
key: 'value'
}
var hrSimple = "### Simple\nkey|\n---|\nvalue|\n";
var simpleArray = ['a0','a1','a2','a3'];
var hrArray = "### Simple Array\nArray|\n---|\na0|\na1|\na2|\na3|\n";
var dataWithEscapeCharacters = {
key1: "value1\r\nvalue1",
key2: "value2\nvalue2",
key3: "value3\rvalue3",
key4: "[url](www.google.com)"
}
var hrWithEscapeCharacters = "### Escape\nkey1|key2|key3|key4\n---|---|---|---\nvalue1<br>value1|value2<br>value2|value3<br>value3|[url](www.google.com)\n";
var dataContainingDotHeaders = {
"key.key": "dot header"
}
var hrContainingDotHeaders = "### Dot\nkey.key|\n---|\ndot header|\n";
var dataWithNestedObject = {
x: {
y: 1
}
}
var hrWithNestedObject = "### Nested\nx|\n---|\n{\"y\":1}|\n";
var hrWithNestedObjectAfterFlat = "### Nested\nx.y|\n---|\n1|\n";
var h = tableToMarkdown("Simple", simpleData)
if ( h!== hrSimple) {
throw "Simple Data failed to be converted to RIGHT Human Redable fotmat. Got: " + h;
}
h = tableToMarkdown("Simple Array", simpleArray, 'Array');
if( h !== hrArray){
throw "Simple Data failed to be converted to RIGHT Human Redable fotmat. Got: " + h;
}
h = tableToMarkdown("Simple Array", simpleArray, ['Array']);
if( h !== hrArray){
throw "Simple Data failed to be converted to RIGHT Human Redable fotmat. Got: " + h;
}
h = tableToMarkdown("Escape", dataWithEscapeCharacters);
if(h !== hrWithEscapeCharacters){
throw "Data with escape characters failed to be converted to RIGHT Human Redable fotmat. Got: " + h;
}
h = tableToMarkdown("Dot", dataContainingDotHeaders);
if(h !== hrContainingDotHeaders){
throw "Data with dot header failed to be converted to RIGHT Human Redable fotmat. Got: " + h;
}
h = tableToMarkdown("Nested", dataWithNestedObject);
if(h !== hrWithNestedObject){
throw "Data with nested object(w/o flatten) failed to be converted to RIGHT Human Redable fotmat. Got: " + h;
}
h = tableToMarkdown("Nested", treeToFlattenObject(dataWithNestedObject));
if(h !== hrWithNestedObjectAfterFlat){
throw "Data with nested object(w/ flatten) failed to be converted to RIGHT Human Redable fotmat. Got: " + h;
}
// validate tableToMarkdown is not escaping dots
var objectWithURL = {
key: "www.url.com"
}
var hrOfObjectWithUrl = "### DoNotEscape\nkey|\n---|\nwww.url.com|\n";
h = tableToMarkdown("DoNotEscape", objectWithURL);
if(h !== hrOfObjectWithUrl){
throw "Data without escape characters failed to be converted to RIGHT Human Redable fotmat. Got: " + h;
}
return true;
type: javascript
tags: []
enabled: true
scripttarget: 0
runonce: false