File tree 6 files changed +52
-1
lines changed
bruno-tests/collection/scripting/inbuilt modules/tv4 6 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 35
35
"node-vault" : " ^0.10.2" ,
36
36
"path" : " ^0.12.7" ,
37
37
"quickjs-emscripten" : " ^0.29.2" ,
38
+ "tv4" : " ^1.3.0" ,
38
39
"uuid" : " ^9.0.0" ,
39
40
"xml2js" : " ^0.6.2"
40
41
},
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ const CryptoJS = require('crypto-js');
30
30
const NodeVault = require ( 'node-vault' ) ;
31
31
const xml2js = require ( 'xml2js' ) ;
32
32
const cheerio = require ( 'cheerio' ) ;
33
+ const tv4 = require ( 'tv4' ) ;
33
34
const { executeQuickJsVmAsync } = require ( '../sandbox/quickjs' ) ;
34
35
35
36
class ScriptRuntime {
@@ -151,6 +152,7 @@ class ScriptRuntime {
151
152
'crypto-js' : CryptoJS ,
152
153
'xml2js' : xml2js ,
153
154
cheerio,
155
+ tv4,
154
156
...whitelistedModules ,
155
157
fs : allowScriptFilesystemAccess ? fs : undefined ,
156
158
'node-vault' : NodeVault
@@ -285,6 +287,7 @@ class ScriptRuntime {
285
287
'crypto-js' : CryptoJS ,
286
288
'xml2js' : xml2js ,
287
289
cheerio,
290
+ tv4,
288
291
...whitelistedModules ,
289
292
fs : allowScriptFilesystemAccess ? fs : undefined ,
290
293
'node-vault' : NodeVault
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ const CryptoJS = require('crypto-js');
32
32
const NodeVault = require ( 'node-vault' ) ;
33
33
const xml2js = require ( 'xml2js' ) ;
34
34
const cheerio = require ( 'cheerio' ) ;
35
+ const tv4 = require ( 'tv4' ) ;
35
36
const { executeQuickJsVmAsync } = require ( '../sandbox/quickjs' ) ;
36
37
37
38
const getResultsSummary = ( results ) => {
@@ -209,6 +210,7 @@ class TestRuntime {
209
210
'crypto-js' : CryptoJS ,
210
211
'xml2js' : xml2js ,
211
212
cheerio,
213
+ tv4,
212
214
...whitelistedModules ,
213
215
fs : allowScriptFilesystemAccess ? fs : undefined ,
214
216
'node-vault' : NodeVault
Original file line number Diff line number Diff line change @@ -12,21 +12,24 @@ const bundleLibraries = async () => {
12
12
import btoa from "btoa";
13
13
import atob from "atob";
14
14
import * as CryptoJS from "@usebruno/crypto-js";
15
+ import tv4 from "tv4";
15
16
globalThis.expect = expect;
16
17
globalThis.assert = assert;
17
18
globalThis.moment = moment;
18
19
globalThis.btoa = btoa;
19
20
globalThis.atob = atob;
20
21
globalThis.Buffer = Buffer;
21
22
globalThis.CryptoJS = CryptoJS;
23
+ globalThis.tv4 = tv4;
22
24
globalThis.requireObject = {
23
25
...(globalThis.requireObject || {}),
24
26
'chai': { expect, assert },
25
27
'moment': moment,
26
28
'buffer': { Buffer },
27
29
'btoa': btoa,
28
30
'atob': atob,
29
- 'crypto-js': CryptoJS
31
+ 'crypto-js': CryptoJS,
32
+ 'tv4': tv4
30
33
};
31
34
` ;
32
35
Original file line number Diff line number Diff line change
1
+ meta {
2
+ name: tv4
3
+ }
Original file line number Diff line number Diff line change
1
+ meta {
2
+ name: tv4
3
+ type: http
4
+ seq: 1
5
+ }
6
+
7
+ post {
8
+ url: {{host}}/api/echo/json
9
+ body: json
10
+ auth: inherit
11
+ }
12
+
13
+ body:json {
14
+ {
15
+ "name": "John",
16
+ "age": 30
17
+ }
18
+ }
19
+
20
+ tests {
21
+ const tv4 = require("tv4")
22
+
23
+ const schema = {
24
+ type: 'object',
25
+ properties: {
26
+ name: { type: 'string' },
27
+ age: { type: 'number' }
28
+ }
29
+ };
30
+
31
+ let responseData = res.getBody();
32
+
33
+ let isValid = tv4.validate(responseData, schema);
34
+
35
+ test("Response body matches expected schema", function () {
36
+ expect(isValid, tv4.error ? tv4.error.message : "").to.be.true;
37
+ });
38
+
39
+ }
You can’t perform that action at this time.
0 commit comments