-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPrimitives.test.ts
More file actions
106 lines (81 loc) · 2.79 KB
/
Primitives.test.ts
File metadata and controls
106 lines (81 loc) · 2.79 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { expectTypeOf } from "expect-type";
import { Primitives } from "../src";
import { ISODateTime } from "../src/Primitives";
import { Course } from "./Course";
import { DeliveryInfo } from "./DeliveryInfo";
import { Learner } from "./Learner";
import { Metadata } from "./Metadata";
import { Product } from "./Product";
import { Step } from "./Step";
import { User } from "./User";
import { Video } from "./Video";
describe("Primitives", () => {
it("should ensure to only return primitive properties excluding methods", () => {
type actualPrimitives = Primitives<Course>;
type expectedPrimitives = {
readonly courseId: string;
};
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
});
it("should get primitive array type from value object array", () => {
type actualPrimitives = Primitives<Learner>;
type expectedPrimitives = {
readonly enrolledCourses: string[];
};
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
});
it("should generate nested primitive object", () => {
type actualPrimitives = Primitives<User>;
type expectedPrimitives = {
readonly address: {
readonly city: string;
readonly street: string;
readonly number: number;
};
};
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
});
it("should generate nested primitive type from array of value objects prop", () => {
type actualPrimitives = Primitives<DeliveryInfo>;
type expectedPrimitives = {
readonly addresses: {
readonly city: string;
readonly street: string;
readonly number: number;
}[];
};
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
});
it("should get primitive type in case it is not a value object", () => {
type actualPrimitives = Primitives<Product>;
type expectedPrimitives = {
readonly active: boolean;
readonly name: string;
};
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
});
it("should get primitive ISO string type from Date", () => {
type actualPrimitives = Primitives<Step>;
type expectedPrimitives = {
readonly name: string;
readonly publishedAt: ISODateTime;
};
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
});
it("should infer the optional properties", () => {
type actualPrimitives = Primitives<Video>;
type expectedPrimitives = {
readonly id: string;
readonly name: string | undefined;
readonly duration: number | undefined;
};
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
});
it("should infer properties with unknown type", () => {
type actualPrimitives = Primitives<Metadata>;
type expectedPrimitives = {
readonly data: Record<string, unknown>;
};
expectTypeOf<actualPrimitives>().toEqualTypeOf<expectedPrimitives>();
});
});