forge
Explore
Log in

Don't you dare go Hollow

Page tests share their fixtures and merge into tables

Browse files at this commit

a83ea02f0be62bc5958cbffec5844b33b261d6d4Ahmet Kaan GümüşParent: 1a6f67b
  • test
    • page tests share their fixtures and merge into tables
Show full message
✅ test: page tests share their fixtures and merge into tables

issue_meta_tests.rs: 13 -> 3 tests (one fixture per scenario group).
issues_list.rs: 15 -> 3 tests (pristine flow, populated flow, private repo).
issue_view.rs: 13 -> 2 tests (page rendering and form gating, comment/close/edit rules).

Merged tests keep every assertion, with a case label in each message.
Tests that need a pristine instance (empty list, pagination, private repo) stay on their own fixture.
The issue-number precondition in the state test was dropped; the number is not the thing under test.
crates/forge-web/src/pages/issue_meta_tests.rsmodified+196 -292
@@ -150,15 +150,63 @@ async fn seeded() -> Seed {
150150
151151 const FORGE_LABELS: &str = "/tahinli/forge/labels";
152152
153+/// Label and milestone writes on forge, in the order the cycle needs: private repos 404 for
154+/// anonymous viewers, CSRF and role refusals first, then the create, duplicate, edit and delete
155+/// cycle (the list ends empty), then the archived refusal last.
153156 #[tokio::test]
154-async fn owner_creates_edits_and_deletes_a_label() {
157+async fn label_writes_follow_csrf_roles_and_archive_rules() {
155158 let s = seeded().await;
156- let cookie = Some(s.tahinli_cookie.as_str());
159+ let store = &s.site.store;
160+ let owner = Some(s.tahinli_cookie.as_str());
161+
162+ // [anonymous] private repo pages are 404, the public milestones page renders.
163+ for uri in ["/tahinli/secret/labels", "/tahinli/secret/milestones"] {
164+ let res = call(&s.site, "GET", uri, None, None).await;
165+ assert_eq!(res.status, 404, "private {uri}");
166+ }
167+ let res = call(&s.site, "GET", "/tahinli/forge/milestones", None, None).await;
168+ assert_eq!(res.status, 200, "public milestones");
169+
170+ // [csrf] label and milestone writes without the token are refused.
171+ let no_token = Some(
172+ form_urlencoded::Serializer::new(String::new())
173+ .extend_pairs([("name", "bug"), ("color", "#ff0000")])
174+ .finish(),
175+ );
176+ let res = call(&s.site, "POST", FORGE_LABELS, owner, no_token).await;
177+ assert_eq!(res.status, 403, "csrf label");
178+ let res = call(
179+ &s.site,
180+ "POST",
181+ "/tahinli/forge/milestones",
182+ owner,
183+ Some(
184+ form_urlencoded::Serializer::new(String::new())
185+ .extend_pairs([("title", "v1")])
186+ .finish(),
187+ ),
188+ )
189+ .await;
190+ assert_eq!(res.status, 403, "csrf milestone");
191+
192+ // [role] a read-only collaborator cannot create labels.
193+ let res = call(
194+ &s.site,
195+ "POST",
196+ FORGE_LABELS,
197+ Some(s.bob_cookie.as_str()),
198+ form(&[("name", "bug"), ("color", "#ff0000")]),
199+ )
200+ .await;
201+ assert_eq!(res.status, 403, "read-only collaborator");
202+ assert!(store.list_labels(&s.repo_id).await.expect("labels").is_empty());
203+
204+ // [create] the owner creates a label; a case-insensitive duplicate is refused.
157205 let created = call(
158206 &s.site,
159207 "POST",
160208 FORGE_LABELS,
161- cookie,
209+ owner,
162210 form(&[
163211 ("name", "bug"),
164212 ("color", "#FF0000"),
@@ -166,25 +214,40 @@ async fn owner_creates_edits_and_deletes_a_label() {
166214 ]),
167215 )
168216 .await;
169- assert_eq!(created.status, 303);
217+ assert_eq!(created.status, 303, "create");
170218 assert_eq!(created.location.as_deref(), Some(FORGE_LABELS));
171-
172219 let page = call(&s.site, "GET", FORGE_LABELS, None, None).await;
173- assert_eq!(page.status, 200);
174- assert!(page.body.contains("label-chip label-"));
175- assert!(page.body.contains("bug"));
220+ assert_eq!(page.status, 200, "labels page");
221+ assert!(page.body.contains("label-chip label-"), "labels page chip");
222+ assert!(page.body.contains("bug"), "labels page name");
176223 assert!(page.body.contains("/tahinli/forge/issues?label=bug"));
177-
178- let labels = s.site.store.list_labels(&s.repo_id).await.expect("labels");
179- assert_eq!(labels.len(), 1);
180- assert_eq!(labels[0].color, "#ff0000");
224+ let labels = store.list_labels(&s.repo_id).await.expect("labels");
225+ assert_eq!(labels.len(), 1, "one label after create");
226+ assert_eq!(labels[0].color, "#ff0000", "color is lowercased");
181227 let id = labels[0].id.clone();
182228
229+ let dup = call(
230+ &s.site,
231+ "POST",
232+ FORGE_LABELS,
233+ owner,
234+ form(&[("name", "BUG"), ("color", "#00ff00")]),
235+ )
236+ .await;
237+ assert_eq!(dup.status, 200, "duplicate");
238+ assert!(dup.body.contains("already exists"), "duplicate message");
239+ assert_eq!(
240+ store.list_labels(&s.repo_id).await.expect("labels").len(),
241+ 1,
242+ "duplicate not stored"
243+ );
244+
245+ // [edit, delete] the label is renamed, then removed; the list ends empty.
183246 let edited = call(
184247 &s.site,
185248 "POST",
186249 &format!("{FORGE_LABELS}/{id}"),
187- cookie,
250+ owner,
188251 form(&[
189252 ("name", "defect"),
190253 ("color", "#00ff00"),
@@ -192,90 +255,23 @@ async fn owner_creates_edits_and_deletes_a_label() {
192255 ]),
193256 )
194257 .await;
195- assert_eq!(edited.status, 303);
196- let labels = s.site.store.list_labels(&s.repo_id).await.expect("labels");
197- assert_eq!(labels[0].name, "defect");
198- assert_eq!(labels[0].color, "#00ff00");
199-
258+ assert_eq!(edited.status, 303, "edit");
259+ let labels = store.list_labels(&s.repo_id).await.expect("labels");
260+ assert_eq!(labels[0].name, "defect", "edited name");
261+ assert_eq!(labels[0].color, "#00ff00", "edited color");
200262 let deleted = call(
201263 &s.site,
202264 "POST",
203265 &format!("{FORGE_LABELS}/{id}/delete"),
204- cookie,
266+ owner,
205267 form(&[]),
206268 )
207269 .await;
208- assert_eq!(deleted.status, 303);
209- assert!(
210- s.site
211- .store
212- .list_labels(&s.repo_id)
213- .await
214- .expect("labels")
215- .is_empty()
216- );
217-}
218-
219-#[tokio::test]
220-async fn duplicate_label_name_shows_an_error() {
221- let s = seeded().await;
222- let cookie = Some(s.tahinli_cookie.as_str());
223- call(
224- &s.site,
225- "POST",
226- FORGE_LABELS,
227- cookie,
228- form(&[("name", "bug"), ("color", "#ff0000")]),
229- )
230- .await;
231- let dup = call(
232- &s.site,
233- "POST",
234- FORGE_LABELS,
235- cookie,
236- form(&[("name", "BUG"), ("color", "#00ff00")]),
237- )
238- .await;
239- assert_eq!(dup.status, 200);
240- assert!(dup.body.contains("already exists"));
241- assert_eq!(
242- s.site
243- .store
244- .list_labels(&s.repo_id)
245- .await
246- .expect("labels")
247- .len(),
248- 1
249- );
250-}
270+ assert_eq!(deleted.status, 303, "delete");
271+ assert!(store.list_labels(&s.repo_id).await.expect("labels").is_empty());
251272
252-#[tokio::test]
253-async fn read_only_collaborator_cannot_write_labels() {
254- let s = seeded().await;
255- let res = call(
256- &s.site,
257- "POST",
258- FORGE_LABELS,
259- Some(s.bob_cookie.as_str()),
260- form(&[("name", "bug"), ("color", "#ff0000")]),
261- )
262- .await;
263- assert_eq!(res.status, 403);
264- assert!(
265- s.site
266- .store
267- .list_labels(&s.repo_id)
268- .await
269- .expect("labels")
270- .is_empty()
271- );
272-}
273-
274-#[tokio::test]
275-async fn archived_repo_refuses_label_writes() {
276- let s = seeded().await;
277- s.site
278- .store
273+ // [archive] an archived repo refuses label writes (last, it changes the repo).
274+ store
279275 .set_repo_archived(&s.repo_id, true)
280276 .await
281277 .expect("archive");
@@ -283,21 +279,27 @@ async fn archived_repo_refuses_label_writes() {
283279 &s.site,
284280 "POST",
285281 FORGE_LABELS,
286- Some(s.tahinli_cookie.as_str()),
282+ owner,
287283 form(&[("name", "bug"), ("color", "#ff0000")]),
288284 )
289285 .await;
290- assert_eq!(res.status, 403);
286+ assert_eq!(res.status, 403, "archived repo");
291287 }
292288
289+/// Issue metadata on forge: labels (a label from another repo rejects the whole write),
290+/// assignees (an unknown user is rejected), and milestone set and clear. Then milestone progress,
291+/// close and delete on `other`, which has no milestones before this test.
293292 #[tokio::test]
294-async fn labels_on_an_issue_are_recorded_and_cross_repo_ids_are_rejected() {
293+async fn issue_metadata_and_milestone_progress() {
295294 let s = seeded().await;
296295 let store = &s.site.store;
296+ let carol = Some(s.carol_cookie.as_str());
297+ let owner = Some(s.tahinli_cookie.as_str());
297298 let issue = store
298299 .create_issue(&s.repo_id, &s.tahinli, "Crash", "")
299300 .await
300301 .expect("issue");
302+ let uri = format!("/tahinli/forge/issues/{}", issue.number);
301303 let mine = store
302304 .create_label(&s.repo_id, "bug", "#ff0000", "")
303305 .await
@@ -306,54 +308,43 @@ async fn labels_on_an_issue_are_recorded_and_cross_repo_ids_are_rejected() {
306308 .create_label(&s.other_repo_id, "elsewhere", "#00ff00", "")
307309 .await
308310 .expect("other label");
309- let uri = "/tahinli/forge/issues/1/labels";
310311
312+ // [labels] a valid label is recorded; a batch with a foreign label id is rejected.
311313 let ok = call(
312314 &s.site,
313315 "POST",
314- uri,
315- Some(s.carol_cookie.as_str()),
316+ &format!("{uri}/labels"),
317+ carol,
316318 form(&[("label", mine.id.as_str())]),
317319 )
318320 .await;
319- assert_eq!(ok.status, 303);
320- assert_eq!(ok.location.as_deref(), Some("/tahinli/forge/issues/1"));
321+ assert_eq!(ok.status, 303, "label add");
322+ assert_eq!(ok.location.as_deref(), Some(uri.as_str()));
321323 let events = store.list_events(&issue.id).await.expect("events");
322- assert!(events.iter().any(|e| e.kind == "labeled"));
323-
324+ assert!(events.iter().any(|e| e.kind == "labeled"), "labeled event");
324325 let rejected = call(
325326 &s.site,
326327 "POST",
327- uri,
328- Some(s.carol_cookie.as_str()),
328+ &format!("{uri}/labels"),
329+ carol,
329330 form(&[("label", mine.id.as_str()), ("label", theirs.id.as_str())]),
330331 )
331332 .await;
332- assert_eq!(rejected.status, 200);
333+ assert_eq!(rejected.status, 200, "foreign label");
333334 let current = store.issue_labels(&issue.id).await.expect("labels");
334- assert_eq!(current.len(), 1);
335+ assert_eq!(current.len(), 1, "foreign label not stored");
335336 assert_eq!(current[0].id, mine.id);
336-}
337-
338-#[tokio::test]
339-async fn assignees_accept_valid_users_and_reject_unknown_ones() {
340- let s = seeded().await;
341- let store = &s.site.store;
342- let issue = store
343- .create_issue(&s.repo_id, &s.tahinli, "Crash", "")
344- .await
345- .expect("issue");
346- let uri = "/tahinli/forge/issues/1/assignees";
347337
338+ // [assignees] known users are set; an unknown user leaves the two in place.
348339 let ok = call(
349340 &s.site,
350341 "POST",
351- uri,
352- Some(s.carol_cookie.as_str()),
342+ &format!("{uri}/assignees"),
343+ carol,
353344 form(&[("assignees", "carol, bob")]),
354345 )
355346 .await;
356- assert_eq!(ok.status, 303);
347+ assert_eq!(ok.status, 303, "assign");
357348 let names: Vec<String> = store
358349 .issue_assignees(&issue.id)
359350 .await
@@ -361,42 +352,34 @@ async fn assignees_accept_valid_users_and_reject_unknown_ones() {
361352 .into_iter()
362353 .map(|(_, name)| name)
363354 .collect();
364- assert_eq!(names.len(), 2);
355+ assert_eq!(names.len(), 2, "two assignees");
365356 assert!(names.iter().any(|n| n == "carol"));
366357 assert!(names.iter().any(|n| n == "bob"));
367-
368358 let unknown = call(
369359 &s.site,
370360 "POST",
371- uri,
372- Some(s.carol_cookie.as_str()),
361+ &format!("{uri}/assignees"),
362+ carol,
373363 form(&[("assignees", "ghost")]),
374364 )
375365 .await;
376- assert_eq!(unknown.status, 200);
366+ assert_eq!(unknown.status, 200, "unknown assignee");
377367 assert_eq!(
378368 store
379369 .issue_assignees(&issue.id)
380370 .await
381371 .expect("assignees")
382372 .len(),
383- 2
373+ 2,
374+ "unknown assignee not stored"
384375 );
385-}
386376
387-#[tokio::test]
388-async fn milestone_is_set_and_cleared_on_an_issue() {
389- let s = seeded().await;
390- let store = &s.site.store;
391- store
392- .create_issue(&s.repo_id, &s.tahinli, "Crash", "")
393- .await
394- .expect("issue");
377+ // [milestone] created on forge, set on the issue by a triage user, then cleared.
395378 let created = call(
396379 &s.site,
397380 "POST",
398381 "/tahinli/forge/milestones",
399- Some(s.tahinli_cookie.as_str()),
382+ owner,
400383 form(&[
401384 ("title", "v1"),
402385 ("description", "**Ship**"),
@@ -404,25 +387,24 @@ async fn milestone_is_set_and_cleared_on_an_issue() {
404387 ]),
405388 )
406389 .await;
407- assert_eq!(created.status, 303);
390+ assert_eq!(created.status, 303, "milestone create");
408391 let milestone = store
409392 .list_milestones(&s.repo_id, None)
410393 .await
411394 .expect("milestones")
412395 .remove(0);
413396 assert_eq!(milestone.due_on.as_deref(), Some("2030-01-02"));
414-
415397 let set = call(
416398 &s.site,
417399 "POST",
418- "/tahinli/forge/issues/1/milestone",
419- Some(s.carol_cookie.as_str()),
400+ &format!("{uri}/milestone"),
401+ carol,
420402 form(&[("milestone_id", milestone.id.as_str())]),
421403 )
422404 .await;
423- assert_eq!(set.status, 303);
405+ assert_eq!(set.status, 303, "milestone set");
424406 let issue_now = store
425- .issue_by_number(&s.repo_id, 1)
407+ .issue_by_number(&s.repo_id, issue.number)
426408 .await
427409 .expect("issue")
428410 .expect("exists");
@@ -430,46 +412,42 @@ async fn milestone_is_set_and_cleared_on_an_issue() {
430412 issue_now.milestone_id.as_deref(),
431413 Some(milestone.id.as_str())
432414 );
433-
434415 let cleared = call(
435416 &s.site,
436417 "POST",
437- "/tahinli/forge/issues/1/milestone",
438- Some(s.carol_cookie.as_str()),
418+ &format!("{uri}/milestone"),
419+ carol,
439420 form(&[("milestone_id", "")]),
440421 )
441422 .await;
442- assert_eq!(cleared.status, 303);
423+ assert_eq!(cleared.status, 303, "milestone clear");
443424 let issue_now = store
444- .issue_by_number(&s.repo_id, 1)
425+ .issue_by_number(&s.repo_id, issue.number)
445426 .await
446427 .expect("issue")
447428 .expect("exists");
448- assert!(issue_now.milestone_id.is_none());
449-}
429+ assert!(issue_now.milestone_id.is_none(), "milestone cleared");
450430
451-#[tokio::test]
452-async fn milestone_progress_close_and_delete_keeps_issues() {
453- let s = seeded().await;
454- let store = &s.site.store;
431+ // [progress] on `other`: one open and one closed issue under one milestone.
432+ let other = &s.other_repo_id;
455433 let open_issue = store
456- .create_issue(&s.repo_id, &s.tahinli, "Open one", "")
434+ .create_issue(other, &s.tahinli, "Open one", "")
457435 .await
458436 .expect("issue");
459437 let done_issue = store
460- .create_issue(&s.repo_id, &s.tahinli, "Done one", "")
438+ .create_issue(other, &s.tahinli, "Done one", "")
461439 .await
462440 .expect("issue");
463441 call(
464442 &s.site,
465443 "POST",
466- "/tahinli/forge/milestones",
467- Some(s.tahinli_cookie.as_str()),
444+ "/tahinli/other/milestones",
445+ owner,
468446 form(&[("title", "v1"), ("due_on", "2030-01-02")]),
469447 )
470448 .await;
471- let milestone = store
472- .list_milestones(&s.repo_id, None)
449+ let other_ms = store
450+ .list_milestones(other, None)
473451 .await
474452 .expect("milestones")
475453 .remove(0);
@@ -477,13 +455,13 @@ async fn milestone_progress_close_and_delete_keeps_issues() {
477455 store
478456 .set_issue_milestone(
479457 &store
480- .issue_by_number(&s.repo_id, number)
458+ .issue_by_number(other, number)
481459 .await
482460 .expect("issue")
483461 .expect("exists")
484462 .id,
485463 &s.tahinli,
486- Some(milestone.id.as_str()),
464+ Some(other_ms.id.as_str()),
487465 )
488466 .await
489467 .expect("set milestone");
@@ -498,29 +476,27 @@ async fn milestone_progress_close_and_delete_keeps_issues() {
498476 )
499477 .await
500478 .expect("close");
501-
502- let list = call(&s.site, "GET", "/tahinli/forge/milestones", None, None).await;
503- assert_eq!(list.status, 200);
479+ let list = call(&s.site, "GET", "/tahinli/other/milestones", None, None).await;
480+ assert_eq!(list.status, 200, "progress list");
504481 assert!(list.body.contains(r#"<progress value="1" max="2">"#));
505482 assert!(list.body.contains("1 open"));
506483 assert!(list.body.contains("1 closed"));
507-
508484 let closed_list = call(
509485 &s.site,
510486 "GET",
511- "/tahinli/forge/milestones?state=closed",
487+ "/tahinli/other/milestones?state=closed",
512488 None,
513489 None,
514490 )
515491 .await;
516492 assert!(closed_list.body.contains("No closed milestones."));
517493
518- let edit_uri = format!("/tahinli/forge/milestones/{}/edit", milestone.id);
494+ // [close, delete] closing via edit, then deleting keeps the issues.
519495 let edit = call(
520496 &s.site,
521497 "POST",
522- &edit_uri,
523- Some(s.tahinli_cookie.as_str()),
498+ &format!("/tahinli/other/milestones/{}/edit", other_ms.id),
499+ owner,
524500 form(&[
525501 ("title", "v1"),
526502 ("description", ""),
@@ -529,110 +505,65 @@ async fn milestone_progress_close_and_delete_keeps_issues() {
529505 ]),
530506 )
531507 .await;
532- assert_eq!(edit.status, 303);
508+ assert_eq!(edit.status, 303, "milestone edit");
533509 assert_eq!(
534510 store
535- .milestone_by_id(&s.repo_id, &milestone.id)
511+ .milestone_by_id(other, &other_ms.id)
536512 .await
537513 .expect("milestone")
538514 .expect("exists")
539515 .state,
540516 forge_core::IssueState::Closed
541517 );
542-
543518 let deleted = call(
544519 &s.site,
545520 "POST",
546- &format!("/tahinli/forge/milestones/{}/delete", milestone.id),
547- Some(s.tahinli_cookie.as_str()),
521+ &format!("/tahinli/other/milestones/{}/delete", other_ms.id),
522+ owner,
548523 form(&[]),
549524 )
550525 .await;
551- assert_eq!(deleted.status, 303);
526+ assert_eq!(deleted.status, 303, "milestone delete");
552527 assert!(
553528 store
554- .list_milestones(&s.repo_id, None)
529+ .list_milestones(other, None)
555530 .await
556531 .expect("milestones")
557532 .is_empty()
558533 );
559534 let survivor = store
560- .issue_by_number(&s.repo_id, open_issue.number)
535+ .issue_by_number(other, open_issue.number)
561536 .await
562537 .expect("issue")
563538 .expect("issues keep existing");
564- assert!(survivor.milestone_id.is_none());
539+ assert!(survivor.milestone_id.is_none(), "issue kept, milestone gone");
565540 }
566541
542+/// Locking on forge: only triage holders may lock, CSRF is required, and a locked issue refuses
543+/// comments and reactions from read-only users while triage can still comment.
567544 #[tokio::test]
568-async fn write_without_csrf_is_rejected() {
545+async fn issue_lock_requires_triage_and_csrf_and_refuses_read_only_replies() {
569546 let s = seeded().await;
570- let no_token = Some(
571- form_urlencoded::Serializer::new(String::new())
572- .extend_pairs([("name", "bug"), ("color", "#ff0000")])
573- .finish(),
574- );
575- let res = call(
576- &s.site,
577- "POST",
578- FORGE_LABELS,
579- Some(s.tahinli_cookie.as_str()),
580- no_token,
581- )
582- .await;
583- assert_eq!(res.status, 403);
584- let res = call(
585- &s.site,
586- "POST",
587- "/tahinli/forge/milestones",
588- Some(s.tahinli_cookie.as_str()),
589- Some(
590- form_urlencoded::Serializer::new(String::new())
591- .extend_pairs([("title", "v1")])
592- .finish(),
593- ),
594- )
595- .await;
596- assert_eq!(res.status, 403);
597-}
598-
599-#[tokio::test]
600-async fn anonymous_viewer_of_a_private_repo_gets_404() {
601- let s = seeded().await;
602- for uri in ["/tahinli/secret/labels", "/tahinli/secret/milestones"] {
603- let res = call(&s.site, "GET", uri, None, None).await;
604- assert_eq!(res.status, 404, "{uri}");
605- }
606- let res = call(&s.site, "GET", "/tahinli/forge/milestones", None, None).await;
607- assert_eq!(res.status, 200);
608-}
609-
610-const FORGE_ISSUE: &str = "/tahinli/forge/issues/1";
611-
612-/// Tahinli opens issue #1 in the seeded repo and returns its id.
613-async fn open_issue(s: &Seed) -> String {
614- s.site
615- .store
547+ let store = &s.site.store;
548+ let issue = store
616549 .create_issue(&s.repo_id, &s.tahinli, "Lock me", "body")
617550 .await
618- .expect("issue")
619- .id
620-}
551+ .expect("issue");
552+ let base = format!("/tahinli/forge/issues/{}", issue.number);
553+ let lock_uri = format!("{base}/lock");
621554
622-#[tokio::test]
623-async fn lock_requires_triage_and_csrf() {
624- let s = seeded().await;
625- open_issue(&s).await;
626- let uri = "/tahinli/forge/issues/1/lock";
555+ // [role] a read-only collaborator cannot lock.
627556 let res = call(
628557 &s.site,
629558 "POST",
630- uri,
559+ &lock_uri,
631560 Some(s.bob_cookie.as_str()),
632561 form(&[("locked", "1"), ("reason", "spam")]),
633562 )
634563 .await;
635- assert_eq!(res.status, 403);
564+ assert_eq!(res.status, 403, "read-only lock");
565+
566+ // [csrf] a triage user without the token is refused.
636567 let no_token = Some(
637568 form_urlencoded::Serializer::new(String::new())
638569 .extend_pairs([("locked", "1"), ("reason", "spam")])
@@ -641,126 +572,99 @@ async fn lock_requires_triage_and_csrf() {
641572 let res = call(
642573 &s.site,
643574 "POST",
644- uri,
575+ &lock_uri,
645576 Some(s.carol_cookie.as_str()),
646577 no_token,
647578 )
648579 .await;
649- assert_eq!(res.status, 403);
650- let issue = s
651- .site
652- .store
653- .issue_by_number(&s.repo_id, 1)
580+ assert_eq!(res.status, 403, "lock csrf");
581+ let current = store
582+ .issue_by_number(&s.repo_id, issue.number)
654583 .await
655584 .expect("lookup")
656585 .expect("issue");
657- assert!(!issue.locked);
658-}
586+ assert!(!current.locked, "not locked after refusals");
659587
660-#[tokio::test]
661-async fn triage_locks_and_unlocks_with_reason() {
662- let s = seeded().await;
663- open_issue(&s).await;
664- let uri = "/tahinli/forge/issues/1/lock";
588+ // [lock, unlock] triage locks with a reason, then unlocks and clears it.
665589 let res = call(
666590 &s.site,
667591 "POST",
668- uri,
592+ &lock_uri,
669593 Some(s.carol_cookie.as_str()),
670594 form(&[("locked", "1"), ("reason", "too_heated")]),
671595 )
672596 .await;
673- assert_eq!(res.status, 303);
674- let issue = s
675- .site
676- .store
677- .issue_by_number(&s.repo_id, 1)
597+ assert_eq!(res.status, 303, "triage lock");
598+ let current = store
599+ .issue_by_number(&s.repo_id, issue.number)
678600 .await
679601 .expect("lookup")
680602 .expect("issue");
681- assert!(issue.locked);
682- assert_eq!(issue.lock_reason.as_deref(), Some("too_heated"));
683-
603+ assert!(current.locked);
604+ assert_eq!(current.lock_reason.as_deref(), Some("too_heated"));
684605 let res = call(
685606 &s.site,
686607 "POST",
687- uri,
608+ &lock_uri,
688609 Some(s.carol_cookie.as_str()),
689610 form(&[("locked", "0")]),
690611 )
691612 .await;
692- assert_eq!(res.status, 303);
693- let issue = s
694- .site
695- .store
696- .issue_by_number(&s.repo_id, 1)
613+ assert_eq!(res.status, 303, "triage unlock");
614+ let current = store
615+ .issue_by_number(&s.repo_id, issue.number)
697616 .await
698617 .expect("lookup")
699618 .expect("issue");
700- assert!(!issue.locked);
701- assert_eq!(issue.lock_reason, None);
702-}
619+ assert!(!current.locked);
620+ assert_eq!(current.lock_reason, None);
703621
704-#[tokio::test]
705-async fn locked_issue_refuses_comments_and_reactions_from_read_users() {
706- let s = seeded().await;
707- let issue_id = open_issue(&s).await;
708- s.site
709- .store
710- .set_issue_locked(&issue_id, Some(&s.tahinli), true, Some("spam"))
622+ // [locked replies] lock via the store; read-only replies and reactions are refused.
623+ store
624+ .set_issue_locked(&issue.id, Some(&s.tahinli), true, Some("spam"))
711625 .await
712626 .expect("lock");
713-
714627 let res = call(
715628 &s.site,
716629 "POST",
717- &format!("{FORGE_ISSUE}/comment"),
630+ &format!("{base}/comment"),
718631 Some(s.bob_cookie.as_str()),
719632 form(&[("body", "hello"), ("action", "comment")]),
720633 )
721634 .await;
722- assert_eq!(res.status, 403);
635+ assert_eq!(res.status, 403, "read-only comment on locked");
723636 let res = call(
724637 &s.site,
725638 "POST",
726- &format!("{FORGE_ISSUE}/reactions"),
639+ &format!("{base}/reactions"),
727640 Some(s.bob_cookie.as_str()),
728641 form(&[
729642 ("target_kind", "issue"),
730- ("target_id", issue_id.as_str()),
643+ ("target_id", issue.id.as_str()),
731644 ("reaction", "heart"),
732645 ]),
733646 )
734647 .await;
735- assert_eq!(res.status, 403);
736- let issue = s
737- .site
738- .store
739- .issue_by_number(&s.repo_id, 1)
648+ assert_eq!(res.status, 403, "read-only reaction on locked");
649+ let current = store
650+ .issue_by_number(&s.repo_id, issue.number)
740651 .await
741652 .expect("lookup")
742653 .expect("issue");
743- assert_eq!(issue.comment_count, 0);
654+ assert_eq!(current.comment_count, 0, "refused comment not counted");
744655
745656 // Triage holders still comment, and the page tells Bob why he cannot.
746657 let res = call(
747658 &s.site,
748659 "POST",
749- &format!("{FORGE_ISSUE}/comment"),
660+ &format!("{base}/comment"),
750661 Some(s.carol_cookie.as_str()),
751662 form(&[("body", "moderating"), ("action", "comment")]),
752663 )
753664 .await;
754- assert_eq!(res.status, 303);
755- let res = call(
756- &s.site,
757- "GET",
758- FORGE_ISSUE,
759- Some(s.bob_cookie.as_str()),
760- None,
761- )
762- .await;
763- assert_eq!(res.status, 200);
665+ assert_eq!(res.status, 303, "triage comment on locked");
666+ let res = call(&s.site, "GET", &base, Some(s.bob_cookie.as_str()), None).await;
667+ assert_eq!(res.status, 200, "locked page");
764668 assert!(
765669 res.body
766670 .contains("This conversation has been locked (spam) and limited to collaborators.")
crates/forge-web/src/pages/issue_view.rsmodified+144 -183
@@ -638,8 +638,11 @@ mod tests {
638638
639639 const ISSUE: &str = "/tahinli/demo/issues/1";
640640
641+ /// The issue page on a fresh public fixture (issue 1), the markdown and reference rendering,
642+ /// bad numbers, form gating for anonymous and owner viewers, and a private repo's 404 on
643+ /// its own fixture.
641644 #[tokio::test]
642- async fn renders_body_markdown_safely_and_links_refs() {
645+ async fn issue_page_renders_and_gates_forms() {
643646 let fx = Fixture::new(Visibility::Public).await;
644647 let owner = tahinli(&fx).await;
645648 let id = repo_id(&fx).await;
@@ -652,18 +655,17 @@ mod tests {
652655 )
653656 .await
654657 .unwrap();
658+
659+ // [markdown] the body renders, script tags are stripped, and #1 links to the issue.
655660 let (status, _, body) = get(&fx.router, ISSUE).await;
656- assert_eq!(status, 200);
661+ assert_eq!(status, 200, "issue page");
657662 let html = String::from_utf8(body).unwrap();
658663 assert!(html.contains(">Heading<a"));
659664 assert!(!html.contains("<script>"));
660665 assert!(html.contains("class=\"issue-ref\""));
661666 assert!(html.contains("href=\"/tahinli/demo/issues/1\""));
662- }
663667
664- #[tokio::test]
665- async fn bad_numbers_and_missing_issues_are_404() {
666- let fx = Fixture::new(Visibility::Public).await;
668+ // [numbers] zero, non-numeric and missing issues are 404.
667669 for uri in [
668670 "/tahinli/demo/issues/0",
669671 "/tahinli/demo/issues/abc",
@@ -672,23 +674,20 @@ mod tests {
672674 let (status, _, _) = get(&fx.router, uri).await;
673675 assert_eq!(status, 404, "{uri}");
674676 }
675- }
676677
677- #[tokio::test]
678- async fn anonymous_sees_no_forms_and_private_is_404() {
679- let fx = Fixture::new(Visibility::Public).await;
680- let owner = tahinli(&fx).await;
681- let id = repo_id(&fx).await;
682- fx.store
683- .create_issue(&id, &owner.id, "First", "body")
684- .await
685- .unwrap();
678+ // [forms] anonymous viewers get no forms; the owner gets the triage forms.
686679 let (status, _, body) = get(&fx.router, ISSUE).await;
687- assert_eq!(status, 200);
680+ assert_eq!(status, 200, "anonymous page");
688681 let html = String::from_utf8(body).unwrap();
689- assert!(!html.contains("name=\"csrf\""));
690- assert!(!html.contains("/issues/1/labels"));
682+ assert!(!html.contains("name=\"csrf\""), "anonymous csrf");
683+ assert!(!html.contains("/issues/1/labels"), "anonymous labels");
684+ let (status, _, body) = send(&fx.router, "GET", ISSUE, Some("tahinli"), None).await;
685+ assert_eq!(status, 200, "owner page");
686+ assert!(body.contains("/issues/1/labels"));
687+ assert!(body.contains("name=\"assignees\""));
688+ assert!(body.contains("name=\"milestone_id\""));
691689
690+ // [private] anonymous viewers of a private repo get 404.
692691 let private = Fixture::new(Visibility::Private).await;
693692 let owner = tahinli(&private).await;
694693 let id = repo_id(&private).await;
@@ -698,39 +697,29 @@ mod tests {
698697 .await
699698 .unwrap();
700699 let (status, _, _) = get(&private.router, ISSUE).await;
701- assert_eq!(status, 404);
700+ assert_eq!(status, 404, "private issue");
702701 }
703702
703+ /// Comments, closing, editing, deleting and archiving on one public fixture. Each scenario
704+ /// opens its own issue so the numbers and counts do not interfere. Archiving is last.
704705 #[tokio::test]
705- async fn owner_gets_triage_forms_in_sidebar() {
706+ async fn comment_close_edit_and_archive_rules() {
706707 let fx = Fixture::new(Visibility::Public).await;
707708 let owner = tahinli(&fx).await;
708709 let id = repo_id(&fx).await;
710+ let bob = signed_in(&fx, "bob", "bob-token").await;
711+ let carol = signed_in(&fx, "carol", "carol-token").await;
709712 fx.store
710- .create_issue(&id, &owner.id, "First", "body")
713+ .set_collaborator(&id, &carol.id, Role::Triage)
711714 .await
712715 .unwrap();
713- let (status, _, body) = send(&fx.router, "GET", ISSUE, Some("tahinli"), None).await;
714- assert_eq!(status, 200);
715- assert!(body.contains("/issues/1/labels"));
716- assert!(body.contains("name=\"assignees\""));
717- assert!(body.contains("name=\"milestone_id\""));
718- let (_, _, body) = send(&fx.router, "GET", ISSUE, None, None).await;
719- assert!(!body.contains("/issues/1/labels"));
720- assert!(!body.contains("name=\"assignees\""));
721- assert!(!body.contains("name=\"milestone_id\""));
722- }
723716
724- #[tokio::test]
725- async fn comment_as_another_user_redirects_to_the_comment() {
726- let fx = Fixture::new(Visibility::Public).await;
727- let owner = tahinli(&fx).await;
728- let id = repo_id(&fx).await;
729- fx.store
730- .create_issue(&id, &owner.id, "First", "body")
717+ // [comment] a read user's comment redirects to the new comment.
718+ let a = fx
719+ .store
720+ .create_issue(&id, &owner.id, "A", "body")
731721 .await
732722 .unwrap();
733- signed_in(&fx, "bob", "bob-token").await;
734723 let form = csrf_form(
735724 "bob-token",
736725 &[("body", "Looks good"), ("action", "comment")],
@@ -738,177 +727,138 @@ mod tests {
738727 let (status, location, _) = send(
739728 &fx.router,
740729 "POST",
741- "/tahinli/demo/issues/1/comment",
730+ &format!("/tahinli/demo/issues/{}/comment", a.number),
742731 Some("bob-token"),
743732 Some(form),
744733 )
745734 .await;
746- assert_eq!(status, 303);
747- let issue = fx.store.issue_by_number(&id, 1).await.unwrap().unwrap();
748- let comments = fx.store.list_comments(&issue.id).await.unwrap();
749- assert_eq!(comments.len(), 1);
735+ assert_eq!(status, 303, "bob comment");
736+ let comments = fx.store.list_comments(&a.id).await.unwrap();
737+ assert_eq!(comments.len(), 1, "one comment on A");
750738 assert_eq!(
751739 location.unwrap(),
752- format!("/tahinli/demo/issues/1#comment-{}", comments[0].id)
740+ format!(
741+ "/tahinli/demo/issues/{}#comment-{}",
742+ a.number, comments[0].id
743+ )
753744 );
754- let (_, _, body) = get(&fx.router, ISSUE).await;
745+ let (_, _, body) = get(&fx.router, &format!("/tahinli/demo/issues/{}", a.number)).await;
755746 assert!(String::from_utf8(body).unwrap().contains("Looks good"));
756- }
757747
758- #[tokio::test]
759- async fn empty_comment_is_a_validation_error() {
760- let fx = Fixture::new(Visibility::Public).await;
761- let owner = tahinli(&fx).await;
762- let id = repo_id(&fx).await;
763- let issue = fx
748+ // [empty] a blank comment is a validation error and stores nothing.
749+ let b = fx
764750 .store
765- .create_issue(&id, &owner.id, "First", "body")
751+ .create_issue(&id, &owner.id, "B", "body")
766752 .await
767753 .unwrap();
768754 let form = csrf_form("tahinli", &[("body", " "), ("action", "comment")]);
769755 let (status, _, body) = send(
770756 &fx.router,
771757 "POST",
772- "/tahinli/demo/issues/1/comment",
758+ &format!("/tahinli/demo/issues/{}/comment", b.number),
773759 Some("tahinli"),
774760 Some(form),
775761 )
776762 .await;
777- assert_eq!(status, 200);
763+ assert_eq!(status, 200, "empty comment");
778764 assert!(body.contains("Comment cannot be empty."));
779- assert!(fx.store.list_comments(&issue.id).await.unwrap().is_empty());
780- }
765+ assert!(fx.store.list_comments(&b.id).await.unwrap().is_empty());
781766
782- #[tokio::test]
783- async fn author_closes_as_not_planned() {
784- let fx = Fixture::new(Visibility::Public).await;
785- let owner = tahinli(&fx).await;
786- let id = repo_id(&fx).await;
787- let issue = fx
767+ // [author close] the author closes as not planned; the event and the page show it.
768+ let c = fx
788769 .store
789- .create_issue(&id, &owner.id, "First", "body")
770+ .create_issue(&id, &owner.id, "C", "body")
790771 .await
791772 .unwrap();
792773 let form = csrf_form("tahinli", &[("action", "close_not_planned")]);
793774 let (status, location, _) = send(
794775 &fx.router,
795776 "POST",
796- "/tahinli/demo/issues/1/comment",
777+ &format!("/tahinli/demo/issues/{}/comment", c.number),
797778 Some("tahinli"),
798779 Some(form),
799780 )
800781 .await;
801- assert_eq!(status, 303);
802- assert_eq!(location.unwrap(), "/tahinli/demo/issues/1#issue-1");
782+ assert_eq!(status, 303, "author close");
783+ assert_eq!(
784+ location.unwrap(),
785+ format!("/tahinli/demo/issues/{}#issue-{}", c.number, c.number)
786+ );
803787 assert_eq!(
804- issue_state(&fx, 1).await,
788+ issue_state(&fx, c.number).await,
805789 (false, Some("not_planned".to_owned()))
806790 );
807- let events = fx.store.list_events(&issue.id).await.unwrap();
791+ let events = fx.store.list_events(&c.id).await.unwrap();
808792 assert!(events.iter().any(|e| e.kind == "closed"));
809- let (_, _, body) = get(&fx.router, ISSUE).await;
793+ let (_, _, body) = get(&fx.router, &format!("/tahinli/demo/issues/{}", c.number)).await;
810794 assert!(
811795 String::from_utf8(body)
812796 .unwrap()
813797 .contains("Closed as not planned")
814798 );
815- }
816799
817- #[tokio::test]
818- async fn non_author_cannot_close_but_can_comment() {
819- let fx = Fixture::new(Visibility::Public).await;
820- let owner = tahinli(&fx).await;
821- let id = repo_id(&fx).await;
822- fx.store
823- .create_issue(&id, &owner.id, "First", "body")
800+ // [non-author] a read user cannot close, but can still comment.
801+ let d = fx
802+ .store
803+ .create_issue(&id, &owner.id, "D", "body")
824804 .await
825805 .unwrap();
826- signed_in(&fx, "bob", "bob-token").await;
806+ let d_uri = format!("/tahinli/demo/issues/{}/comment", d.number);
827807 let form = csrf_form("bob-token", &[("action", "close_completed")]);
828- let (status, _, _) = send(
829- &fx.router,
830- "POST",
831- "/tahinli/demo/issues/1/comment",
832- Some("bob-token"),
833- Some(form),
834- )
835- .await;
836- assert_eq!(status, 403);
837- assert_eq!(issue_state(&fx, 1).await, (true, None));
838-
808+ let (status, _, _) = send(&fx.router, "POST", &d_uri, Some("bob-token"), Some(form)).await;
809+ assert_eq!(status, 403, "non-author close");
810+ assert_eq!(issue_state(&fx, d.number).await, (true, None));
839811 let form = csrf_form("bob-token", &[("body", "Me too"), ("action", "comment")]);
840- let (status, _, _) = send(
841- &fx.router,
842- "POST",
843- "/tahinli/demo/issues/1/comment",
844- Some("bob-token"),
845- Some(form),
846- )
847- .await;
848- assert_eq!(status, 303);
849- }
812+ let (status, _, _) = send(&fx.router, "POST", &d_uri, Some("bob-token"), Some(form)).await;
813+ assert_eq!(status, 303, "non-author comment");
850814
851- #[tokio::test]
852- async fn triage_collaborator_closes_and_edits_others_comments() {
853- let fx = Fixture::new(Visibility::Public).await;
854- let owner = tahinli(&fx).await;
855- let id = repo_id(&fx).await;
856- let issue = fx
815+ // [triage] a triage user closes the issue and edits another user's comment.
816+ let e = fx
857817 .store
858- .create_issue(&id, &owner.id, "First", "body")
859- .await
860- .unwrap();
861- let carol = signed_in(&fx, "carol", "carol-token").await;
862- fx.store
863- .set_collaborator(&id, &carol.id, Role::Triage)
818+ .create_issue(&id, &owner.id, "E", "body")
864819 .await
865820 .unwrap();
866- let bob = signed_in(&fx, "bob", "bob-token").await;
867821 let comment = fx
868822 .store
869- .add_comment(&issue.id, &bob.id, "original")
823+ .add_comment(&e.id, &bob.id, "original")
870824 .await
871825 .unwrap();
872-
873826 let form = csrf_form("carol-token", &[("action", "close_completed")]);
874827 let (status, _, _) = send(
875828 &fx.router,
876829 "POST",
877- "/tahinli/demo/issues/1/comment",
830+ &format!("/tahinli/demo/issues/{}/comment", e.number),
878831 Some("carol-token"),
879832 Some(form),
880833 )
881834 .await;
882- assert_eq!(status, 303);
835+ assert_eq!(status, 303, "triage close");
883836 assert_eq!(
884- issue_state(&fx, 1).await,
837+ issue_state(&fx, e.number).await,
885838 (false, Some("completed".to_owned()))
886839 );
887-
888- let uri = format!("/tahinli/demo/issues/1/comments/{}/edit", comment.id);
840+ let uri = format!(
841+ "/tahinli/demo/issues/{}/comments/{}/edit",
842+ e.number, comment.id
843+ );
889844 let (status, _, _) = get(&fx.router, &uri).await;
890- assert_eq!(status, 303, "anonymous goes to login");
845+ assert_eq!(status, 303, "anonymous edit goes to login");
891846 let (status, _, _) = send(&fx.router, "GET", &uri, Some("carol-token"), None).await;
892- assert_eq!(status, 200);
847+ assert_eq!(status, 200, "triage edit form");
893848 let form = csrf_form("carol-token", &[("body", "edited by triage")]);
894849 let (status, _, _) = send(&fx.router, "POST", &uri, Some("carol-token"), Some(form)).await;
895- assert_eq!(status, 303);
850+ assert_eq!(status, 303, "triage edit");
896851 let saved = fx
897852 .store
898- .comment_by_id(&issue.id, &comment.id)
853+ .comment_by_id(&e.id, &comment.id)
899854 .await
900855 .unwrap()
901856 .unwrap();
902857 assert_eq!(saved.body, "edited by triage");
903858 assert!(saved.edited);
904- }
905859
906- #[tokio::test]
907- async fn edit_issue_updates_title_and_records_rename() {
908- let fx = Fixture::new(Visibility::Public).await;
909- let owner = tahinli(&fx).await;
910- let id = repo_id(&fx).await;
911- let issue = fx
860+ // [edit issue] title and body change, and the rename is recorded.
861+ let f = fx
912862 .store
913863 .create_issue(&id, &owner.id, "old", "old body")
914864 .await
@@ -917,104 +867,108 @@ mod tests {
917867 let (status, location, _) = send(
918868 &fx.router,
919869 "POST",
920- "/tahinli/demo/issues/1/edit",
870+ &format!("/tahinli/demo/issues/{}/edit", f.number),
921871 Some("tahinli"),
922872 Some(form),
923873 )
924874 .await;
925- assert_eq!(status, 303);
926- assert_eq!(location.unwrap(), "/tahinli/demo/issues/1");
927- let saved = fx.store.issue_by_number(&id, 1).await.unwrap().unwrap();
875+ assert_eq!(status, 303, "issue edit");
876+ assert_eq!(
877+ location.unwrap(),
878+ format!("/tahinli/demo/issues/{}", f.number)
879+ );
880+ let saved = fx
881+ .store
882+ .issue_by_number(&id, f.number)
883+ .await
884+ .unwrap()
885+ .unwrap();
928886 assert_eq!(
929887 (saved.title.as_str(), saved.body.as_str()),
930888 ("new", "new body")
931889 );
932890 // The store writes the previous version to edit_history on every edit; the rename event
933891 // is the visible part of that write.
934- let events = fx.store.list_events(&issue.id).await.unwrap();
892+ let events = fx.store.list_events(&f.id).await.unwrap();
935893 assert!(events.iter().any(|e| e.kind == "renamed"));
936- }
937894
938- #[tokio::test]
939- async fn deleting_a_comment_decrements_the_count() {
940- let fx = Fixture::new(Visibility::Public).await;
941- let owner = tahinli(&fx).await;
942- let id = repo_id(&fx).await;
943- let issue = fx
895+ // [delete comment] deleting one of two comments drops the count to one.
896+ let g = fx
944897 .store
945- .create_issue(&id, &owner.id, "First", "body")
898+ .create_issue(&id, &owner.id, "G", "body")
946899 .await
947900 .unwrap();
948901 let first = fx
949902 .store
950- .add_comment(&issue.id, &owner.id, "one")
903+ .add_comment(&g.id, &owner.id, "one")
951904 .await
952905 .unwrap();
953906 fx.store
954- .add_comment(&issue.id, &owner.id, "two")
907+ .add_comment(&g.id, &owner.id, "two")
955908 .await
956909 .unwrap();
957910 assert_eq!(
958911 fx.store
959- .issue_by_number(&id, 1)
912+ .issue_by_number(&id, g.number)
960913 .await
961914 .unwrap()
962915 .unwrap()
963916 .comment_count,
964- 2
917+ 2,
918+ "two comments before delete"
919+ );
920+ let uri = format!(
921+ "/tahinli/demo/issues/{}/comments/{}/delete",
922+ g.number, first.id
965923 );
966-
967- let uri = format!("/tahinli/demo/issues/1/comments/{}/delete", first.id);
968924 let form = csrf_form("tahinli", &[]);
969925 let (status, _, _) = send(&fx.router, "POST", &uri, Some("tahinli"), Some(form)).await;
970- assert_eq!(status, 303);
926+ assert_eq!(status, 303, "delete comment");
971927 assert_eq!(
972928 fx.store
973- .issue_by_number(&id, 1)
929+ .issue_by_number(&id, g.number)
974930 .await
975931 .unwrap()
976932 .unwrap()
977933 .comment_count,
978- 1
934+ 1,
935+ "count after delete"
979936 );
980- }
981937
982- #[tokio::test]
983- async fn comment_id_from_another_issue_is_404() {
984- let fx = Fixture::new(Visibility::Public).await;
985- let owner = tahinli(&fx).await;
986- let id = repo_id(&fx).await;
987- fx.store
988- .create_issue(&id, &owner.id, "First", "body")
938+ // [foreign comment] a comment id from another issue is 404 on edit and delete.
939+ let h1 = fx
940+ .store
941+ .create_issue(&id, &owner.id, "H1", "body")
989942 .await
990943 .unwrap();
991- let other = fx
944+ let h2 = fx
992945 .store
993- .create_issue(&id, &owner.id, "Second", "body")
946+ .create_issue(&id, &owner.id, "H2", "body")
994947 .await
995948 .unwrap();
996949 let foreign = fx
997950 .store
998- .add_comment(&other.id, &owner.id, "elsewhere")
951+ .add_comment(&h2.id, &owner.id, "elsewhere")
999952 .await
1000953 .unwrap();
1001-
1002- let edit = format!("/tahinli/demo/issues/1/comments/{}/edit", foreign.id);
954+ let edit = format!(
955+ "/tahinli/demo/issues/{}/comments/{}/edit",
956+ h1.number, foreign.id
957+ );
1003958 let (status, _, _) = send(&fx.router, "GET", &edit, Some("tahinli"), None).await;
1004- assert_eq!(status, 404);
1005- let delete = format!("/tahinli/demo/issues/1/comments/{}/delete", foreign.id);
959+ assert_eq!(status, 404, "foreign edit");
960+ let delete = format!(
961+ "/tahinli/demo/issues/{}/comments/{}/delete",
962+ h1.number, foreign.id
963+ );
1006964 let form = csrf_form("tahinli", &[]);
1007965 let (status, _, _) = send(&fx.router, "POST", &delete, Some("tahinli"), Some(form)).await;
1008- assert_eq!(status, 404);
1009- }
966+ assert_eq!(status, 404, "foreign delete");
1010967
1011- #[tokio::test]
1012- async fn archived_repo_rejects_writes() {
1013- let fx = Fixture::new(Visibility::Public).await;
1014- let owner = tahinli(&fx).await;
1015- let id = repo_id(&fx).await;
1016- fx.store
1017- .create_issue(&id, &owner.id, "First", "body")
968+ // [archived] last, because it changes the repo: comments are 403 and the form is hidden.
969+ let i = fx
970+ .store
971+ .create_issue(&id, &owner.id, "I", "body")
1018972 .await
1019973 .unwrap();
1020974 fx.store.set_repo_archived(&id, true).await.unwrap();
@@ -1022,13 +976,20 @@ mod tests {
1022976 let (status, _, _) = send(
1023977 &fx.router,
1024978 "POST",
1025- "/tahinli/demo/issues/1/comment",
979+ &format!("/tahinli/demo/issues/{}/comment", i.number),
1026980 Some("tahinli"),
1027981 Some(form),
1028982 )
1029983 .await;
1030- assert_eq!(status, 403);
1031- let (_, _, body) = send(&fx.router, "GET", ISSUE, Some("tahinli"), None).await;
1032- assert!(!body.contains("name=\"body\""));
984+ assert_eq!(status, 403, "archived comment");
985+ let (_, _, body) = send(
986+ &fx.router,
987+ "GET",
988+ &format!("/tahinli/demo/issues/{}", i.number),
989+ Some("tahinli"),
990+ None,
991+ )
992+ .await;
993+ assert!(!body.contains("name=\"body\""), "archived form hidden");
1033994 }
1034995 }
crates/forge-web/src/pages/issues_list.rsmodified+133 -186
@@ -997,11 +997,16 @@ mod tests {
997997 html.matches("class=\"issue-row\"").count()
998998 }
999999
1000+ /// One pristine public fixture, in order: empty list and toolbar links, Turkish empty state,
1001+ /// a refused draft and bad CSRF, the new-issue form, a valid create, newest-first order, the
1002+ /// Turkish relative times, and archived refusals last.
10001003 #[tokio::test]
1001- async fn toolbar_links_to_labels_and_milestones() {
1004+ async fn empty_create_and_locale_flow() {
10021005 let fx = fixture(Visibility::Public).await;
10031006 let labels = format!("href=\"/{OWNER}/{REPO}/labels\"");
10041007 let milestones = format!("href=\"/{OWNER}/{REPO}/milestones\"");
1008+
1009+ // [empty] toolbar links for signed-in and anonymous viewers; no rows yet.
10051010 for signed_in in [true, false] {
10061011 let html = send(&fx.router, "GET", &base(), signed_in, None, &[])
10071012 .await
@@ -1009,21 +1014,61 @@ mod tests {
10091014 assert!(html.contains(&labels), "signed_in={signed_in}");
10101015 assert!(html.contains(&milestones), "signed_in={signed_in}");
10111016 }
1012- }
1017+ let empty = send(&fx.router, "GET", &base(), true, None, &[]).await;
1018+ assert_eq!(empty.status, 200, "empty list");
1019+ assert!(empty.text().contains("No issues match these filters."));
1020+ assert_eq!(rows(&empty.text()), 0);
1021+ let tr = send(
1022+ &fx.router,
1023+ "GET",
1024+ &base(),
1025+ true,
1026+ None,
1027+ &[("accept-language", "tr")],
1028+ )
1029+ .await
1030+ .text();
1031+ assert!(tr.contains(">Yeni sorun</a>"), "{tr}");
1032+ assert!(tr.contains("Bu filtrelerle eşleşen sorun yok."), "{tr}");
10131033
1014- #[tokio::test]
1015- async fn empty_list_says_so() {
1016- let fx = fixture(Visibility::Public).await;
1017- let reply = send(&fx.router, "GET", &base(), true, None, &[]).await;
1018- assert_eq!(reply.status, 200);
1019- assert!(reply.text().contains("No issues match these filters."));
1020- assert_eq!(rows(&reply.text()), 0);
1021- }
1034+ // [refusals] an empty-title draft keeps its body and creates nothing; bad CSRF is 403.
1035+ let draft = send(
1036+ &fx.router,
1037+ "POST",
1038+ &format!("{}/new", base()),
1039+ true,
1040+ Some("csrf=issues-test-csrf&title=+++&body=kept+body"),
1041+ &[],
1042+ )
1043+ .await;
1044+ assert_eq!(draft.status, 422, "invalid draft");
1045+ assert!(draft.text().contains("kept body"));
1046+ let bad = send(
1047+ &fx.router,
1048+ "POST",
1049+ &format!("{}/new", base()),
1050+ true,
1051+ Some("csrf=wrong&title=hi"),
1052+ &[],
1053+ )
1054+ .await;
1055+ assert_eq!(bad.status, 403, "bad csrf");
1056+ let (total, _) = fx.store.issue_counts(&fx.repo.id).await.unwrap();
1057+ assert_eq!(total, 0, "refusals create nothing");
10221058
1023- #[tokio::test]
1024- async fn newest_first_and_post_creates_an_issue() {
1025- let fx = fixture(Visibility::Public).await;
1026- let reply = send(
1059+ // [create] the owner sees the form, and a valid create redirects to issue 1.
1060+ let form = send(
1061+ &fx.router,
1062+ "GET",
1063+ &format!("{}/new", base()),
1064+ true,
1065+ None,
1066+ &[],
1067+ )
1068+ .await;
1069+ assert_eq!(form.status, 200, "new form");
1070+ assert!(form.text().contains(&format!("action=\"{}/new\"", base())));
1071+ let created = send(
10271072 &fx.router,
10281073 "POST",
10291074 &format!("{}/new", base()),
@@ -1032,35 +1077,77 @@ mod tests {
10321077 &[],
10331078 )
10341079 .await;
1035- assert_eq!(reply.status, 303);
1080+ assert_eq!(created.status, 303, "create");
10361081 assert_eq!(
1037- reply.header("location").as_deref(),
1082+ created.header("location").as_deref(),
10381083 Some(format!("{}/1", base()).as_str())
10391084 );
1040- let repo_id = fx.repo.id.clone();
1041- fx.store
1042- .create_issue(&repo_id, &fx.owner.id, "second issue", "")
1043- .await
1044- .unwrap();
1045- fx.store
1046- .create_issue(&repo_id, &fx.owner.id, "third issue", "")
1047- .await
1048- .unwrap();
10491085
1086+ // [order] two more issues; the list is newest first.
1087+ let repo_id = fx.repo.id.clone();
1088+ for title in ["second issue", "third issue"] {
1089+ fx.store
1090+ .create_issue(&repo_id, &fx.owner.id, title, "")
1091+ .await
1092+ .unwrap();
1093+ }
10501094 let html = send(&fx.router, "GET", &base(), true, None, &[])
10511095 .await
10521096 .text();
1053- assert_eq!(rows(&html), 3);
1097+ assert_eq!(rows(&html), 3, "three rows");
10541098 let third = html.find("third issue").unwrap();
10551099 let second = html.find("second issue").unwrap();
10561100 let first = html.find("first issue").unwrap();
10571101 assert!(third < second && second < first, "{html}");
1102+
1103+ // [locale] Turkish relative times for fresh issues.
1104+ let html = send(
1105+ &fx.router,
1106+ "GET",
1107+ &base(),
1108+ true,
1109+ None,
1110+ &[("accept-language", "tr")],
1111+ )
1112+ .await
1113+ .text();
1114+ assert!(html.contains("az önce"), "{html}");
1115+ assert!(html.contains("açıldı"), "{html}");
1116+ assert!(!html.contains("just now"), "{html}");
1117+
1118+ // [archived] last, because it changes the repo: creates and the form are 403.
1119+ fx.store.set_repo_archived(&fx.repo.id, true).await.unwrap();
1120+ let archived = send(
1121+ &fx.router,
1122+ "POST",
1123+ &format!("{}/new", base()),
1124+ true,
1125+ Some("csrf=issues-test-csrf&title=hi"),
1126+ &[],
1127+ )
1128+ .await;
1129+ assert_eq!(archived.status, 403, "archived create");
1130+ let form = send(
1131+ &fx.router,
1132+ "GET",
1133+ &format!("{}/new", base()),
1134+ true,
1135+ None,
1136+ &[],
1137+ )
1138+ .await;
1139+ assert_eq!(form.status, 403, "archived form");
10581140 }
10591141
1142+ /// One populated public fixture, in order: 30 bulk issues for pagination (checked before
1143+ /// anything else is added), then the state filter, the label filter, search, and the
1144+ /// anonymous view. Anonymous writes are compared against the total taken just before them.
10601145 #[tokio::test]
1061- async fn pagination_with_thirty_issues() {
1146+ async fn pagination_state_label_search_and_anonymous_reads() {
10621147 let fx = fixture(Visibility::Public).await;
10631148 let repo_id = fx.repo.id.clone();
1149+
1150+ // [pagination] 30 issues: page 1 holds 25, page 2 the oldest 5.
10641151 for n in 1..=30 {
10651152 fx.store
10661153 .create_issue(&repo_id, &fx.owner.id, &format!("bulk {n:02}"), "")
@@ -1070,10 +1157,9 @@ mod tests {
10701157 let page1 = send(&fx.router, "GET", &base(), true, None, &[])
10711158 .await
10721159 .text();
1073- assert_eq!(rows(&page1), 25);
1160+ assert_eq!(rows(&page1), 25, "page 1 rows");
10741161 assert!(page1.contains(">Older<"));
10751162 assert!(!page1.contains(">Newer<"));
1076-
10771163 let page2 = send(
10781164 &fx.router,
10791165 "GET",
@@ -1084,18 +1170,13 @@ mod tests {
10841170 )
10851171 .await
10861172 .text();
1087- assert_eq!(rows(&page2), 5);
1173+ assert_eq!(rows(&page2), 5, "page 2 rows");
10881174 assert!(page2.contains(">Newer<"));
10891175 assert!(!page2.contains(">Older<"));
10901176 assert!(page2.contains("bulk 01"));
1091- }
10921177
1093- #[tokio::test]
1094- async fn state_filter_and_counts() {
1095- let fx = fixture(Visibility::Public).await;
1096- let repo_id = fx.repo.id.clone();
1097- let open = fx
1098- .store
1178+ // [state] one open and one closed issue; the filters split them.
1179+ fx.store
10991180 .create_issue(&repo_id, &fx.owner.id, "still open", "")
11001181 .await
11011182 .unwrap();
@@ -1114,15 +1195,12 @@ mod tests {
11141195 )
11151196 .await
11161197 .unwrap();
1117- assert_eq!(open.number, 1);
1118-
11191198 let default = send(&fx.router, "GET", &base(), true, None, &[])
11201199 .await
11211200 .text();
11221201 assert!(default.contains("still open"));
11231202 assert!(!default.contains("already done"));
11241203 assert!(default.contains("Closed 1"), "{default}");
1125-
11261204 let closed = send(
11271205 &fx.router,
11281206 "GET",
@@ -1135,7 +1213,6 @@ mod tests {
11351213 .text();
11361214 assert!(closed.contains("already done"));
11371215 assert!(!closed.contains("still open"));
1138-
11391216 let all = send(
11401217 &fx.router,
11411218 "GET",
@@ -1147,7 +1224,6 @@ mod tests {
11471224 .await
11481225 .text();
11491226 assert!(all.contains("already done") && all.contains("still open"));
1150-
11511227 let bogus = send(
11521228 &fx.router,
11531229 "GET",
@@ -1157,14 +1233,10 @@ mod tests {
11571233 &[],
11581234 )
11591235 .await;
1160- assert_eq!(bogus.status, 200);
1236+ assert_eq!(bogus.status, 200, "bogus state");
11611237 assert!(bogus.text().contains("still open"));
1162- }
11631238
1164- #[tokio::test]
1165- async fn label_filter_uses_store_labels() {
1166- let fx = fixture(Visibility::Public).await;
1167- let repo_id = fx.repo.id.clone();
1239+ // [label] the label filter shows only the tagged issue.
11681240 let bug = fx
11691241 .store
11701242 .create_label(&repo_id, "bug", "#d73a4a", "")
@@ -1183,7 +1255,6 @@ mod tests {
11831255 .set_issue_labels(&tagged.id, &fx.owner.id, std::slice::from_ref(&bug.id))
11841256 .await
11851257 .unwrap();
1186-
11871258 let filtered = send(
11881259 &fx.router,
11891260 "GET",
@@ -1198,12 +1269,8 @@ mod tests {
11981269 assert!(!filtered.contains("plain issue"));
11991270 assert!(filtered.contains(&format!("label-chip label-{}", bug.id)));
12001271 assert!(filtered.contains(&format!("/{OWNER}/{REPO}/labels.css")));
1201- }
12021272
1203- #[tokio::test]
1204- async fn search_treats_percent_as_a_literal() {
1205- let fx = fixture(Visibility::Public).await;
1206- let repo_id = fx.repo.id.clone();
1273+ // [search] % is a literal character in the search term.
12071274 for title in ["100% done", "100 done", "other thing"] {
12081275 fx.store
12091276 .create_issue(&repo_id, &fx.owner.id, title, "")
@@ -1223,7 +1290,6 @@ mod tests {
12231290 assert!(html.contains(">100% done</a>"), "{html}");
12241291 assert!(!html.contains(">100 done</a>"), "{html}");
12251292 assert!(!html.contains(">other thing</a>"), "{html}");
1226-
12271293 let raw = send(
12281294 &fx.router,
12291295 "GET",
@@ -1233,22 +1299,18 @@ mod tests {
12331299 &[],
12341300 )
12351301 .await;
1236- assert_eq!(raw.status, 200);
1237- }
1302+ assert_eq!(raw.status, 200, "raw percent");
12381303
1239- #[tokio::test]
1240- async fn anonymous_reads_public_but_cannot_create() {
1241- let fx = fixture(Visibility::Public).await;
1242- let repo_id = fx.repo.id.clone();
1304+ // [anonymous] reads are public; creates bounce to login and store nothing.
12431305 fx.store
12441306 .create_issue(&repo_id, &fx.owner.id, "public issue", "")
12451307 .await
12461308 .unwrap();
1309+ let (before, _) = fx.store.issue_counts(&repo_id).await.unwrap();
12471310 let list = send(&fx.router, "GET", &base(), false, None, &[]).await;
1248- assert_eq!(list.status, 200);
1311+ assert_eq!(list.status, 200, "anonymous list");
12491312 assert!(list.text().contains("public issue"));
12501313 assert!(!list.text().contains("New issue</a>"));
1251-
12521314 let form = send(
12531315 &fx.router,
12541316 "GET",
@@ -1258,9 +1320,8 @@ mod tests {
12581320 &[],
12591321 )
12601322 .await;
1261- assert_eq!(form.status, 303);
1323+ assert_eq!(form.status, 303, "anonymous form");
12621324 assert!(form.header("location").unwrap().starts_with("/login"));
1263-
12641325 let post = send(
12651326 &fx.router,
12661327 "POST",
@@ -1270,24 +1331,21 @@ mod tests {
12701331 &[],
12711332 )
12721333 .await;
1273- assert_eq!(post.status, 303);
1334+ assert_eq!(post.status, 303, "anonymous create");
12741335 assert!(post.header("location").unwrap().starts_with("/login"));
12751336 let (total, _) = fx.store.issue_counts(&repo_id).await.unwrap();
1276- assert_eq!(total, 1);
1337+ assert_eq!(total, before, "anonymous create stores nothing");
12771338 }
12781339
1340+ /// A private repo is 404 for anonymous viewers and visible to the owner, whose invalid
1341+ /// query values fall back to the defaults.
12791342 #[tokio::test]
1280- async fn private_repo_is_404_for_anonymous() {
1343+ async fn private_repo_is_404_for_anonymous_and_bad_queries_fall_back() {
12811344 let fx = fixture(Visibility::Private).await;
12821345 let list = send(&fx.router, "GET", &base(), false, None, &[]).await;
1283- assert_eq!(list.status, 404);
1346+ assert_eq!(list.status, 404, "anonymous private");
12841347 let owner = send(&fx.router, "GET", &base(), true, None, &[]).await;
1285- assert_eq!(owner.status, 200);
1286- }
1287-
1288- #[tokio::test]
1289- async fn invalid_query_values_fall_back_to_defaults() {
1290- let fx = fixture(Visibility::Public).await;
1348+ assert_eq!(owner.status, 200, "owner private");
12911349 for query in [
12921350 "page=abc",
12931351 "page=0",
@@ -1307,115 +1365,4 @@ mod tests {
13071365 assert!(reply.text().contains("Page 1"), "{query}");
13081366 }
13091367 }
1310-
1311- #[tokio::test]
1312- async fn new_issue_route_wins_over_issue_number() {
1313- let fx = fixture(Visibility::Public).await;
1314- let reply = send(
1315- &fx.router,
1316- "GET",
1317- &format!("{}/new", base()),
1318- true,
1319- None,
1320- &[],
1321- )
1322- .await;
1323- assert_eq!(reply.status, 200);
1324- assert!(reply.text().contains(&format!("action=\"{}/new\"", base())));
1325- }
1326-
1327- #[tokio::test]
1328- async fn invalid_draft_keeps_values_and_creates_nothing() {
1329- let fx = fixture(Visibility::Public).await;
1330- let reply = send(
1331- &fx.router,
1332- "POST",
1333- &format!("{}/new", base()),
1334- true,
1335- Some("csrf=issues-test-csrf&title=+++&body=kept+body"),
1336- &[],
1337- )
1338- .await;
1339- assert_eq!(reply.status, 422);
1340- assert!(reply.text().contains("kept body"));
1341- let (total, _) = fx.store.issue_counts(&fx.repo.id).await.unwrap();
1342- assert_eq!(total, 0);
1343- }
1344-
1345- #[tokio::test]
1346- async fn bad_csrf_is_403_and_archived_repo_is_403() {
1347- let fx = fixture(Visibility::Public).await;
1348- let bad = send(
1349- &fx.router,
1350- "POST",
1351- &format!("{}/new", base()),
1352- true,
1353- Some("csrf=wrong&title=hi"),
1354- &[],
1355- )
1356- .await;
1357- assert_eq!(bad.status, 403);
1358-
1359- fx.store.set_repo_archived(&fx.repo.id, true).await.unwrap();
1360- let archived = send(
1361- &fx.router,
1362- "POST",
1363- &format!("{}/new", base()),
1364- true,
1365- Some("csrf=issues-test-csrf&title=hi"),
1366- &[],
1367- )
1368- .await;
1369- assert_eq!(archived.status, 403);
1370- let form = send(
1371- &fx.router,
1372- "GET",
1373- &format!("{}/new", base()),
1374- true,
1375- None,
1376- &[],
1377- )
1378- .await;
1379- assert_eq!(form.status, 403);
1380- }
1381-
1382- #[tokio::test]
1383- async fn turkish_viewer_sees_turkish_list() {
1384- let fx = fixture(Visibility::Public).await;
1385- let reply = send(
1386- &fx.router,
1387- "GET",
1388- &base(),
1389- true,
1390- None,
1391- &[("accept-language", "tr")],
1392- )
1393- .await;
1394- assert_eq!(reply.status, 200);
1395- let html = reply.text();
1396- assert!(html.contains(">Yeni sorun</a>"), "{html}");
1397- assert!(html.contains("Bu filtrelerle eşleşen sorun yok."), "{html}");
1398- }
1399-
1400- #[tokio::test]
1401- async fn turkish_viewer_sees_relative_times_in_turkish() {
1402- let fx = fixture(Visibility::Public).await;
1403- fx.store
1404- .create_issue(&fx.repo.id, &fx.owner.id, "fresh issue", "")
1405- .await
1406- .unwrap();
1407- let html = send(
1408- &fx.router,
1409- "GET",
1410- &base(),
1411- true,
1412- None,
1413- &[("accept-language", "tr")],
1414- )
1415- .await
1416- .text();
1417- assert!(html.contains("az önce"), "{html}");
1418- assert!(html.contains("açıldı"), "{html}");
1419- assert!(!html.contains("just now"), "{html}");
1420- }
14211368 }