t2500: add test for disown notifications
[aur.git] / test / t2500-notify.sh
blobc9c72080a2c83df85d4bb00d492672d5992fc2a0
1 #!/bin/sh
3 test_description='notify tests'
5 . ./setup.sh
7 test_expect_success 'Test out-of-date notifications.' '
8 cat <<-EOD | sqlite3 aur.db &&
9 /* Use package base IDs which can be distinguished from user IDs. */
10 INSERT INTO PackageBases (ID, Name, MaintainerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1001, "foobar", 1, 0, 0, "This is a test OOD comment.");
11 INSERT INTO PackageBases (ID, Name, MaintainerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1002, "foobar2", 2, 0, 0, "");
12 INSERT INTO PackageBases (ID, Name, MaintainerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1003, "foobar3", NULL, 0, 0, "");
13 INSERT INTO PackageBases (ID, Name, MaintainerUID, SubmittedTS, ModifiedTS, FlaggerComment) VALUES (1004, "foobar4", 1, 0, 0, "");
14 INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1001, 2, 1);
15 INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1001, 4, 2);
16 INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1002, 3, 1);
17 INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1002, 5, 2);
18 INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (1003, 4, 1);
19 EOD
20 >sendmail.out &&
21 "$NOTIFY" flag 1 1001 &&
22 cat <<-EOD >expected &&
23 Subject: AUR Out-of-date Notification for foobar
24 To: tu@localhost
25 Subject: AUR Out-of-date Notification for foobar
26 To: user2@localhost
27 Subject: AUR Out-of-date Notification for foobar
28 To: user@localhost
29 EOD
30 grep "^\(Subject\|To\)" sendmail.out >sendmail.parts &&
31 test_cmp sendmail.parts expected &&
32 cat <<-EOD | sqlite3 aur.db
33 DELETE FROM PackageComaintainers;
34 EOD
37 test_expect_success 'Test subject and body of reset key notifications.' '
38 cat <<-EOD | sqlite3 aur.db &&
39 UPDATE Users SET ResetKey = "12345678901234567890123456789012" WHERE ID = 1;
40 EOD
41 >sendmail.out &&
42 "$NOTIFY" send-resetkey 1 &&
43 grep ^Subject: sendmail.out >actual &&
44 cat <<-EOD >expected &&
45 Subject: AUR Password Reset
46 EOD
47 test_cmp actual expected &&
48 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
49 echo >>actual &&
50 cat <<-EOD >expected &&
51 A password reset request was submitted for the account user associated
52 with your email address. If you wish to reset your password follow the
53 link [1] below, otherwise ignore this message and nothing will happen.
55 [1] https://aur.archlinux.org/passreset/?resetkey=12345678901234567890123456789012
56 EOD
57 test_cmp actual expected
60 test_expect_success 'Test subject and body of welcome notifications.' '
61 cat <<-EOD | sqlite3 aur.db &&
62 UPDATE Users SET ResetKey = "12345678901234567890123456789012" WHERE ID = 1;
63 EOD
64 >sendmail.out &&
65 "$NOTIFY" welcome 1 &&
66 grep ^Subject: sendmail.out >actual &&
67 cat <<-EOD >expected &&
68 Subject: Welcome to the Arch User Repository
69 EOD
70 test_cmp actual expected &&
71 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
72 echo >>actual &&
73 cat <<-EOD >expected &&
74 Welcome to the Arch User Repository! In order to set an initial
75 password for your new account, please click the link [1] below. If the
76 link does not work, try copying and pasting it into your browser.
78 [1] https://aur.archlinux.org/passreset/?resetkey=12345678901234567890123456789012
79 EOD
80 test_cmp actual expected
83 test_expect_success 'Test subject and body of comment notifications.' '
84 cat <<-EOD | sqlite3 aur.db &&
85 /* Use package comments IDs which can be distinguished from other IDs. */
86 INSERT INTO PackageComments (ID, PackageBaseID, UsersID, Comments, RenderedComment) VALUES (2001, 1001, 1, "This is a test comment.", "This is a test comment.");
87 INSERT INTO PackageNotifications (PackageBaseID, UserID) VALUES (1001, 2);
88 UPDATE Users SET CommentNotify = 1 WHERE ID = 2;
89 EOD
90 >sendmail.out &&
91 "$NOTIFY" comment 1 1001 2001 &&
92 grep ^Subject: sendmail.out >actual &&
93 cat <<-EOD >expected &&
94 Subject: AUR Comment for foobar
95 EOD
96 test_cmp actual expected &&
97 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
98 echo >>actual &&
99 cat <<-EOD >expected &&
100 user [1] added the following comment to foobar [2]:
102 This is a test comment.
104 If you no longer wish to receive notifications about this package,
105 please go to the package page [2] and select "Disable notifications".
107 [1] https://aur.archlinux.org/account/user/
108 [2] https://aur.archlinux.org/pkgbase/foobar/
110 test_cmp actual expected
113 test_expect_success 'Test subject and body of update notifications.' '
114 cat <<-EOD | sqlite3 aur.db &&
115 UPDATE Users SET UpdateNotify = 1 WHERE ID = 2;
117 >sendmail.out &&
118 "$NOTIFY" update 1 1001 &&
119 grep ^Subject: sendmail.out >actual &&
120 cat <<-EOD >expected &&
121 Subject: AUR Package Update: foobar
123 test_cmp actual expected &&
124 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
125 echo >>actual &&
126 cat <<-EOD >expected &&
127 user [1] pushed a new commit to foobar [2].
129 If you no longer wish to receive notifications about this package,
130 please go to the package page [2] and select "Disable notifications".
132 [1] https://aur.archlinux.org/account/user/
133 [2] https://aur.archlinux.org/pkgbase/foobar/
135 test_cmp actual expected
138 test_expect_success 'Test subject and body of out-of-date notifications.' '
139 >sendmail.out &&
140 "$NOTIFY" flag 1 1001 &&
141 grep ^Subject: sendmail.out >actual &&
142 cat <<-EOD >expected &&
143 Subject: AUR Out-of-date Notification for foobar
145 test_cmp actual expected &&
146 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
147 echo >>actual &&
148 cat <<-EOD >expected &&
149 Your package foobar [1] has been flagged out-of-date by user [2]:
151 This is a test OOD comment.
153 [1] https://aur.archlinux.org/pkgbase/foobar/
154 [2] https://aur.archlinux.org/account/user/
156 test_cmp actual expected
159 test_expect_success 'Test subject and body of adopt notifications.' '
160 >sendmail.out &&
161 "$NOTIFY" adopt 1 1001 &&
162 grep ^Subject: sendmail.out >actual &&
163 cat <<-EOD >expected &&
164 Subject: AUR Ownership Notification for foobar
166 test_cmp actual expected &&
167 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
168 echo >>actual &&
169 cat <<-EOD >expected &&
170 The package foobar [1] was adopted by user [2].
172 [1] https://aur.archlinux.org/pkgbase/foobar/
173 [2] https://aur.archlinux.org/account/user/
175 test_cmp actual expected
178 test_expect_success 'Test subject and body of disown notifications.' '
179 >sendmail.out &&
180 "$NOTIFY" disown 1 1001 &&
181 grep ^Subject: sendmail.out >actual &&
182 cat <<-EOD >expected &&
183 Subject: AUR Ownership Notification for foobar
185 test_cmp actual expected &&
186 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
187 echo >>actual &&
188 cat <<-EOD >expected &&
189 The package foobar [1] was disowned by user [2].
191 [1] https://aur.archlinux.org/pkgbase/foobar/
192 [2] https://aur.archlinux.org/account/user/
194 test_cmp actual expected
197 test_expect_success 'Test subject and body of co-maintainer addition notifications.' '
198 >sendmail.out &&
199 "$NOTIFY" comaintainer-add 1 1001 &&
200 grep ^Subject: sendmail.out >actual &&
201 cat <<-EOD >expected &&
202 Subject: AUR Co-Maintainer Notification for foobar
204 test_cmp actual expected &&
205 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
206 echo >>actual &&
207 cat <<-EOD >expected &&
208 You were added to the co-maintainer list of foobar [1].
210 [1] https://aur.archlinux.org/pkgbase/foobar/
212 test_cmp actual expected
215 test_expect_success 'Test subject and body of co-maintainer removal notifications.' '
216 >sendmail.out &&
217 "$NOTIFY" comaintainer-remove 1 1001 &&
218 grep ^Subject: sendmail.out >actual &&
219 cat <<-EOD >expected &&
220 Subject: AUR Co-Maintainer Notification for foobar
222 test_cmp actual expected &&
223 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
224 echo >>actual &&
225 cat <<-EOD >expected &&
226 You were removed from the co-maintainer list of foobar [1].
228 [1] https://aur.archlinux.org/pkgbase/foobar/
230 test_cmp actual expected
233 test_expect_success 'Test subject and body of delete notifications.' '
234 >sendmail.out &&
235 "$NOTIFY" delete 1 1001 &&
236 grep ^Subject: sendmail.out >actual &&
237 cat <<-EOD >expected &&
238 Subject: AUR Package deleted: foobar
240 test_cmp actual expected &&
241 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
242 echo >>actual &&
243 cat <<-EOD >expected &&
244 user [1] deleted foobar [2].
246 You will no longer receive notifications about this package.
248 [1] https://aur.archlinux.org/account/user/
249 [2] https://aur.archlinux.org/pkgbase/foobar/
251 test_cmp actual expected
254 test_expect_success 'Test subject and body of merge notifications.' '
255 >sendmail.out &&
256 "$NOTIFY" delete 1 1001 1002 &&
257 grep ^Subject: sendmail.out >actual &&
258 cat <<-EOD >expected &&
259 Subject: AUR Package deleted: foobar
261 test_cmp actual expected &&
262 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
263 echo >>actual &&
264 cat <<-EOD >expected &&
265 user [1] merged foobar [2] into foobar2 [3].
267 If you no longer wish receive notifications about the new package,
268 please go to [3] and click "Disable notifications".
270 [1] https://aur.archlinux.org/account/user/
271 [2] https://aur.archlinux.org/pkgbase/foobar/
272 [3] https://aur.archlinux.org/pkgbase/foobar2/
274 test_cmp actual expected
277 test_expect_success 'Test subject and body of request open notifications.' '
278 cat <<-EOD | sqlite3 aur.db &&
279 /* Use package request IDs which can be distinguished from other IDs. */
280 INSERT INTO PackageRequests (ID, PackageBaseID, PackageBaseName, UsersID, ReqTypeID, Comments, ClosureComment) VALUES (3001, 1001, "foobar", 1, 1, "This is a request test comment.", "");
282 >sendmail.out &&
283 "$NOTIFY" request-open 1 3001 orphan 1001 &&
284 grep ^Subject: sendmail.out >actual &&
285 cat <<-EOD >expected &&
286 Subject: [PRQ#3001] Orphan Request for foobar
288 test_cmp actual expected &&
289 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
290 echo >>actual &&
291 cat <<-EOD >expected &&
292 user [1] filed a orphan request for foobar [2]:
294 This is a request test comment.
296 [1] https://aur.archlinux.org/account/user/
297 [2] https://aur.archlinux.org/pkgbase/foobar/
299 test_cmp actual expected
302 test_expect_success 'Test subject and body of request open notifications for merge requests.' '
303 >sendmail.out &&
304 "$NOTIFY" request-open 1 3001 merge 1001 foobar2 &&
305 grep ^Subject: sendmail.out >actual &&
306 cat <<-EOD >expected &&
307 Subject: [PRQ#3001] Merge Request for foobar
309 test_cmp actual expected &&
310 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
311 echo >>actual &&
312 cat <<-EOD >expected &&
313 user [1] filed a request to merge foobar [2] into foobar2 [3]:
315 This is a request test comment.
317 [1] https://aur.archlinux.org/account/user/
318 [2] https://aur.archlinux.org/pkgbase/foobar/
319 [3] https://aur.archlinux.org/pkgbase/foobar2/
321 test_cmp actual expected
324 test_expect_success 'Test subject and body of request close notifications.' '
325 >sendmail.out &&
326 "$NOTIFY" request-close 1 3001 accepted &&
327 grep ^Subject: sendmail.out >actual &&
328 cat <<-EOD >expected &&
329 Subject: [PRQ#3001] Deletion Request for foobar Accepted
331 test_cmp actual expected &&
332 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
333 echo >>actual &&
334 cat <<-EOD >expected &&
335 Request #3001 has been accepted by user [1].
337 [1] https://aur.archlinux.org/account/user/
339 test_cmp actual expected
342 test_expect_success 'Test subject and body of request close notifications (auto-accept).' '
343 >sendmail.out &&
344 "$NOTIFY" request-close 0 3001 accepted &&
345 grep ^Subject: sendmail.out >actual &&
346 cat <<-EOD >expected &&
347 Subject: [PRQ#3001] Deletion Request for foobar Accepted
349 test_cmp actual expected &&
350 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
351 echo >>actual &&
352 cat <<-EOD >expected &&
353 Request #3001 has been accepted automatically by the Arch User
354 Repository package request system.
356 test_cmp actual expected
359 test_expect_success 'Test subject and body of request close notifications with closure comment.' '
360 cat <<-EOD | sqlite3 aur.db &&
361 UPDATE PackageRequests SET ClosureComment = "This is a test closure comment." WHERE ID = 3001;
363 >sendmail.out &&
364 "$NOTIFY" request-close 1 3001 accepted &&
365 grep ^Subject: sendmail.out >actual &&
366 cat <<-EOD >expected &&
367 Subject: [PRQ#3001] Deletion Request for foobar Accepted
369 test_cmp actual expected &&
370 sed -n "/^\$/,\$p" sendmail.out | base64 -d >actual &&
371 echo >>actual &&
372 cat <<-EOD >expected &&
373 Request #3001 has been accepted by user [1]:
375 This is a test closure comment.
377 [1] https://aur.archlinux.org/account/user/
379 test_cmp actual expected
382 test_expect_success 'Test subject and body of TU vote reminders.' '
383 >sendmail.out &&
384 "$NOTIFY" tu-vote-reminder 1 &&
385 grep ^Subject: sendmail.out | head -1 >actual &&
386 cat <<-EOD >expected &&
387 Subject: TU Vote Reminder: Proposal 1
389 test_cmp actual expected &&
390 sed -n "/^\$/,\$p" sendmail.out | head -4 | base64 -d >actual &&
391 echo >>actual &&
392 cat <<-EOD >expected &&
393 Please remember to cast your vote on proposal 1 [1]. The voting period
394 ends in less than 48 hours.
396 [1] https://aur.archlinux.org/tu/?id=1
398 test_cmp actual expected
401 test_done