/
custom-filters.js
78 lines (55 loc) · 2.24 KB
/
custom-filters.js
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
/// version 1.3.1
/// copy tc-types.d.ts file for vscode autocompletion on tc object
/// <reference path="./tc-types.d.ts" />
// built-in node modules
const CryptoJS = require("crypto-js");
const { v4: uuid4 } = require("uuid");
const axios = require('axios'); // -- you can use async/await to make requests
// ---- All built-in node modules supported
// ajv, ajv-formats, assert, atob, axios, btoa, buffer, chai, crypto-js, fast-xml-parser, fs, http, https, papaparse, stream, tough-cookie, url
// ---- To load any additional node modules from npm
// await tc.loadModule("moduleName"); see example below.
var chai = require("chai");
var expect = chai.expect;
var assert = chai.assert;
async function appendString(input, param1) {
// read a file
var data = await tc.readFile(input);
// execute a command
var result = await tc.exec("echo testing");
return `${input} ${data} ${result}`;
}
function customHmac(input) {
console.log("running custom hmac");
var secretValue = tc.getVar("secret");
let encoded = CryptoJS.HmacSHA256(input, secretValue);
return encoded.toString(CryptoJS.enc.Base64);
}
function preFilter1() {
console.log("set env variable example");
let uuid = uuid4();
// ---- save to active environment
tc.setVar("uuidFromScript", uuid);
// ---- save to local environment
// tc.setVar("uuidFromScript", uuid, "local");
// ---- save to global environment
// tc.setVar("uuidFromScript", uuid, "global");
}
async function customFilter(input) {
console.log("Loading node module - moment");
// ---- load any node module from npm registry
// the first run will take few seconds as it needs to download the module from npm registry
var moment = await tc.loadModule("moment");
// ---- load specific version of moment
// var moment = await tc.loadModule("moment", "2.29.1");
return `${input} ${moment().format()}`;
}
async function testChaiFilter() {
tc.test("Response code is 200", function () {
assert.equal(tc.response.status, 200)
})
tc.test("Response code expect to be 200", function () {
expect(tc.response.status).to.equal(200);
})
}
module.exports = [customHmac, appendString, preFilter1, customFilter, testChaiFilter];