mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
OperationErrors now bubble up to the top of the API.
Added test functionality for node api refactor TestRegister into class
This commit is contained in:
parent
e50758f0a6
commit
5fb50a1759
6 changed files with 194 additions and 30 deletions
45
test/tests/assertionHandler.mjs
Normal file
45
test/tests/assertionHandler.mjs
Normal file
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* assertionHandler.mjs
|
||||
*
|
||||
* Pair native node assertions with a description for
|
||||
* the benefit of the TestRegister.
|
||||
*
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import assert from "assert";
|
||||
|
||||
/**
|
||||
* it - wrapper for assertions to provide a helpful description
|
||||
* to the TestRegister
|
||||
* @param {String} description - The description of the test
|
||||
* @param {Function} assertion - The test
|
||||
*
|
||||
* @example
|
||||
* // One assertion
|
||||
* it("should run one assertion", () => assert.equal(1,1))
|
||||
*
|
||||
* @example
|
||||
* // multiple assertions
|
||||
* it("should handle multiple assertions", () => {
|
||||
* assert.equal(1,1)
|
||||
* assert.notEqual(3,4)
|
||||
* })
|
||||
*
|
||||
* @example
|
||||
* // async assertions
|
||||
* it("should handle async", async () => {
|
||||
* let r = await asyncFunc()
|
||||
* assert(r)
|
||||
* })
|
||||
*/
|
||||
export function it(name, run) {
|
||||
return {
|
||||
name,
|
||||
run
|
||||
};
|
||||
}
|
||||
|
||||
export default it;
|
63
test/tests/nodeApi/nodeApi.mjs
Normal file
63
test/tests/nodeApi/nodeApi.mjs
Normal file
|
@ -0,0 +1,63 @@
|
|||
/* eslint no-console: 0 */
|
||||
|
||||
/**
|
||||
* nodeApi.js
|
||||
*
|
||||
* Test node api utilities
|
||||
*
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import assert from "assert";
|
||||
import it from "../assertionHandler";
|
||||
import chef from "../../../src/node/index";
|
||||
import TestRegister from "../../TestRegister";
|
||||
|
||||
TestRegister.addApiTests([
|
||||
it("should have some operations", () => {
|
||||
assert(chef);
|
||||
assert(chef.toBase32);
|
||||
assert(chef.setUnion);
|
||||
assert(!chef.randomFunction);
|
||||
}),
|
||||
|
||||
it("should have an async/await api", async () => {
|
||||
try {
|
||||
const result = await chef.toBase32("input");
|
||||
assert.notEqual("something", result);
|
||||
} catch (e) {
|
||||
// shouldnt reach here
|
||||
assert(false);
|
||||
}
|
||||
|
||||
try {
|
||||
const fail = chef.setUnion("1");
|
||||
// shouldnt get here
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(true);
|
||||
}
|
||||
}),
|
||||
|
||||
it("should have a callback API", async () => {
|
||||
await chef.toBase32("something", (err, result) => {
|
||||
if (err) {
|
||||
assert(false);
|
||||
} else {
|
||||
assert.equal("ONXW2ZLUNBUW4ZY=", result);
|
||||
}
|
||||
});
|
||||
}),
|
||||
|
||||
it("should handle errors in callback API", async () => {
|
||||
await chef.setUnion("1", (err, result) => {
|
||||
if (err) {
|
||||
assert(true);
|
||||
return;
|
||||
}
|
||||
assert(false);
|
||||
});
|
||||
})
|
||||
]);
|
Loading…
Add table
Add a link
Reference in a new issue