Skip to content

Commit 22e9663

Browse files
Fix Json decoding (#317)
* Fix Json deserialization * Update * Update test data
1 parent bc2f755 commit 22e9663

File tree

6 files changed

+17
-23
lines changed

6 files changed

+17
-23
lines changed

lib/generate-report.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,22 +406,20 @@ function generateReport(options) {
406406
scenario.steps.forEach((step) => {
407407
if (step.embeddings !== undefined) {
408408
step.attachments = [];
409-
410409
step.embeddings.forEach((embedding, embeddingIndex) => {
411410
/* Decode Base64 for Text-ish attachements */
412-
if(
413-
embedding.mime_type === 'application/json' ||
414-
embedding.mime_type === 'text/html' ||
415-
embedding.mime_type === 'text/plain'
411+
if(
412+
embedding.mime_type === 'text/html' ||
413+
embedding.mime_type === 'text/plain'
416414
) {
417-
embedding.data = Buffer.from(embedding.data.toString(), 'base64')
418-
}
419-
415+
embedding.data = Buffer.from(embedding.data.toString(), 'base64')
416+
}
420417
/* istanbul ignore else */
421418
if (
422419
embedding.mime_type === 'application/json' ||
423420
(embedding.media && embedding.media.type === 'application/json')
424421
) {
422+
embedding.data = Buffer.from(embedding.data, 'base64').toString()
425423
step.json = (step.json ? step.json : []).concat([
426424
typeof embedding.data === 'string'
427425
? JSON.parse(embedding.data)

test/unit/data/custom-metadata-json/multiple_different_attachements.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@
5353
},
5454
"embeddings": [
5555
{
56-
"data": "{\"some\":\"json\"}",
56+
"data": "eyJzb21lIjoianNvbiJ9",
5757
"media": {
5858
"type": "application/json"
5959
}
6060
},
6161
{
62-
"data": "{\"other\":\"json\"}",
62+
"data": "eyJvdGhlciI6Impzb24ifQ==",
6363
"media": {
6464
"type": "application/json"
6565
}
@@ -71,13 +71,13 @@
7171
}
7272
},
7373
{
74-
"data": "{\"yet another json\":5}",
74+
"data": "eyJ5ZXQgYW5vdGhlciBqc29uIjo1fQ==",
7575
"media": {
7676
"type": "application/json"
7777
}
7878
},
7979
{
80-
"data": 0,
80+
"data": "MA==",
8181
"media": {
8282
"type": "application/json"
8383
}

test/unit/data/custom-metadata-json/undefined_scenarios_specified_v3.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@
131131
},
132132
"embeddings": [
133133
{
134-
"data": "{\"some\":\"json\"}",
134+
"data": "eyJzb21lIjoianNvbiJ9",
135135
"media": {
136136
"type": "application/json"
137137
}
138138
},
139139
{
140-
"data": "{\"other\":\"json\"}",
140+
"data": "eyJvdGhlciI6Impzb24ifQ==",
141141
"media": {
142142
"type": "application/json"
143143
}
@@ -149,7 +149,7 @@
149149
}
150150
},
151151
{
152-
"data": "{\"yet another json\":5}",
152+
"data": "eyJ5ZXQgYW5vdGhlciBqc29uIjo1fQ==",
153153
"media": {
154154
"type": "application/json"
155155
}

test/unit/data/json/before-and-after-hook.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@
8383
"mime_type": "text/plain"
8484
},
8585
{
86-
"data": {
87-
"json-string": true
88-
},
86+
"data": "eyJqc29uLXN0cmluZyI6IHRydWV9",
8987
"mime_type": "application/json"
9088
}
9189
]

test/unit/data/json/embeddings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"embeddings": [
3030
{
31-
"data": "[{\"data\":{\"x\":\"1\",\"y\":\"1\",\"url\":\"http://url.com\"},\"event\":\"start\",\"show\":1,\"id\":50},{\"data\":{\"x\":\"2\",\"y\":\"3\",\"url\":\"http://example.com\"},\"event\":\"stop\",\"show\":2,\"id\":51}]",
31+
"data": "W3siZGF0YSI6eyJ4IjoiMSIsInkiOiIxIiwidXJsIjoiaHR0cDovL3VybC5jb20ifSwiZXZlbnQiOiJzdGFydCIsInNob3ciOjEsImlkIjo1MH0seyJkYXRhIjp7IngiOiIyIiwieSI6IjMiLCJ1cmwiOiJodHRwOi8vZXhhbXBsZS5jb20ifSwiZXZlbnQiOiJzdG9wIiwic2hvdyI6MiwiaWQiOjUxfV0=",
3232
"mime_type": "application/json"
3333
},
3434
{

test/unit/data/output/merged-output.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,9 +1090,7 @@
10901090
"mime_type": "text/plain"
10911091
},
10921092
{
1093-
"data": {
1094-
"json-string": true
1095-
},
1093+
"data": "eyJqc29uLXN0cmluZyI6IHRydWV9",
10961094
"mime_type": "application/json"
10971095
}
10981096
]
@@ -1265,7 +1263,7 @@
12651263
},
12661264
"embeddings": [
12671265
{
1268-
"data": "[{\"data\":{\"x\":\"1\",\"y\":\"1\",\"url\":\"http://url.com\"},\"event\":\"start\",\"show\":1,\"id\":50},{\"data\":{\"x\":\"2\",\"y\":\"3\",\"url\":\"http://example.com\"},\"event\":\"stop\",\"show\":2,\"id\":51}]",
1266+
"data": "W3siZGF0YSI6eyJ4IjoiMSIsInkiOiIxIiwidXJsIjoiaHR0cDovL3VybC5jb20ifSwiZXZlbnQiOiJzdGFydCIsInNob3ciOjEsImlkIjo1MH0seyJkYXRhIjp7IngiOiIyIiwieSI6IjMiLCJ1cmwiOiJodHRwOi8vZXhhbXBsZS5jb20ifSwiZXZlbnQiOiJzdG9wIiwic2hvdyI6MiwiaWQiOjUxfV0=",
12691267
"mime_type": "application/json"
12701268
},
12711269
{

0 commit comments

Comments
 (0)