-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.test.ts
81 lines (77 loc) · 2.21 KB
/
api.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/
import { describe, expect, it } from "vitest";
import { genTransformResponse } from "./api";
const projectSchema = {
description: "View of a Project",
type: "object",
properties: {
description: {
description: "human-readable free-form text about a resource",
type: "string",
},
id: {
description:
"unique, immutable, system-controlled identifier for each resource",
type: "string",
format: "uuid",
},
name: {
description:
"unique, mutable, user-controlled identifier for each resource",
allOf: [Array],
},
time_created: {
description: "timestamp when this resource was created",
type: "string",
format: "date-time",
},
time_modified: {
description: "timestamp when this resource was last modified",
type: "string",
format: "date-time",
},
},
required: ["description", "id", "name", "time_created", "time_modified"],
};
// TODO: add array and nested object properties
const noTransforms = {
description: "View of a Project",
type: "object",
properties: {
description: {
description: "human-readable free-form text about a resource",
type: "string",
},
id: {
description:
"unique, immutable, system-controlled identifier for each resource",
type: "string",
format: "uuid",
},
name: {
description:
"unique, mutable, user-controlled identifier for each resource",
allOf: [Array],
},
},
required: ["description", "id", "name"],
};
describe("generateTransformFunction", () => {
it("handles timestamps at top level", () => {
expect(genTransformResponse(projectSchema)).toMatchInlineSnapshot(`
"(o) => {
o.time_created = new Date(o.time_created)
o.time_modified = new Date(o.time_modified)
}"
`);
});
it("returns null when there are no transforms to make", () => {
expect(genTransformResponse(noTransforms)).toEqual(undefined);
});
});