mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-04-02 05:23:21 +00:00
chore: Add tests and fix tests. Remove validation for types not seeable
This commit is contained in:
@@ -38,7 +38,7 @@ describe("builder tests", () => {
|
||||
"minLength": null,
|
||||
"maxLength": null,
|
||||
"patterns": [],
|
||||
"inputmode":"text",
|
||||
"inputMode":"text",
|
||||
"name": "Peer tor address",
|
||||
"required": true
|
||||
}}`
|
||||
@@ -67,6 +67,24 @@ describe("values", () => {
|
||||
validator.unsafeCast("test text");
|
||||
testOutput<typeof validator._TYPE, string>()(null);
|
||||
});
|
||||
test("color", () => {
|
||||
const value = Value.color({
|
||||
name: "Testing",
|
||||
required: false,
|
||||
});
|
||||
const validator = value.validator();
|
||||
validator.unsafeCast("#000000");
|
||||
testOutput<typeof validator._TYPE, string>()(null);
|
||||
});
|
||||
test("datetime", () => {
|
||||
const value = Value.datetime({
|
||||
name: "Testing",
|
||||
required: false,
|
||||
});
|
||||
const validator = value.validator();
|
||||
validator.unsafeCast("2021-01-01");
|
||||
testOutput<typeof validator._TYPE, string>()(null);
|
||||
});
|
||||
test("textarea", () => {
|
||||
const value = Value.textarea({
|
||||
name: "Testing",
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
ListValueSpecOf,
|
||||
isValueSpecListOf,
|
||||
} from "../config/configTypes";
|
||||
import { ListValueSpecOf, isValueSpecListOf } from "../config/configTypes";
|
||||
import { Config } from "../config/builder/config";
|
||||
import { List } from "../config/builder/list";
|
||||
import { Value } from "../config/builder/value";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { writeConvertedFile } from "../../scripts/oldSpecToBuilder";
|
||||
import { writeConvertedFileFromOld } from "../../scripts/oldSpecToBuilder";
|
||||
|
||||
writeConvertedFile(
|
||||
writeConvertedFileFromOld(
|
||||
"./lib/test/output.ts", // Make the location
|
||||
{
|
||||
// Put the config here
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
UnionValueKey,
|
||||
unionValueKey,
|
||||
} from "../config/configTypes";
|
||||
import { deepMerge } from "../util";
|
||||
import { InputSpec, matchInputSpec, testListUnion } from "./output";
|
||||
|
||||
export type IfEquals<T, U, Y = unknown, N = never> = (<G>() => G extends T
|
||||
@@ -15,42 +16,10 @@ export function testOutput<A, B>(): (c: IfEquals<A, B>) => null {
|
||||
return () => null;
|
||||
}
|
||||
|
||||
function isObject(item: unknown): item is object {
|
||||
return !!(item && typeof item === "object" && !Array.isArray(item));
|
||||
}
|
||||
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (
|
||||
x: infer R,
|
||||
) => any
|
||||
? R
|
||||
: never;
|
||||
export function mergeDeep<A extends unknown[]>(...sources: A) {
|
||||
return _mergeDeep({}, ...sources);
|
||||
}
|
||||
function _mergeDeep<A extends unknown[]>(
|
||||
target: UnionToIntersection<A[number]> | {},
|
||||
...sources: A
|
||||
): UnionToIntersection<A[number]> | {} {
|
||||
if (!sources.length) return target;
|
||||
const source = sources.shift();
|
||||
|
||||
if (isObject(target) && isObject(source)) {
|
||||
for (const key in source) {
|
||||
if (isObject((source as any)[key])) {
|
||||
if (!(target as any)[key]) Object.assign(target, { [key]: {} });
|
||||
_mergeDeep((target as any)[key], (source as any)[key]);
|
||||
} else {
|
||||
Object.assign(target, { [key]: (source as any)[key] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _mergeDeep(target, ...sources);
|
||||
}
|
||||
|
||||
/// Testing the types of the input spec
|
||||
testOutput<InputSpec["rpc"]["enable"], boolean>()(null);
|
||||
// @ts-expect-error Because enable should be a boolean
|
||||
testOutput<InputSpec["rpc"]["enable"], string>()(null);
|
||||
testOutput<InputSpec["rpc"]["enable"], boolean>()(null);
|
||||
testOutput<InputSpec["rpc"]["username"], string>()(null);
|
||||
|
||||
testOutput<InputSpec["rpc"]["advanced"]["auth"], string[]>()(null);
|
||||
@@ -135,19 +104,22 @@ describe("Inputs", () => {
|
||||
const output = matchInputSpec.unsafeCast(validInput);
|
||||
expect(output).toEqual(validInput);
|
||||
});
|
||||
test("test errors", () => {
|
||||
test("test no longer care about the conversion of min/max and validating", () => {
|
||||
matchInputSpec.unsafeCast(
|
||||
deepMerge({}, validInput, { rpc: { advanced: { threads: 0 } } }),
|
||||
);
|
||||
});
|
||||
test("test errors should throw for number in string", () => {
|
||||
expect(() =>
|
||||
matchInputSpec.unsafeCast(
|
||||
mergeDeep(validInput, { rpc: { advanced: { threads: 0 } } }),
|
||||
deepMerge({}, validInput, { rpc: { enable: 2 } }),
|
||||
),
|
||||
).toThrowError();
|
||||
expect(() =>
|
||||
matchInputSpec.unsafeCast(mergeDeep(validInput, { rpc: { enable: 2 } })),
|
||||
).toThrowError();
|
||||
|
||||
});
|
||||
test("Test that we set serialversion to something not segwit or non-segwit", () => {
|
||||
expect(() =>
|
||||
matchInputSpec.unsafeCast(
|
||||
mergeDeep(validInput, {
|
||||
deepMerge({}, validInput, {
|
||||
rpc: { advanced: { serialversion: "testing" } },
|
||||
}),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user