-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathsession-utils.test.ts
More file actions
144 lines (133 loc) · 4.7 KB
/
Copy pathsession-utils.test.ts
File metadata and controls
144 lines (133 loc) · 4.7 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { describe, test, expect } from "bun:test"
import { Session } from "../../src/session"
describe("Session.isDefaultTitle", () => {
test("recognises parent session titles", () => {
expect(Session.isDefaultTitle("New session - 2024-01-15T08:30:00.000Z")).toBe(true)
})
test("recognises child session titles", () => {
expect(Session.isDefaultTitle("Child session - 2024-06-01T23:59:59.999Z")).toBe(true)
})
test("rejects arbitrary strings", () => {
expect(Session.isDefaultTitle("My custom title")).toBe(false)
expect(Session.isDefaultTitle("")).toBe(false)
expect(Session.isDefaultTitle("hello world")).toBe(false)
})
test("rejects prefix without valid ISO timestamp", () => {
expect(Session.isDefaultTitle("New session - not-a-date")).toBe(false)
expect(Session.isDefaultTitle("New session - ")).toBe(false)
expect(Session.isDefaultTitle("New session - 2024-01-15")).toBe(false)
})
test("rejects partial prefix matches", () => {
expect(Session.isDefaultTitle("New session 2024-01-15T08:30:00.000Z")).toBe(false)
expect(Session.isDefaultTitle("New session -2024-01-15T08:30:00.000Z")).toBe(false)
})
test("rejects titles with extra content after timestamp", () => {
expect(Session.isDefaultTitle("New session - 2024-01-15T08:30:00.000Z extra")).toBe(false)
})
})
describe("Session.fromRow / toRow", () => {
test("roundtrip preserves fields with full summary", () => {
const info: Session.Info = {
id: "sess_123" as any,
slug: "abc-def",
projectID: "proj_456" as any,
workspaceID: "ws_789" as any,
directory: "/home/user/project",
parentID: "sess_parent" as any,
title: "Test session",
version: "0.5.13",
summary: {
additions: 10,
deletions: 5,
files: 3,
diffs: [{ file: "src/index.ts", additions: 10, deletions: 5 }] as any,
},
share: { url: "https://example.com/share/123" },
revert: "snapshot_abc" as any,
permission: "plan" as any,
time: {
created: 1700000000000,
updated: 1700001000000,
compacting: 1700002000000,
archived: 1700003000000,
},
}
const row = Session.toRow(info)
const restored = Session.fromRow(row as any)
expect(restored.id).toBe(info.id)
expect(restored.slug).toBe(info.slug)
expect(restored.projectID).toBe(info.projectID)
expect(restored.workspaceID).toBe(info.workspaceID)
expect(restored.directory).toBe(info.directory)
expect(restored.parentID).toBe(info.parentID)
expect(restored.title).toBe(info.title)
expect(restored.version).toBe(info.version)
expect(restored.summary).toEqual(info.summary)
expect(restored.share).toEqual(info.share)
expect(restored.revert).toBe(info.revert)
expect(restored.permission).toBe(info.permission)
expect(restored.time.created).toBe(info.time.created)
expect(restored.time.updated).toBe(info.time.updated)
expect(restored.time.compacting).toBe(info.time.compacting)
expect(restored.time.archived).toBe(info.time.archived)
})
test("fromRow produces undefined summary when all summary columns are null", () => {
const row = {
id: "sess_1",
slug: "x",
project_id: "p1",
workspace_id: null,
directory: "/tmp",
parent_id: null,
title: "t",
version: "1",
summary_additions: null,
summary_deletions: null,
summary_files: null,
summary_diffs: null,
share_url: null,
revert: null,
permission: null,
time_created: 1,
time_updated: 2,
time_compacting: null,
time_archived: null,
}
const info = Session.fromRow(row as any)
expect(info.summary).toBeUndefined()
expect(info.share).toBeUndefined()
expect(info.revert).toBeUndefined()
expect(info.parentID).toBeUndefined()
expect(info.workspaceID).toBeUndefined()
expect(info.time.compacting).toBeUndefined()
expect(info.time.archived).toBeUndefined()
})
test("fromRow constructs summary when at least one summary column is non-null", () => {
const row = {
id: "sess_2",
slug: "y",
project_id: "p2",
workspace_id: null,
directory: "/tmp",
parent_id: null,
title: "t",
version: "1",
summary_additions: 5,
summary_deletions: null,
summary_files: null,
summary_diffs: null,
share_url: null,
revert: null,
permission: null,
time_created: 1,
time_updated: 2,
time_compacting: null,
time_archived: null,
}
const info = Session.fromRow(row as any)
expect(info.summary).toBeDefined()
expect(info.summary!.additions).toBe(5)
expect(info.summary!.deletions).toBe(0)
expect(info.summary!.files).toBe(0)
})
})