|
4 | 4 | [clojars.email :as email] |
5 | 5 | [clojars.integration.steps :refer [disable-mfa enable-mfa login-as register-as]] |
6 | 6 | ;; for defmethods |
| 7 | + [clojars.notifications.group] |
7 | 8 | [clojars.notifications.user] |
8 | 9 | [clojars.test-helper :as help :refer [with-test-system]] |
| 10 | + [clojure.string :as str] |
9 | 11 | [clojure.test :refer [deftest is testing use-fixtures]] |
10 | 12 | [kerodon.core :refer [check fill-in follow follow-redirect |
11 | 13 | press session visit within]] |
|
278 | 280 | (has (text? "The reset code was not found. Please ask for a new code in the forgot password page"))))) |
279 | 281 |
|
280 | 282 | (deftest admin-can-add-member-to-group |
281 | | - (-> (session (help/app)) |
282 | | - (register-as "fixture" "fixture@example.org" "password")) |
283 | | - (-> (session (help/app)) |
284 | | - (register-as "dantheman" "test@example.org" "password") |
285 | | - (visit "/groups/org.clojars.dantheman") |
286 | | - (fill-in [:#username] "fixture") |
287 | | - (press "Add Member") |
288 | | - ;;(follow-redirect) |
289 | | - (within [:table.group-member-list |
290 | | - [:tr enlive/last-of-type] |
291 | | - [:td enlive/first-of-type]] |
292 | | - (has (text? "fixture"))) |
293 | | - (within [:table.group-member-list |
294 | | - [:tr enlive/last-of-type] |
295 | | - [:td (enlive/nth-of-type 2)]] |
296 | | - (has (text? "No")))) |
297 | | - |
298 | | - (is (some #{"fixture"} (db/group-membernames help/*db* "org.clojars.dantheman"))) |
299 | | - |
300 | | - (help/match-audit {:username "dantheman"} |
301 | | - {:tag "member-added" |
302 | | - :user "dantheman" |
303 | | - :group_name "org.clojars.dantheman" |
304 | | - :message "user 'fixture' added as member"})) |
| 283 | + (with-test-system |
| 284 | + (-> (session (help/app)) |
| 285 | + (register-as "fixture" "fixture@example.org" "password")) |
| 286 | + (-> (session (help/app)) |
| 287 | + (register-as "dantheman" "test@example.org" "password") |
| 288 | + ((fn [session] (email/expect-mock-emails 2) session)) |
| 289 | + (visit "/groups/org.clojars.dantheman") |
| 290 | + (fill-in [:#username] "fixture") |
| 291 | + (press "Add Member") |
| 292 | + ;;(follow-redirect) |
| 293 | + (within [:table.group-member-list |
| 294 | + [:tr enlive/last-of-type] |
| 295 | + [:td enlive/first-of-type]] |
| 296 | + (has (text? "fixture"))) |
| 297 | + (within [:table.group-member-list |
| 298 | + [:tr enlive/last-of-type] |
| 299 | + [:td (enlive/nth-of-type 2)]] |
| 300 | + (has (text? "No")))) |
| 301 | + |
| 302 | + (is (some #{"fixture"} (db/group-membernames help/*db* "org.clojars.dantheman"))) |
| 303 | + |
| 304 | + (help/match-audit {:username "dantheman"} |
| 305 | + {:tag "member-added" |
| 306 | + :user "dantheman" |
| 307 | + :group_name "org.clojars.dantheman" |
| 308 | + :message "user 'fixture' added as member"}) |
| 309 | + |
| 310 | + (is (true? (email/wait-for-mock-emails))) |
| 311 | + (is (= 2 (count @email/mock-emails))) |
| 312 | + (is (= #{"fixture@example.org" "test@example.org"} |
| 313 | + (into #{} (map first) @email/mock-emails))) |
| 314 | + (is (every? #(= "A member was added to the group org.clojars.dantheman" |
| 315 | + %) |
| 316 | + (into [] (map second) @email/mock-emails))) |
| 317 | + (is (every? #(str/starts-with? % "User 'fixture' was added to the org.clojars.dantheman group by dantheman.\n\n") |
| 318 | + (into [] (map #(nth % 2)) @email/mock-emails))))) |
305 | 319 |
|
306 | 320 | (deftest admin-can-add-admin-to-group |
307 | | - (-> (session (help/app)) |
308 | | - (register-as "fixture" "fixture@example.org" "password")) |
309 | | - (-> (session (help/app)) |
310 | | - (register-as "dantheman" "test@example.org" "password") |
311 | | - (visit "/groups/org.clojars.dantheman") |
312 | | - (fill-in [:#username] "fixture") |
313 | | - (check [:#admin]) |
314 | | - (press "Add Member") |
315 | | - ;;(follow-redirect) |
316 | | - (within [:table.group-member-list |
317 | | - [:tr enlive/last-of-type] |
318 | | - [:td enlive/first-of-type]] |
319 | | - (has (text? "fixture"))) |
320 | | - (within [:table.group-member-list |
321 | | - [:tr enlive/last-of-type] |
322 | | - [:td (enlive/nth-of-type 2)]] |
323 | | - (has (text? "Yes")))) |
324 | | - |
325 | | - (is (some #{"fixture"} (db/group-adminnames help/*db* "org.clojars.dantheman"))) |
326 | | - |
327 | | - (help/match-audit {:username "dantheman"} |
328 | | - {:tag "member-added" |
329 | | - :user "dantheman" |
330 | | - :group_name "org.clojars.dantheman" |
331 | | - :message "user 'fixture' added as admin"})) |
| 321 | + (with-test-system |
| 322 | + (-> (session (help/app)) |
| 323 | + (register-as "fixture" "fixture@example.org" "password")) |
| 324 | + (-> (session (help/app)) |
| 325 | + (register-as "dantheman" "test@example.org" "password") |
| 326 | + ((fn [session] (email/expect-mock-emails 2) session)) |
| 327 | + (visit "/groups/org.clojars.dantheman") |
| 328 | + (fill-in [:#username] "fixture") |
| 329 | + (check [:#admin]) |
| 330 | + (press "Add Member") |
| 331 | + (within [:table.group-member-list |
| 332 | + [:tr enlive/last-of-type] |
| 333 | + [:td enlive/first-of-type]] |
| 334 | + (has (text? "fixture"))) |
| 335 | + (within [:table.group-member-list |
| 336 | + [:tr enlive/last-of-type] |
| 337 | + [:td (enlive/nth-of-type 2)]] |
| 338 | + (has (text? "Yes")))) |
| 339 | + |
| 340 | + (is (some #{"fixture"} (db/group-adminnames help/*db* "org.clojars.dantheman"))) |
| 341 | + |
| 342 | + (help/match-audit {:username "dantheman"} |
| 343 | + {:tag "member-added" |
| 344 | + :user "dantheman" |
| 345 | + :group_name "org.clojars.dantheman" |
| 346 | + :message "user 'fixture' added as admin"}) |
| 347 | + |
| 348 | + (is (true? (email/wait-for-mock-emails))) |
| 349 | + (is (= 2 (count @email/mock-emails))) |
| 350 | + (is (= #{"fixture@example.org" "test@example.org"} |
| 351 | + (into #{} (map first) @email/mock-emails))) |
| 352 | + (is (every? #(= "An admin member was added to the group org.clojars.dantheman" |
| 353 | + %) |
| 354 | + (into [] (map second) @email/mock-emails))) |
| 355 | + (is (every? #(str/starts-with? % "User 'fixture' was added as an admin to the org.clojars.dantheman group by dantheman.\n\n") |
| 356 | + (into [] (map #(nth % 2)) @email/mock-emails))))) |
332 | 357 |
|
333 | 358 | (deftest admin-can-remove-user-from-group |
334 | | - (-> (session (help/app)) |
335 | | - (register-as "fixture" "fixture@example.org" "password")) |
336 | | - (-> (session (help/app)) |
337 | | - (register-as "dantheman" "test@example.org" "password") |
338 | | - (visit "/groups/org.clojars.dantheman") |
339 | | - (fill-in [:#username] "fixture") |
340 | | - (press "Add Member") |
341 | | - (press "Remove Member")) |
342 | | - (help/match-audit {:username "dantheman"} |
343 | | - {:tag "member-removed" |
344 | | - :user "dantheman" |
345 | | - :group_name "org.clojars.dantheman" |
346 | | - :message "user 'fixture' removed"})) |
| 359 | + (with-test-system |
| 360 | + (-> (session (help/app)) |
| 361 | + (register-as "fixture" "fixture@example.org" "password")) |
| 362 | + (-> (session (help/app)) |
| 363 | + (register-as "dantheman" "test@example.org" "password") |
| 364 | + (visit "/groups/org.clojars.dantheman") |
| 365 | + (fill-in [:#username] "fixture") |
| 366 | + (press "Add Member") |
| 367 | + ((fn [session] (email/expect-mock-emails 2) session)) |
| 368 | + (press "Remove Member")) |
| 369 | + (help/match-audit {:username "dantheman"} |
| 370 | + {:tag "member-removed" |
| 371 | + :user "dantheman" |
| 372 | + :group_name "org.clojars.dantheman" |
| 373 | + :message "user 'fixture' removed"}) |
| 374 | + |
| 375 | + (is (true? (email/wait-for-mock-emails))) |
| 376 | + (is (= 2 (count @email/mock-emails))) |
| 377 | + (is (= #{"fixture@example.org" "test@example.org"} |
| 378 | + (into #{} (map first) @email/mock-emails))) |
| 379 | + (is (every? #(= "A member was removed from the group org.clojars.dantheman" |
| 380 | + %) |
| 381 | + (into [] (map second) @email/mock-emails))) |
| 382 | + (is (every? #(str/starts-with? % "User 'fixture' was removed from the org.clojars.dantheman group by dantheman.\n\n") |
| 383 | + (into [] (map #(nth % 2)) @email/mock-emails))))) |
347 | 384 |
|
348 | 385 | (deftest user-must-exist-to-be-added-to-group |
349 | 386 | (-> (session (help/app)) |
|
0 commit comments