-
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
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com>
// SPDX-License-Identifier: AGPL-3.0-only
import { describe, test, expect } from "bun:test";
import * as proto from "@bufbuild/protobuf";
import { DateSchema } from "@yamori/proto/yamori/type/v1/date_pb.js";
import { WorkspaceSchema } from "@yamori/proto/yamori/workspace/v1/workspace_pb.js";
import { href, deserializeDate, serializeDate } from "./meta.ts";
describe("serializeDate", () => {
test("Should serialize full date", () => {
expect(serializeDate({ year: 2020, month: 11, day: 30 })).toBe("2020-11-30");
});
test("Should pad month and day", () => {
expect(serializeDate({ year: 2020, month: 1, day: 1 })).toBe("2020-01-01");
});
});
describe("deserializeDate", () => {
test("Should deserialize full date", () => {
expect(deserializeDate("2020-02-12")).toMatchObject({
year: 2020,
month: 2,
day: 12,
});
});
test("Should deserialize non-0-prefixed numbers", () => {
expect(deserializeDate("2020-2-2")).toMatchObject({
year: 2020,
month: 2,
day: 2,
});
});
test("Should not parse non-base10 numbers", () => {
expect(deserializeDate("2020-02-ff")).toBeNull();
});
});
describe("href", () => {
test("Should not append search part when both since and until are empty", () => {
expect(
href({
workspace: proto.create(WorkspaceSchema, {
id: { value: "ws-foo" },
}),
}),
).toBe("/ws-foo/summary");
});
test("Should set since param", () => {
expect(
href({
workspace: proto.create(WorkspaceSchema, {
id: { value: "ws-foo" },
}),
since: proto.create(DateSchema, {
year: 2020,
month: 2,
day: 2,
}),
}),
).toBe("/ws-foo/summary?since=2020-02-02");
});
test("Should set since param", () => {
expect(
href({
workspace: proto.create(WorkspaceSchema, {
id: { value: "ws-foo" },
}),
since: proto.create(DateSchema, {
year: 2020,
month: 2,
day: 2,
}),
}),
).toBe("/ws-foo/summary?since=2020-02-02");
});
test("Should set until param", () => {
expect(
href({
workspace: proto.create(WorkspaceSchema, {
id: { value: "ws-foo" },
}),
until: proto.create(DateSchema, {
year: 2020,
month: 2,
day: 2,
}),
}),
).toBe("/ws-foo/summary?until=2020-02-02");
});
test("Should set search params", () => {
expect(
href({
workspace: proto.create(WorkspaceSchema, {
id: { value: "ws-foo" },
}),
since: proto.create(DateSchema, {
year: 2020,
month: 2,
day: 1,
}),
until: proto.create(DateSchema, {
year: 2020,
month: 3,
day: 1,
}),
}),
).toBe("/ws-foo/summary?since=2020-02-01&until=2020-03-01");
});
});