Repository navigation
Expand file tree
/
Copy pathissue_management_test.v
More file actions
184 lines (170 loc) · 5.37 KB
/
Copy pathissue_management_test.v
File metadata and controls
184 lines (170 loc) · 5.37 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
module main
import config
import os
fn issue_management_test_app() !(&App, string) {
db_path := os.join_path(os.temp_dir(), 'gitly_issue_management_${os.getpid()}.sqlite')
os.rm(db_path) or {}
conf := config.Config{
repo_storage_path: os.temp_dir()
archive_path: os.temp_dir()
avatars_path: os.temp_dir()
sqlite: config.SqliteConfig{
path: db_path
}
}
mut app := &App{
db: connect_db(conf)!
config: conf
}
app.create_tables()!
return app, db_path
}
fn cleanup_issue_management_test(mut app App, db_path string) {
app.db.close() or {}
for suffix in ['', '-shm', '-wal'] {
os.rm(db_path + suffix) or {}
}
}
fn insert_issue_management_user(mut app App, id int, username string) ! {
user := User{
id: id
username: username
is_registered: true
}
sql app.db {
insert user into User
}!
}
fn test_issue_labels_are_validated_scoped_and_idempotent() {
$if sqlite? {
mut app, db_path := issue_management_test_app()!
defer {
cleanup_issue_management_test(mut app, db_path)
}
insert_issue_management_user(mut app, 1, 'owner')!
app.add_repo(Repo{
id: 1
name: 'one'
user_id: 1
user_name: 'owner'
is_public: true
})!
app.add_repo(Repo{
id: 2
name: 'two'
user_id: 1
user_name: 'owner'
is_public: true
})!
issue_id := app.add_issue_returning_id(1, 1, 'Before', '')!
other_issue_id := app.add_issue_returning_id(2, 1, 'Other', '')!
label_id := app.add_repo_label(1, ' bug ', '#AABBCC')!
other_label_id := app.add_repo_label(2, 'other', '112233')!
label := app.find_repo_label_by_id(1, label_id) or { panic('label missing') }
assert label.name == 'bug'
assert label.color == 'aabbcc'
app.add_issue_label(issue_id, label_id)!
app.add_issue_label(issue_id, label_id)!
assert app.get_issue_labels(issue_id).map(it.id) == [label_id]
mut cross_repo_rejected := false
app.add_issue_label(issue_id, other_label_id) or { cross_repo_rejected = true }
assert cross_repo_rejected
mut reverse_cross_repo_rejected := false
app.add_issue_label(other_issue_id, label_id) or { reverse_cross_repo_rejected = true }
assert reverse_cross_repo_rejected
app.update_repo_label(1, label_id, 'confirmed', '00FF00')!
updated_label := app.find_repo_label_by_id(1, label_id) or { panic('label missing') }
assert updated_label.name == 'confirmed'
assert updated_label.color == '00ff00'
mut invalid_color_rejected := false
app.update_repo_label(1, label_id, 'confirmed', 'red; color:black') or {
invalid_color_rejected = true
}
assert invalid_color_rejected
mut repeated_hash_rejected := false
app.update_repo_label(1, label_id, 'confirmed', '##ffffff') or {
repeated_hash_rejected = true
}
assert repeated_hash_rejected
app.update_issue(issue_id, ' After ', 'Updated body')!
updated_issue := app.find_issue_by_id(issue_id) or { panic('issue missing') }
assert updated_issue.title == 'After'
assert updated_issue.text == 'Updated body'
app.delete_repo_label(1, label_id)!
assert app.get_issue_labels(issue_id).len == 0
links := sql app.db {
select count from IssueLabel where label_id == label_id
}!
assert links == 0
} $else {
assert true
}
}
fn test_issue_and_discussion_mutations_require_current_private_project_access() {
$if sqlite? {
mut app, db_path := issue_management_test_app()!
defer {
cleanup_issue_management_test(mut app, db_path)
}
insert_issue_management_user(mut app, 1, 'owner')!
insert_issue_management_user(mut app, 2, 'reporter')!
app.add_repo(Repo{
id: 1
name: 'private-project'
user_id: 1
user_name: 'owner'
is_public: false
})!
app.add_project_member(1, 2, 'reporter')!
issue_id := app.add_issue_returning_id(1, 2, 'Issue', '')!
discussion_id := app.add_discussion(1, 2, 'Discussion', '', 'general')!
repo := app.find_repo_by_id(1) or { panic('repository missing') }
issue := app.find_issue_by_id(issue_id) or { panic('issue missing') }
discussion := app.find_discussion(discussion_id) or { panic('discussion missing') }
member_ctx := Context{
logged_in: true
user: User{
id: 2
username: 'reporter'
}
}
assert app.can_manage_issue(member_ctx, repo, issue)
assert app.can_manage_discussion(member_ctx, repo, discussion)
assert app.user_can_manage_labels(2, repo)
member := app.find_project_members(repo.id).first().member
app.remove_project_member(repo.id, member.id)!
assert !app.can_read_repo(member_ctx, repo)
assert !app.can_manage_issue(member_ctx, repo, issue)
assert !app.can_manage_discussion(member_ctx, repo, discussion)
assert !app.user_can_manage_labels(2, repo)
} $else {
assert true
}
}
fn test_delete_repo_issues_removes_issue_metadata_and_comments() {
$if sqlite? {
mut app, db_path := issue_management_test_app()!
defer {
cleanup_issue_management_test(mut app, db_path)
}
insert_issue_management_user(mut app, 1, 'owner')!
app.add_repo(Repo{
id: 1
name: 'project'
user_id: 1
user_name: 'owner'
})!
issue_id := app.add_issue_returning_id(1, 1, 'Issue', '')!
label_id := app.add_repo_label(1, 'bug', 'ff0000')!
app.add_issue_label(issue_id, label_id)!
app.add_issue_comment(1, issue_id, 'comment')!
app.assign_issue(issue_id, 1)!
app.delete_repo_issues(1)!
assert app.list_repo_labels(1).len == 0
assert app.get_all_issue_comments(issue_id).len == 0
assert app.get_issue_assignee_ids(issue_id).len == 0
assert app.get_issue_labels(issue_id).len == 0
} $else {
assert true
}
}