-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod_test.ts
More file actions
80 lines (75 loc) · 1.72 KB
/
mod_test.ts
File metadata and controls
80 lines (75 loc) · 1.72 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
import { assertEquals } from "https://deno.land/std@0.127.0/testing/asserts.ts";
import { Equal, Expect } from "./test_utils.ts";
import { Camelize, camelize, CamelizeDeep, camelizeDeep } from "./mod.ts";
// Type Checks
type cases = [
Expect<Equal<Camelize<"id">, "id">>,
Expect<Equal<Camelize<"user_id">, "userId">>,
Expect<Equal<Camelize<"test-company-123">, "testCompany123">>,
Expect<Equal<CamelizeDeep<{ user_id: string }>, { userId: string }>>,
Expect<
Equal<
CamelizeDeep<{
id: number;
bookings: {
booking_id: number;
is_confirmed: boolean;
}[];
}>,
{
id: number;
bookings: {
bookingId: number;
isConfirmed: boolean;
}[];
}
>
>,
];
// Conversion Checks
Deno.test("camelize", () => {
const camelized = camelize("abc_def-ghi.j123");
assertEquals(camelized, "abcDefGhiJ123");
});
Deno.test("camelizeDeep: Object with Array", () => {
assertEquals(
camelizeDeep({
user_id: 123,
bookings: [
{
booking_id: 1,
is_confirmed: true,
},
{
booking_id: 2,
is_confirmed: false,
},
],
created_at: "2022-01-01T00:00:00.000",
}),
{
userId: 123,
bookings: [
{
bookingId: 1,
isConfirmed: true,
},
{
bookingId: 2,
isConfirmed: false,
},
],
createdAt: "2022-01-01T00:00:00.000",
},
);
});
Deno.test("camelizeDeep: Object with Date instance", () => {
assertEquals(
camelizeDeep({
created_at: new Date("2022-01-31T12:00:00.000"),
}),
{
createdAt: new Date("2022-01-31T12:00:00.000"),
},
);
});