replace operations on Dish with apply

This commit is contained in:
d98762625 2018-10-12 11:30:41 +01:00
parent 48f3a3b18f
commit fa87fc8325
2 changed files with 25 additions and 10 deletions

View file

@ -17,7 +17,7 @@ import OperationError from "../../../src/core/errors/OperationError";
import SyncDish from "../../../src/node/SyncDish";
import fs from "fs";
import { toBase32, Dish } from "../../../src/node/index";
import { toBase32, Dish, SHA3 } from "../../../src/node/index";
import TestRegister from "../../TestRegister";
TestRegister.addApiTests([
@ -324,18 +324,18 @@ TestRegister.addApiTests([
assert.strictEqual(dish.type, 0);
}),
it("Composable Dish: constructed dish should have operation prototype functions", () => {
it("Composable Dish: constructed dish should have apply prototype functions", () => {
const dish = new Dish();
assert.ok(dish.translateDateTimeFormat);
assert.ok(dish.stripHTTPHeaders);
assert.ok(dish.apply);
assert.throws(() => dish.someInvalidFunction());
}),
it("Composable Dish: composed function returns another dish", () => {
const result = new Dish("some input").toBase32();
const result = new Dish("some input").apply(toBase32);
assert.ok(result instanceof SyncDish);
}),
it("Composable dish: infers type from input if needed", () => {
const dish = new Dish("string input");
assert.strictEqual(dish.type, 1);
@ -357,6 +357,16 @@ TestRegister.addApiTests([
fs.unlinkSync("test.txt");
}),
it("Composable Dish: apply should allow set of arguments for operation", () => {
const result = new Dish("input").apply(SHA3, {size: "256"});
assert.strictEqual(result.toString(), "7640cc9b7e3662b2250a43d1757e318bb29fb4860276ac4373b67b1650d6d3e3");
}),
it("Composable Dish: apply functions can be chained", () => {
const result = new Dish("input").apply(toBase32).apply(SHA3, {size: "224"});
assert.strictEqual(result.toString(), "493e8136b759370a415ef2cf2f7a69690441ff86592aba082bc2e2e0");
}),
it("Excluded operations: throw a sensible error when you try and call one", () => {
try {
chef.fork();