mirror of
https://github.com/gchq/CyberChef.git
synced 2025-06-17 19:55:18 -04:00
update tests to reflect new API behaviour
This commit is contained in:
parent
45d2fbc5fc
commit
33f2c89716
4 changed files with 2106 additions and 2132 deletions
|
@ -13,6 +13,10 @@
|
|||
import assert from "assert";
|
||||
import it from "../assertionHandler";
|
||||
import chef from "../../../src/node/index";
|
||||
import OperationError from "../../../src/core/errors/OperationError";
|
||||
import SyncDish from "../../../src/node/SyncDish";
|
||||
|
||||
import { toBase32 } from "../../../src/node/index";
|
||||
import TestRegister from "../../TestRegister";
|
||||
|
||||
TestRegister.addApiTests([
|
||||
|
@ -23,9 +27,13 @@ TestRegister.addApiTests([
|
|||
assert(!chef.randomFunction);
|
||||
}),
|
||||
|
||||
it("should have an async/await api", async () => {
|
||||
it("should export other functions at top level", () => {
|
||||
assert(toBase32);
|
||||
}),
|
||||
|
||||
it("should be synchronous", () => {
|
||||
try {
|
||||
const result = await chef.toBase32("input");
|
||||
const result = chef.toBase32("input");
|
||||
assert.notEqual("something", result);
|
||||
} catch (e) {
|
||||
// shouldnt reach here
|
||||
|
@ -41,45 +49,63 @@ TestRegister.addApiTests([
|
|||
}
|
||||
}),
|
||||
|
||||
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;
|
||||
}
|
||||
it("should not catch Errors", () => {
|
||||
try {
|
||||
chef.setUnion("1");
|
||||
assert(false);
|
||||
});
|
||||
} catch (e) {
|
||||
assert(e instanceof OperationError);
|
||||
}
|
||||
}),
|
||||
|
||||
it("should accept arguments in object format for operations", async () => {
|
||||
const result = await chef.setUnion("1 2 3 4:3 4 5 6", {
|
||||
it("should accept arguments in object format for operations", () => {
|
||||
const result = chef.setUnion("1 2 3 4:3 4 5 6", {
|
||||
itemDelimiter: " ",
|
||||
sampleDelimiter: ":"
|
||||
});
|
||||
|
||||
assert.equal(result, "1 2 3 4 5 6");
|
||||
assert.equal(result.value, "1 2 3 4 5 6");
|
||||
}),
|
||||
|
||||
it("should accept just some of the optional arguments being overriden", async () => {
|
||||
const result = await chef.setIntersection("1 2 3 4 5\\n\\n3 4 5", {
|
||||
it("should accept just some of the optional arguments being overriden", () => {
|
||||
const result = chef.setIntersection("1 2 3 4 5\\n\\n3 4 5", {
|
||||
itemDelimiter: " ",
|
||||
});
|
||||
|
||||
assert.equal(result, "3 4 5");
|
||||
assert.equal(result.value, "3 4 5");
|
||||
}),
|
||||
|
||||
it("should accept no override arguments and just use the default values", async () => {
|
||||
const result = await chef.powerSet("1,2,3");
|
||||
assert.equal(result, "\n3\n2\n1\n2,3\n1,3\n1,2\n1,2,3\n");
|
||||
})
|
||||
it("should accept no override arguments and just use the default values", () => {
|
||||
const result = chef.powerSet("1,2,3");
|
||||
assert.equal(result.value, "\n3\n2\n1\n2,3\n1,3\n1,2\n1,2,3\n");
|
||||
}),
|
||||
|
||||
it("should return an object with a .to method", () => {
|
||||
const result = chef.toBase32("input");
|
||||
assert(result.to);
|
||||
assert.equal(result.to("string"), "NFXHA5LU");
|
||||
}),
|
||||
|
||||
it("should return an object with a .get method", () => {
|
||||
const result = chef.toBase32("input");
|
||||
assert(result.get);
|
||||
assert.equal(result.get("string"), "NFXHA5LU");
|
||||
}),
|
||||
|
||||
it("should return a SyncDish", () => {
|
||||
const result = chef.toBase32("input");
|
||||
assert(result instanceof SyncDish);
|
||||
}),
|
||||
|
||||
it("should coerce to a string as you expect", () => {
|
||||
const result = chef.fromBase32(chef.toBase32("something"));
|
||||
assert.equal(String(result), "something");
|
||||
// This kind of coercion uses toValue
|
||||
assert.equal(""+result, "NaN");
|
||||
}),
|
||||
|
||||
it("should coerce to a number as you expect", () => {
|
||||
const result = chef.fromBase32(chef.toBase32("32"));
|
||||
assert.equal(3 + result, 35);
|
||||
}),
|
||||
]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue