-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaskStatusQuery.test.ts
165 lines (131 loc) · 4.25 KB
/
taskStatusQuery.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { taskStatusQuery } from './taskStatusQuery'
import { User } from '../../dbschema/interfaces'
import e from '../edgedb/builder'
import { client } from '../edgedb/client'
import { createTaskQuery } from './createTaskQuery'
import { Client, DateDuration } from 'edgedb'
import { cleanup } from './helpers/cleanup'
import { insertTaskActionQuery } from './helpers/insertTaskAction'
describe('taskStatusQuery', () => {
let currentUser: User
let currentUserClient: Client
afterAll(cleanup)
beforeAll(async () => {
;[currentUser] = await e
.select(e.User, () => ({
...e.User['*'],
limit: 1,
}))
.run(client)
currentUserClient = client.withGlobals({ currentUserId: currentUser.id })
})
describe('with the due date in the future', () => {
let dueAt: Date
const title = 'test'
beforeAll(async () => {
dueAt = await e
.select(e.op(e.datetime_current(), '+', e.cal.date_duration('2 days')))
.run(client)
})
it('equals InProgress when last action is Opened', async () => {
const { task } = await createTaskQuery.run(currentUserClient, {
title,
dueAt,
assignees: [currentUser.id],
})
const result = await taskStatusQuery.run(client, task)
if (!result) {
throw new Error()
}
expect(result.computedStatus).toBe('InProgress')
})
it('equals InProgress when last action is Edited', async () => {
const { task } = await createTaskQuery.run(currentUserClient, {
title,
assignees: [currentUser.id],
})
await e
.insert(e.TaskAction, {
kind: e.TaskActionKind.Edited,
user: e.global.currentUser,
task: e.select(e.Task, () => ({ filter_single: { id: task.id } })),
})
.run(currentUserClient)
const result = await taskStatusQuery.run(client, task)
if (!result) {
throw new Error()
}
expect(result.computedStatus).toBe('InProgress')
})
it('equals Completed when last action is Closed', async () => {
const { task } = await createTaskQuery.run(currentUserClient, {
title,
dueAt,
assignees: [currentUser.id],
})
await e
.insert(e.TaskAction, {
kind: e.TaskActionKind.Closed,
user: e.global.currentUser,
task: e.select(e.Task, () => ({ filter_single: { id: task.id } })),
})
.run(currentUserClient)
const result = await taskStatusQuery.run(client, task)
if (!result) {
throw new Error()
}
expect(result.computedStatus).toBe('Completed')
})
})
describe('with the due date in the past', () => {
const title = 'test'
const deadline = new DateDuration(0, 0, 0, -2)
it('equals PastDue when last action is Opened', async () => {
const { task } = await createTaskQuery.run(currentUserClient, {
title,
deadline,
assignees: [currentUser.id],
})
const result = await taskStatusQuery.run(client, task)
if (!result) {
throw new Error()
}
expect(result.computedStatus).toBe('PastDue')
})
it('equals PastDue when last action is Edited', async () => {
const { task } = await createTaskQuery.run(currentUserClient, {
title,
deadline,
assignees: [currentUser.id],
})
await e
.insert(e.TaskAction, {
kind: e.TaskActionKind.Edited,
user: e.global.currentUser,
task: e.select(e.Task, () => ({ filter_single: { id: task.id } })),
})
.run(currentUserClient)
const result = await taskStatusQuery.run(client, task)
if (!result) {
throw new Error()
}
expect(result.computedStatus).toBe('PastDue')
})
it('equals Completed when last action is Closed', async () => {
const { task } = await createTaskQuery.run(currentUserClient, {
title,
deadline,
assignees: [currentUser.id],
})
await insertTaskActionQuery.run(currentUserClient, {
id: task.id,
kind: 'Closed',
})
const result = await taskStatusQuery.run(client, task)
if (!result) {
throw new Error()
}
expect(result.computedStatus).toBe('Completed')
})
})
})