65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { UpListing, UpObject } from "../";
|
|
|
|
function testObj() {
|
|
const listing = new UpListing({
|
|
a: {
|
|
entity: "test",
|
|
attribute: "string",
|
|
value: { t: "String", c: "hello" },
|
|
provenance: "test",
|
|
timestamp: "0",
|
|
user: "test",
|
|
},
|
|
b: {
|
|
entity: "test",
|
|
attribute: "number",
|
|
value: { t: "Number", c: 1 },
|
|
provenance: "test",
|
|
timestamp: "0",
|
|
user: "test",
|
|
},
|
|
c: {
|
|
entity: "test",
|
|
attribute: "null",
|
|
value: { t: "Null", c: null },
|
|
provenance: "test",
|
|
timestamp: "0",
|
|
user: "test",
|
|
},
|
|
d: {
|
|
entity: "test",
|
|
attribute: "stringy_number",
|
|
value: { t: "String", c: "3" },
|
|
provenance: "test",
|
|
timestamp: "0",
|
|
user: "test",
|
|
},
|
|
});
|
|
return new UpObject("test", listing);
|
|
}
|
|
|
|
describe("UpObject get function", () => {
|
|
test("getting as string works", () => {
|
|
const obj = testObj();
|
|
expect(obj.getAs("string", "string")).toBe("hello");
|
|
expect(obj.getAs("number", "string")).toBe("1");
|
|
expect(obj.getAs("null", "string")).toBe(undefined);
|
|
expect(obj.getAs("stringy_number", "string")).toBe("3");
|
|
});
|
|
|
|
test("getting as number works", () => {
|
|
const obj = testObj();
|
|
expect(obj.getAs("string", "number")).toBe(undefined);
|
|
expect(obj.getAs("number", "number")).toBe(1);
|
|
expect(obj.getAs("null", "number")).toBe(undefined);
|
|
expect(obj.getAs("stringy_number", "number")).toBe(3);
|
|
});
|
|
|
|
test("getting as null works", () => {
|
|
const obj = testObj();
|
|
expect(obj.getAs("string", "null")).toBe(undefined);
|
|
expect(obj.getAs("number", "null")).toBe(undefined);
|
|
expect(obj.getAs("null", "null")).toBe(null);
|
|
expect(obj.getAs("stringy_number", "null")).toBe(undefined);
|
|
});
|
|
});
|