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 {
150 150
151 const FORGE_LABELS: &str = "/tahinli/forge/labels";151 const FORGE_LABELS: &str = "/tahinli/forge/labels";
152 152
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.
153 #[tokio::test]156 #[tokio::test]
154-async fn owner_creates_edits_and_deletes_a_label() {157+async fn label_writes_follow_csrf_roles_and_archive_rules() {
155 let s = seeded().await;158 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.
157 let created = call(205 let created = call(
158 &s.site,206 &s.site,
159 "POST",207 "POST",
160 FORGE_LABELS,208 FORGE_LABELS,
161- cookie,209+ owner,
162 form(&[210 form(&[
163 ("name", "bug"),211 ("name", "bug"),
164 ("color", "#FF0000"),212 ("color", "#FF0000"),
@@ -166,25 +214,40 @@ async fn owner_creates_edits_and_deletes_a_label() {
166 ]),214 ]),
167 )215 )
168 .await;216 .await;
169- assert_eq!(created.status, 303);217+ assert_eq!(created.status, 303, "create");
170 assert_eq!(created.location.as_deref(), Some(FORGE_LABELS));218 assert_eq!(created.location.as_deref(), Some(FORGE_LABELS));
171-
172 let page = call(&s.site, "GET", FORGE_LABELS, None, None).await;219 let page = call(&s.site, "GET", FORGE_LABELS, None, None).await;
173- assert_eq!(page.status, 200);220+ assert_eq!(page.status, 200, "labels page");
174- assert!(page.body.contains("label-chip label-"));221+ assert!(page.body.contains("label-chip label-"), "labels page chip");
175- assert!(page.body.contains("bug"));222+ assert!(page.body.contains("bug"), "labels page name");
176 assert!(page.body.contains("/tahinli/forge/issues?label=bug"));223 assert!(page.body.contains("/tahinli/forge/issues?label=bug"));
177-224+ let labels = store.list_labels(&s.repo_id).await.expect("labels");
178- let labels = s.site.store.list_labels(&s.repo_id).await.expect("labels");225+ assert_eq!(labels.len(), 1, "one label after create");
179- assert_eq!(labels.len(), 1);226+ assert_eq!(labels[0].color, "#ff0000", "color is lowercased");
180- assert_eq!(labels[0].color, "#ff0000");
181 let id = labels[0].id.clone();227 let id = labels[0].id.clone();
182 228
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.
183 let edited = call(246 let edited = call(
184 &s.site,247 &s.site,
185 "POST",248 "POST",
186 &format!("{FORGE_LABELS}/{id}"),249 &format!("{FORGE_LABELS}/{id}"),
187- cookie,250+ owner,
188 form(&[251 form(&[
189 ("name", "defect"),252 ("name", "defect"),
190 ("color", "#00ff00"),253 ("color", "#00ff00"),
@@ -192,90 +255,23 @@ async fn owner_creates_edits_and_deletes_a_label() {
192 ]),255 ]),
193 )256 )
194 .await;257 .await;
195- assert_eq!(edited.status, 303);258+ assert_eq!(edited.status, 303, "edit");
196- let labels = s.site.store.list_labels(&s.repo_id).await.expect("labels");259+ let labels = store.list_labels(&s.repo_id).await.expect("labels");
197- assert_eq!(labels[0].name, "defect");260+ assert_eq!(labels[0].name, "defect", "edited name");
198- assert_eq!(labels[0].color, "#00ff00");261+ assert_eq!(labels[0].color, "#00ff00", "edited color");
199-
200 let deleted = call(262 let deleted = call(
201 &s.site,263 &s.site,
202 "POST",264 "POST",
203 &format!("{FORGE_LABELS}/{id}/delete"),265 &format!("{FORGE_LABELS}/{id}/delete"),
204- cookie,266+ owner,
205 form(&[]),267 form(&[]),
206 )268 )
207 .await;269 .await;
208- assert_eq!(deleted.status, 303);270+ assert_eq!(deleted.status, 303, "delete");
209- assert!(271+ assert!(store.list_labels(&s.repo_id).await.expect("labels").is_empty());
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-}
251 272
252-#[tokio::test]273+ // [archive] an archived repo refuses label writes (last, it changes the repo).
253-async fn read_only_collaborator_cannot_write_labels() {274+ store
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
279 .set_repo_archived(&s.repo_id, true)275 .set_repo_archived(&s.repo_id, true)
280 .await276 .await
281 .expect("archive");277 .expect("archive");
@@ -283,21 +279,27 @@ async fn archived_repo_refuses_label_writes() {
283 &s.site,279 &s.site,
284 "POST",280 "POST",
285 FORGE_LABELS,281 FORGE_LABELS,
286- Some(s.tahinli_cookie.as_str()),282+ owner,
287 form(&[("name", "bug"), ("color", "#ff0000")]),283 form(&[("name", "bug"), ("color", "#ff0000")]),
288 )284 )
289 .await;285 .await;
290- assert_eq!(res.status, 403);286+ assert_eq!(res.status, 403, "archived repo");
291 }287 }
292 288
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.
293 #[tokio::test]292 #[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() {
295 let s = seeded().await;294 let s = seeded().await;
296 let store = &s.site.store;295 let store = &s.site.store;
296+ let carol = Some(s.carol_cookie.as_str());
297+ let owner = Some(s.tahinli_cookie.as_str());
297 let issue = store298 let issue = store
298 .create_issue(&s.repo_id, &s.tahinli, "Crash", "")299 .create_issue(&s.repo_id, &s.tahinli, "Crash", "")
299 .await300 .await
300 .expect("issue");301 .expect("issue");
302+ let uri = format!("/tahinli/forge/issues/{}", issue.number);
301 let mine = store303 let mine = store
302 .create_label(&s.repo_id, "bug", "#ff0000", "")304 .create_label(&s.repo_id, "bug", "#ff0000", "")
303 .await305 .await
@@ -306,54 +308,43 @@ async fn labels_on_an_issue_are_recorded_and_cross_repo_ids_are_rejected() {
306 .create_label(&s.other_repo_id, "elsewhere", "#00ff00", "")308 .create_label(&s.other_repo_id, "elsewhere", "#00ff00", "")
307 .await309 .await
308 .expect("other label");310 .expect("other label");
309- let uri = "/tahinli/forge/issues/1/labels";
310 311
312+ // [labels] a valid label is recorded; a batch with a foreign label id is rejected.
311 let ok = call(313 let ok = call(
312 &s.site,314 &s.site,
313 "POST",315 "POST",
314- uri,316+ &format!("{uri}/labels"),
315- Some(s.carol_cookie.as_str()),317+ carol,
316 form(&[("label", mine.id.as_str())]),318 form(&[("label", mine.id.as_str())]),
317 )319 )
318 .await;320 .await;
319- assert_eq!(ok.status, 303);321+ assert_eq!(ok.status, 303, "label add");
320- assert_eq!(ok.location.as_deref(), Some("/tahinli/forge/issues/1"));322+ assert_eq!(ok.location.as_deref(), Some(uri.as_str()));
321 let events = store.list_events(&issue.id).await.expect("events");323 let events = store.list_events(&issue.id).await.expect("events");
322- assert!(events.iter().any(|e| e.kind == "labeled"));324+ assert!(events.iter().any(|e| e.kind == "labeled"), "labeled event");
323-
324 let rejected = call(325 let rejected = call(
325 &s.site,326 &s.site,
326 "POST",327 "POST",
327- uri,328+ &format!("{uri}/labels"),
328- Some(s.carol_cookie.as_str()),329+ carol,
329 form(&[("label", mine.id.as_str()), ("label", theirs.id.as_str())]),330 form(&[("label", mine.id.as_str()), ("label", theirs.id.as_str())]),
330 )331 )
331 .await;332 .await;
332- assert_eq!(rejected.status, 200);333+ assert_eq!(rejected.status, 200, "foreign label");
333 let current = store.issue_labels(&issue.id).await.expect("labels");334 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");
335 assert_eq!(current[0].id, mine.id);336 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";
347 337
338+ // [assignees] known users are set; an unknown user leaves the two in place.
348 let ok = call(339 let ok = call(
349 &s.site,340 &s.site,
350 "POST",341 "POST",
351- uri,342+ &format!("{uri}/assignees"),
352- Some(s.carol_cookie.as_str()),343+ carol,
353 form(&[("assignees", "carol, bob")]),344 form(&[("assignees", "carol, bob")]),
354 )345 )
355 .await;346 .await;
356- assert_eq!(ok.status, 303);347+ assert_eq!(ok.status, 303, "assign");
357 let names: Vec<String> = store348 let names: Vec<String> = store
358 .issue_assignees(&issue.id)349 .issue_assignees(&issue.id)
359 .await350 .await
@@ -361,42 +352,34 @@ async fn assignees_accept_valid_users_and_reject_unknown_ones() {
361 .into_iter()352 .into_iter()
362 .map(|(_, name)| name)353 .map(|(_, name)| name)
363 .collect();354 .collect();
364- assert_eq!(names.len(), 2);355+ assert_eq!(names.len(), 2, "two assignees");
365 assert!(names.iter().any(|n| n == "carol"));356 assert!(names.iter().any(|n| n == "carol"));
366 assert!(names.iter().any(|n| n == "bob"));357 assert!(names.iter().any(|n| n == "bob"));
367-
368 let unknown = call(358 let unknown = call(
369 &s.site,359 &s.site,
370 "POST",360 "POST",
371- uri,361+ &format!("{uri}/assignees"),
372- Some(s.carol_cookie.as_str()),362+ carol,
373 form(&[("assignees", "ghost")]),363 form(&[("assignees", "ghost")]),
374 )364 )
375 .await;365 .await;
376- assert_eq!(unknown.status, 200);366+ assert_eq!(unknown.status, 200, "unknown assignee");
377 assert_eq!(367 assert_eq!(
378 store368 store
379 .issue_assignees(&issue.id)369 .issue_assignees(&issue.id)
380 .await370 .await
381 .expect("assignees")371 .expect("assignees")
382 .len(),372 .len(),
383- 2373+ 2,
374+ "unknown assignee not stored"
384 );375 );
385-}
386 376
387-#[tokio::test]377+ // [milestone] created on forge, set on the issue by a triage user, then cleared.
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");
395 let created = call(378 let created = call(
396 &s.site,379 &s.site,
397 "POST",380 "POST",
398 "/tahinli/forge/milestones",381 "/tahinli/forge/milestones",
399- Some(s.tahinli_cookie.as_str()),382+ owner,
400 form(&[383 form(&[
401 ("title", "v1"),384 ("title", "v1"),
402 ("description", "**Ship**"),385 ("description", "**Ship**"),
@@ -404,25 +387,24 @@ async fn milestone_is_set_and_cleared_on_an_issue() {
404 ]),387 ]),
405 )388 )
406 .await;389 .await;
407- assert_eq!(created.status, 303);390+ assert_eq!(created.status, 303, "milestone create");
408 let milestone = store391 let milestone = store
409 .list_milestones(&s.repo_id, None)392 .list_milestones(&s.repo_id, None)
410 .await393 .await
411 .expect("milestones")394 .expect("milestones")
412 .remove(0);395 .remove(0);
413 assert_eq!(milestone.due_on.as_deref(), Some("2030-01-02"));396 assert_eq!(milestone.due_on.as_deref(), Some("2030-01-02"));
414-
415 let set = call(397 let set = call(
416 &s.site,398 &s.site,
417 "POST",399 "POST",
418- "/tahinli/forge/issues/1/milestone",400+ &format!("{uri}/milestone"),
419- Some(s.carol_cookie.as_str()),401+ carol,
420 form(&[("milestone_id", milestone.id.as_str())]),402 form(&[("milestone_id", milestone.id.as_str())]),
421 )403 )
422 .await;404 .await;
423- assert_eq!(set.status, 303);405+ assert_eq!(set.status, 303, "milestone set");
424 let issue_now = store406 let issue_now = store
425- .issue_by_number(&s.repo_id, 1)407+ .issue_by_number(&s.repo_id, issue.number)
426 .await408 .await
427 .expect("issue")409 .expect("issue")
428 .expect("exists");410 .expect("exists");
@@ -430,46 +412,42 @@ async fn milestone_is_set_and_cleared_on_an_issue() {
430 issue_now.milestone_id.as_deref(),412 issue_now.milestone_id.as_deref(),
431 Some(milestone.id.as_str())413 Some(milestone.id.as_str())
432 );414 );
433-
434 let cleared = call(415 let cleared = call(
435 &s.site,416 &s.site,
436 "POST",417 "POST",
437- "/tahinli/forge/issues/1/milestone",418+ &format!("{uri}/milestone"),
438- Some(s.carol_cookie.as_str()),419+ carol,
439 form(&[("milestone_id", "")]),420 form(&[("milestone_id", "")]),
440 )421 )
441 .await;422 .await;
442- assert_eq!(cleared.status, 303);423+ assert_eq!(cleared.status, 303, "milestone clear");
443 let issue_now = store424 let issue_now = store
444- .issue_by_number(&s.repo_id, 1)425+ .issue_by_number(&s.repo_id, issue.number)
445 .await426 .await
446 .expect("issue")427 .expect("issue")
447 .expect("exists");428 .expect("exists");
448- assert!(issue_now.milestone_id.is_none());429+ assert!(issue_now.milestone_id.is_none(), "milestone cleared");
449-}
450 430
451-#[tokio::test]431+ // [progress] on `other`: one open and one closed issue under one milestone.
452-async fn milestone_progress_close_and_delete_keeps_issues() {432+ let other = &s.other_repo_id;
453- let s = seeded().await;
454- let store = &s.site.store;
455 let open_issue = store433 let open_issue = store
456- .create_issue(&s.repo_id, &s.tahinli, "Open one", "")434+ .create_issue(other, &s.tahinli, "Open one", "")
457 .await435 .await
458 .expect("issue");436 .expect("issue");
459 let done_issue = store437 let done_issue = store
460- .create_issue(&s.repo_id, &s.tahinli, "Done one", "")438+ .create_issue(other, &s.tahinli, "Done one", "")
461 .await439 .await
462 .expect("issue");440 .expect("issue");
463 call(441 call(
464 &s.site,442 &s.site,
465 "POST",443 "POST",
466- "/tahinli/forge/milestones",444+ "/tahinli/other/milestones",
467- Some(s.tahinli_cookie.as_str()),445+ owner,
468 form(&[("title", "v1"), ("due_on", "2030-01-02")]),446 form(&[("title", "v1"), ("due_on", "2030-01-02")]),
469 )447 )
470 .await;448 .await;
471- let milestone = store449+ let other_ms = store
472- .list_milestones(&s.repo_id, None)450+ .list_milestones(other, None)
473 .await451 .await
474 .expect("milestones")452 .expect("milestones")
475 .remove(0);453 .remove(0);
@@ -477,13 +455,13 @@ async fn milestone_progress_close_and_delete_keeps_issues() {
477 store455 store
478 .set_issue_milestone(456 .set_issue_milestone(
479 &store457 &store
480- .issue_by_number(&s.repo_id, number)458+ .issue_by_number(other, number)
481 .await459 .await
482 .expect("issue")460 .expect("issue")
483 .expect("exists")461 .expect("exists")
484 .id,462 .id,
485 &s.tahinli,463 &s.tahinli,
486- Some(milestone.id.as_str()),464+ Some(other_ms.id.as_str()),
487 )465 )
488 .await466 .await
489 .expect("set milestone");467 .expect("set milestone");
@@ -498,29 +476,27 @@ async fn milestone_progress_close_and_delete_keeps_issues() {
498 )476 )
499 .await477 .await
500 .expect("close");478 .expect("close");
501-479+ let list = call(&s.site, "GET", "/tahinli/other/milestones", None, None).await;
502- let list = call(&s.site, "GET", "/tahinli/forge/milestones", None, None).await;480+ assert_eq!(list.status, 200, "progress list");
503- assert_eq!(list.status, 200);
504 assert!(list.body.contains(r#"<progress value="1" max="2">"#));481 assert!(list.body.contains(r#"<progress value="1" max="2">"#));
505 assert!(list.body.contains("1 open"));482 assert!(list.body.contains("1 open"));
506 assert!(list.body.contains("1 closed"));483 assert!(list.body.contains("1 closed"));
507-
508 let closed_list = call(484 let closed_list = call(
509 &s.site,485 &s.site,
510 "GET",486 "GET",
511- "/tahinli/forge/milestones?state=closed",487+ "/tahinli/other/milestones?state=closed",
512 None,488 None,
513 None,489 None,
514 )490 )
515 .await;491 .await;
516 assert!(closed_list.body.contains("No closed milestones."));492 assert!(closed_list.body.contains("No closed milestones."));
517 493
518- let edit_uri = format!("/tahinli/forge/milestones/{}/edit", milestone.id);494+ // [close, delete] closing via edit, then deleting keeps the issues.
519 let edit = call(495 let edit = call(
520 &s.site,496 &s.site,
521 "POST",497 "POST",
522- &edit_uri,498+ &format!("/tahinli/other/milestones/{}/edit", other_ms.id),
523- Some(s.tahinli_cookie.as_str()),499+ owner,
524 form(&[500 form(&[
525 ("title", "v1"),501 ("title", "v1"),
526 ("description", ""),502 ("description", ""),
@@ -529,110 +505,65 @@ async fn milestone_progress_close_and_delete_keeps_issues() {
529 ]),505 ]),
530 )506 )
531 .await;507 .await;
532- assert_eq!(edit.status, 303);508+ assert_eq!(edit.status, 303, "milestone edit");
533 assert_eq!(509 assert_eq!(
534 store510 store
535- .milestone_by_id(&s.repo_id, &milestone.id)511+ .milestone_by_id(other, &other_ms.id)
536 .await512 .await
537 .expect("milestone")513 .expect("milestone")
538 .expect("exists")514 .expect("exists")
539 .state,515 .state,
540 forge_core::IssueState::Closed516 forge_core::IssueState::Closed
541 );517 );
542-
543 let deleted = call(518 let deleted = call(
544 &s.site,519 &s.site,
545 "POST",520 "POST",
546- &format!("/tahinli/forge/milestones/{}/delete", milestone.id),521+ &format!("/tahinli/other/milestones/{}/delete", other_ms.id),
547- Some(s.tahinli_cookie.as_str()),522+ owner,
548 form(&[]),523 form(&[]),
549 )524 )
550 .await;525 .await;
551- assert_eq!(deleted.status, 303);526+ assert_eq!(deleted.status, 303, "milestone delete");
552 assert!(527 assert!(
553 store528 store
554- .list_milestones(&s.repo_id, None)529+ .list_milestones(other, None)
555 .await530 .await
556 .expect("milestones")531 .expect("milestones")
557 .is_empty()532 .is_empty()
558 );533 );
559 let survivor = store534 let survivor = store
560- .issue_by_number(&s.repo_id, open_issue.number)535+ .issue_by_number(other, open_issue.number)
561 .await536 .await
562 .expect("issue")537 .expect("issue")
563 .expect("issues keep existing");538 .expect("issues keep existing");
564- assert!(survivor.milestone_id.is_none());539+ assert!(survivor.milestone_id.is_none(), "issue kept, milestone gone");
565-}
566-
567-#[tokio::test]
568-async fn write_without_csrf_is_rejected() {
569- 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 }540 }
598 541
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.
599 #[tokio::test]544 #[tokio::test]
600-async fn anonymous_viewer_of_a_private_repo_gets_404() {545+async fn issue_lock_requires_triage_and_csrf_and_refuses_read_only_replies() {
601 let s = seeded().await;546 let s = seeded().await;
602- for uri in ["/tahinli/secret/labels", "/tahinli/secret/milestones"] {547+ let store = &s.site.store;
603- let res = call(&s.site, "GET", uri, None, None).await;548+ let issue = store
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
616 .create_issue(&s.repo_id, &s.tahinli, "Lock me", "body")549 .create_issue(&s.repo_id, &s.tahinli, "Lock me", "body")
617 .await550 .await
618- .expect("issue")551+ .expect("issue");
619- .id552+ let base = format!("/tahinli/forge/issues/{}", issue.number);
620-}553+ let lock_uri = format!("{base}/lock");
621 554
622-#[tokio::test]555+ // [role] a read-only collaborator cannot lock.
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";
627 let res = call(556 let res = call(
628 &s.site,557 &s.site,
629 "POST",558 "POST",
630- uri,559+ &lock_uri,
631 Some(s.bob_cookie.as_str()),560 Some(s.bob_cookie.as_str()),
632 form(&[("locked", "1"), ("reason", "spam")]),561 form(&[("locked", "1"), ("reason", "spam")]),
633 )562 )
634 .await;563 .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.
636 let no_token = Some(567 let no_token = Some(
637 form_urlencoded::Serializer::new(String::new())568 form_urlencoded::Serializer::new(String::new())
638 .extend_pairs([("locked", "1"), ("reason", "spam")])569 .extend_pairs([("locked", "1"), ("reason", "spam")])
@@ -641,126 +572,99 @@ async fn lock_requires_triage_and_csrf() {
641 let res = call(572 let res = call(
642 &s.site,573 &s.site,
643 "POST",574 "POST",
644- uri,575+ &lock_uri,
645 Some(s.carol_cookie.as_str()),576 Some(s.carol_cookie.as_str()),
646 no_token,577 no_token,
647 )578 )
648 .await;579 .await;
649- assert_eq!(res.status, 403);580+ assert_eq!(res.status, 403, "lock csrf");
650- let issue = s581+ let current = store
651- .site582+ .issue_by_number(&s.repo_id, issue.number)
652- .store
653- .issue_by_number(&s.repo_id, 1)
654 .await583 .await
655 .expect("lookup")584 .expect("lookup")
656 .expect("issue");585 .expect("issue");
657- assert!(!issue.locked);586+ assert!(!current.locked, "not locked after refusals");
658-}
659 587
660-#[tokio::test]588+ // [lock, unlock] triage locks with a reason, then unlocks and clears it.
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";
665 let res = call(589 let res = call(
666 &s.site,590 &s.site,
667 "POST",591 "POST",
668- uri,592+ &lock_uri,
669 Some(s.carol_cookie.as_str()),593 Some(s.carol_cookie.as_str()),
670 form(&[("locked", "1"), ("reason", "too_heated")]),594 form(&[("locked", "1"), ("reason", "too_heated")]),
671 )595 )
672 .await;596 .await;
673- assert_eq!(res.status, 303);597+ assert_eq!(res.status, 303, "triage lock");
674- let issue = s598+ let current = store
675- .site599+ .issue_by_number(&s.repo_id, issue.number)
676- .store
677- .issue_by_number(&s.repo_id, 1)
678 .await600 .await
679 .expect("lookup")601 .expect("lookup")
680 .expect("issue");602 .expect("issue");
681- assert!(issue.locked);603+ assert!(current.locked);
682- assert_eq!(issue.lock_reason.as_deref(), Some("too_heated"));604+ assert_eq!(current.lock_reason.as_deref(), Some("too_heated"));
683-
684 let res = call(605 let res = call(
685 &s.site,606 &s.site,
686 "POST",607 "POST",
687- uri,608+ &lock_uri,
688 Some(s.carol_cookie.as_str()),609 Some(s.carol_cookie.as_str()),
689 form(&[("locked", "0")]),610 form(&[("locked", "0")]),
690 )611 )
691 .await;612 .await;
692- assert_eq!(res.status, 303);613+ assert_eq!(res.status, 303, "triage unlock");
693- let issue = s614+ let current = store
694- .site615+ .issue_by_number(&s.repo_id, issue.number)
695- .store
696- .issue_by_number(&s.repo_id, 1)
697 .await616 .await
698 .expect("lookup")617 .expect("lookup")
699 .expect("issue");618 .expect("issue");
700- assert!(!issue.locked);619+ assert!(!current.locked);
701- assert_eq!(issue.lock_reason, None);620+ assert_eq!(current.lock_reason, None);
702-}
703 621
704-#[tokio::test]622+ // [locked replies] lock via the store; read-only replies and reactions are refused.
705-async fn locked_issue_refuses_comments_and_reactions_from_read_users() {623+ store
706- let s = seeded().await;624+ .set_issue_locked(&issue.id, Some(&s.tahinli), true, Some("spam"))
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"))
711 .await625 .await
712 .expect("lock");626 .expect("lock");
713-
714 let res = call(627 let res = call(
715 &s.site,628 &s.site,
716 "POST",629 "POST",
717- &format!("{FORGE_ISSUE}/comment"),630+ &format!("{base}/comment"),
718 Some(s.bob_cookie.as_str()),631 Some(s.bob_cookie.as_str()),
719 form(&[("body", "hello"), ("action", "comment")]),632 form(&[("body", "hello"), ("action", "comment")]),
720 )633 )
721 .await;634 .await;
722- assert_eq!(res.status, 403);635+ assert_eq!(res.status, 403, "read-only comment on locked");
723 let res = call(636 let res = call(
724 &s.site,637 &s.site,
725 "POST",638 "POST",
726- &format!("{FORGE_ISSUE}/reactions"),639+ &format!("{base}/reactions"),
727 Some(s.bob_cookie.as_str()),640 Some(s.bob_cookie.as_str()),
728 form(&[641 form(&[
729 ("target_kind", "issue"),642 ("target_kind", "issue"),
730- ("target_id", issue_id.as_str()),643+ ("target_id", issue.id.as_str()),
731 ("reaction", "heart"),644 ("reaction", "heart"),
732 ]),645 ]),
733 )646 )
734 .await;647 .await;
735- assert_eq!(res.status, 403);648+ assert_eq!(res.status, 403, "read-only reaction on locked");
736- let issue = s649+ let current = store
737- .site650+ .issue_by_number(&s.repo_id, issue.number)
738- .store
739- .issue_by_number(&s.repo_id, 1)
740 .await651 .await
741 .expect("lookup")652 .expect("lookup")
742 .expect("issue");653 .expect("issue");
743- assert_eq!(issue.comment_count, 0);654+ assert_eq!(current.comment_count, 0, "refused comment not counted");
744 655
745 // Triage holders still comment, and the page tells Bob why he cannot.656 // Triage holders still comment, and the page tells Bob why he cannot.
746 let res = call(657 let res = call(
747 &s.site,658 &s.site,
748 "POST",659 "POST",
749- &format!("{FORGE_ISSUE}/comment"),660+ &format!("{base}/comment"),
750 Some(s.carol_cookie.as_str()),661 Some(s.carol_cookie.as_str()),
751 form(&[("body", "moderating"), ("action", "comment")]),662 form(&[("body", "moderating"), ("action", "comment")]),
752 )663 )
753 .await;664 .await;
754- assert_eq!(res.status, 303);665+ assert_eq!(res.status, 303, "triage comment on locked");
755- let res = call(666+ let res = call(&s.site, "GET", &base, Some(s.bob_cookie.as_str()), None).await;
756- &s.site,667+ assert_eq!(res.status, 200, "locked page");
757- "GET",
758- FORGE_ISSUE,
759- Some(s.bob_cookie.as_str()),
760- None,
761- )
762- .await;
763- assert_eq!(res.status, 200);
764 assert!(668 assert!(
765 res.body669 res.body
766 .contains("This conversation has been locked (spam) and limited to collaborators.")670 .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 {
638 638
639 const ISSUE: &str = "/tahinli/demo/issues/1";639 const ISSUE: &str = "/tahinli/demo/issues/1";
640 640
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.
641 #[tokio::test]644 #[tokio::test]
642- async fn renders_body_markdown_safely_and_links_refs() {645+ async fn issue_page_renders_and_gates_forms() {
643 let fx = Fixture::new(Visibility::Public).await;646 let fx = Fixture::new(Visibility::Public).await;
644 let owner = tahinli(&fx).await;647 let owner = tahinli(&fx).await;
645 let id = repo_id(&fx).await;648 let id = repo_id(&fx).await;
@@ -652,18 +655,17 @@ mod tests {
652 )655 )
653 .await656 .await
654 .unwrap();657 .unwrap();
658+
659+ // [markdown] the body renders, script tags are stripped, and #1 links to the issue.
655 let (status, _, body) = get(&fx.router, ISSUE).await;660 let (status, _, body) = get(&fx.router, ISSUE).await;
656- assert_eq!(status, 200);661+ assert_eq!(status, 200, "issue page");
657 let html = String::from_utf8(body).unwrap();662 let html = String::from_utf8(body).unwrap();
658 assert!(html.contains(">Heading<a"));663 assert!(html.contains(">Heading<a"));
659 assert!(!html.contains("<script>"));664 assert!(!html.contains("<script>"));
660 assert!(html.contains("class=\"issue-ref\""));665 assert!(html.contains("class=\"issue-ref\""));
661 assert!(html.contains("href=\"/tahinli/demo/issues/1\""));666 assert!(html.contains("href=\"/tahinli/demo/issues/1\""));
662- }
663 667
664- #[tokio::test]668+ // [numbers] zero, non-numeric and missing issues are 404.
665- async fn bad_numbers_and_missing_issues_are_404() {
666- let fx = Fixture::new(Visibility::Public).await;
667 for uri in [669 for uri in [
668 "/tahinli/demo/issues/0",670 "/tahinli/demo/issues/0",
669 "/tahinli/demo/issues/abc",671 "/tahinli/demo/issues/abc",
@@ -672,23 +674,20 @@ mod tests {
672 let (status, _, _) = get(&fx.router, uri).await;674 let (status, _, _) = get(&fx.router, uri).await;
673 assert_eq!(status, 404, "{uri}");675 assert_eq!(status, 404, "{uri}");
674 }676 }
675- }
676 677
677- #[tokio::test]678+ // [forms] anonymous viewers get no forms; the owner gets the triage forms.
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();
686 let (status, _, body) = get(&fx.router, ISSUE).await;679 let (status, _, body) = get(&fx.router, ISSUE).await;
687- assert_eq!(status, 200);680+ assert_eq!(status, 200, "anonymous page");
688 let html = String::from_utf8(body).unwrap();681 let html = String::from_utf8(body).unwrap();
689- assert!(!html.contains("name=\"csrf\""));682+ assert!(!html.contains("name=\"csrf\""), "anonymous csrf");
690- assert!(!html.contains("/issues/1/labels"));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\""));
691 689
690+ // [private] anonymous viewers of a private repo get 404.
692 let private = Fixture::new(Visibility::Private).await;691 let private = Fixture::new(Visibility::Private).await;
693 let owner = tahinli(&private).await;692 let owner = tahinli(&private).await;
694 let id = repo_id(&private).await;693 let id = repo_id(&private).await;
@@ -698,39 +697,29 @@ mod tests {
698 .await697 .await
699 .unwrap();698 .unwrap();
700 let (status, _, _) = get(&private.router, ISSUE).await;699 let (status, _, _) = get(&private.router, ISSUE).await;
701- assert_eq!(status, 404);700+ assert_eq!(status, 404, "private issue");
702 }701 }
703 702
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.
704 #[tokio::test]705 #[tokio::test]
705- async fn owner_gets_triage_forms_in_sidebar() {706+ async fn comment_close_edit_and_archive_rules() {
706 let fx = Fixture::new(Visibility::Public).await;707 let fx = Fixture::new(Visibility::Public).await;
707 let owner = tahinli(&fx).await;708 let owner = tahinli(&fx).await;
708 let id = repo_id(&fx).await;709 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;
709 fx.store712 fx.store
710- .create_issue(&id, &owner.id, "First", "body")713+ .set_collaborator(&id, &carol.id, Role::Triage)
711 .await714 .await
712 .unwrap();715 .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- }
723 716
724- #[tokio::test]717+ // [comment] a read user's comment redirects to the new comment.
725- async fn comment_as_another_user_redirects_to_the_comment() {718+ let a = fx
726- let fx = Fixture::new(Visibility::Public).await;719+ .store
727- let owner = tahinli(&fx).await;720+ .create_issue(&id, &owner.id, "A", "body")
728- let id = repo_id(&fx).await;
729- fx.store
730- .create_issue(&id, &owner.id, "First", "body")
731 .await721 .await
732 .unwrap();722 .unwrap();
733- signed_in(&fx, "bob", "bob-token").await;
734 let form = csrf_form(723 let form = csrf_form(
735 "bob-token",724 "bob-token",
736 &[("body", "Looks good"), ("action", "comment")],725 &[("body", "Looks good"), ("action", "comment")],
@@ -738,177 +727,138 @@ mod tests {
738 let (status, location, _) = send(727 let (status, location, _) = send(
739 &fx.router,728 &fx.router,
740 "POST",729 "POST",
741- "/tahinli/demo/issues/1/comment",730+ &format!("/tahinli/demo/issues/{}/comment", a.number),
742 Some("bob-token"),731 Some("bob-token"),
743 Some(form),732 Some(form),
744 )733 )
745 .await;734 .await;
746- assert_eq!(status, 303);735+ assert_eq!(status, 303, "bob comment");
747- let issue = fx.store.issue_by_number(&id, 1).await.unwrap().unwrap();736+ let comments = fx.store.list_comments(&a.id).await.unwrap();
748- let comments = fx.store.list_comments(&issue.id).await.unwrap();737+ assert_eq!(comments.len(), 1, "one comment on A");
749- assert_eq!(comments.len(), 1);
750 assert_eq!(738 assert_eq!(
751 location.unwrap(),739 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+ )
753 );744 );
754- let (_, _, body) = get(&fx.router, ISSUE).await;745+ let (_, _, body) = get(&fx.router, &format!("/tahinli/demo/issues/{}", a.number)).await;
755 assert!(String::from_utf8(body).unwrap().contains("Looks good"));746 assert!(String::from_utf8(body).unwrap().contains("Looks good"));
756- }
757 747
758- #[tokio::test]748+ // [empty] a blank comment is a validation error and stores nothing.
759- async fn empty_comment_is_a_validation_error() {749+ let b = fx
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
764 .store750 .store
765- .create_issue(&id, &owner.id, "First", "body")751+ .create_issue(&id, &owner.id, "B", "body")
766 .await752 .await
767 .unwrap();753 .unwrap();
768 let form = csrf_form("tahinli", &[("body", " "), ("action", "comment")]);754 let form = csrf_form("tahinli", &[("body", " "), ("action", "comment")]);
769 let (status, _, body) = send(755 let (status, _, body) = send(
770 &fx.router,756 &fx.router,
771 "POST",757 "POST",
772- "/tahinli/demo/issues/1/comment",758+ &format!("/tahinli/demo/issues/{}/comment", b.number),
773 Some("tahinli"),759 Some("tahinli"),
774 Some(form),760 Some(form),
775 )761 )
776 .await;762 .await;
777- assert_eq!(status, 200);763+ assert_eq!(status, 200, "empty comment");
778 assert!(body.contains("Comment cannot be empty."));764 assert!(body.contains("Comment cannot be empty."));
779- assert!(fx.store.list_comments(&issue.id).await.unwrap().is_empty());765+ assert!(fx.store.list_comments(&b.id).await.unwrap().is_empty());
780- }
781 766
782- #[tokio::test]767+ // [author close] the author closes as not planned; the event and the page show it.
783- async fn author_closes_as_not_planned() {768+ let c = fx
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
788 .store769 .store
789- .create_issue(&id, &owner.id, "First", "body")770+ .create_issue(&id, &owner.id, "C", "body")
790 .await771 .await
791 .unwrap();772 .unwrap();
792 let form = csrf_form("tahinli", &[("action", "close_not_planned")]);773 let form = csrf_form("tahinli", &[("action", "close_not_planned")]);
793 let (status, location, _) = send(774 let (status, location, _) = send(
794 &fx.router,775 &fx.router,
795 "POST",776 "POST",
796- "/tahinli/demo/issues/1/comment",777+ &format!("/tahinli/demo/issues/{}/comment", c.number),
797 Some("tahinli"),778 Some("tahinli"),
798 Some(form),779 Some(form),
799 )780 )
800 .await;781 .await;
801- assert_eq!(status, 303);782+ assert_eq!(status, 303, "author close");
802- assert_eq!(location.unwrap(), "/tahinli/demo/issues/1#issue-1");783+ assert_eq!(
784+ location.unwrap(),
785+ format!("/tahinli/demo/issues/{}#issue-{}", c.number, c.number)
786+ );
803 assert_eq!(787 assert_eq!(
804- issue_state(&fx, 1).await,788+ issue_state(&fx, c.number).await,
805 (false, Some("not_planned".to_owned()))789 (false, Some("not_planned".to_owned()))
806 );790 );
807- let events = fx.store.list_events(&issue.id).await.unwrap();791+ let events = fx.store.list_events(&c.id).await.unwrap();
808 assert!(events.iter().any(|e| e.kind == "closed"));792 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;
810 assert!(794 assert!(
811 String::from_utf8(body)795 String::from_utf8(body)
812 .unwrap()796 .unwrap()
813 .contains("Closed as not planned")797 .contains("Closed as not planned")
814 );798 );
815- }
816 799
817- #[tokio::test]800+ // [non-author] a read user cannot close, but can still comment.
818- async fn non_author_cannot_close_but_can_comment() {801+ let d = fx
819- let fx = Fixture::new(Visibility::Public).await;802+ .store
820- let owner = tahinli(&fx).await;803+ .create_issue(&id, &owner.id, "D", "body")
821- let id = repo_id(&fx).await;
822- fx.store
823- .create_issue(&id, &owner.id, "First", "body")
824 .await804 .await
825 .unwrap();805 .unwrap();
826- signed_in(&fx, "bob", "bob-token").await;806+ let d_uri = format!("/tahinli/demo/issues/{}/comment", d.number);
827 let form = csrf_form("bob-token", &[("action", "close_completed")]);807 let form = csrf_form("bob-token", &[("action", "close_completed")]);
828- let (status, _, _) = send(808+ let (status, _, _) = send(&fx.router, "POST", &d_uri, Some("bob-token"), Some(form)).await;
829- &fx.router,809+ assert_eq!(status, 403, "non-author close");
830- "POST",810+ assert_eq!(issue_state(&fx, d.number).await, (true, None));
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-
839 let form = csrf_form("bob-token", &[("body", "Me too"), ("action", "comment")]);811 let form = csrf_form("bob-token", &[("body", "Me too"), ("action", "comment")]);
840- let (status, _, _) = send(812+ let (status, _, _) = send(&fx.router, "POST", &d_uri, Some("bob-token"), Some(form)).await;
841- &fx.router,813+ assert_eq!(status, 303, "non-author comment");
842- "POST",
843- "/tahinli/demo/issues/1/comment",
844- Some("bob-token"),
845- Some(form),
846- )
847- .await;
848- assert_eq!(status, 303);
849- }
850 814
851- #[tokio::test]815+ // [triage] a triage user closes the issue and edits another user's comment.
852- async fn triage_collaborator_closes_and_edits_others_comments() {816+ let e = fx
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
857 .store817 .store
858- .create_issue(&id, &owner.id, "First", "body")818+ .create_issue(&id, &owner.id, "E", "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)
864 .await819 .await
865 .unwrap();820 .unwrap();
866- let bob = signed_in(&fx, "bob", "bob-token").await;
867 let comment = fx821 let comment = fx
868 .store822 .store
869- .add_comment(&issue.id, &bob.id, "original")823+ .add_comment(&e.id, &bob.id, "original")
870 .await824 .await
871 .unwrap();825 .unwrap();
872-
873 let form = csrf_form("carol-token", &[("action", "close_completed")]);826 let form = csrf_form("carol-token", &[("action", "close_completed")]);
874 let (status, _, _) = send(827 let (status, _, _) = send(
875 &fx.router,828 &fx.router,
876 "POST",829 "POST",
877- "/tahinli/demo/issues/1/comment",830+ &format!("/tahinli/demo/issues/{}/comment", e.number),
878 Some("carol-token"),831 Some("carol-token"),
879 Some(form),832 Some(form),
880 )833 )
881 .await;834 .await;
882- assert_eq!(status, 303);835+ assert_eq!(status, 303, "triage close");
883 assert_eq!(836 assert_eq!(
884- issue_state(&fx, 1).await,837+ issue_state(&fx, e.number).await,
885 (false, Some("completed".to_owned()))838 (false, Some("completed".to_owned()))
886 );839 );
887-840+ let uri = format!(
888- let uri = format!("/tahinli/demo/issues/1/comments/{}/edit", comment.id);841+ "/tahinli/demo/issues/{}/comments/{}/edit",
842+ e.number, comment.id
843+ );
889 let (status, _, _) = get(&fx.router, &uri).await;844 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");
891 let (status, _, _) = send(&fx.router, "GET", &uri, Some("carol-token"), None).await;846 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");
893 let form = csrf_form("carol-token", &[("body", "edited by triage")]);848 let form = csrf_form("carol-token", &[("body", "edited by triage")]);
894 let (status, _, _) = send(&fx.router, "POST", &uri, Some("carol-token"), Some(form)).await;849 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");
896 let saved = fx851 let saved = fx
897 .store852 .store
898- .comment_by_id(&issue.id, &comment.id)853+ .comment_by_id(&e.id, &comment.id)
899 .await854 .await
900 .unwrap()855 .unwrap()
901 .unwrap();856 .unwrap();
902 assert_eq!(saved.body, "edited by triage");857 assert_eq!(saved.body, "edited by triage");
903 assert!(saved.edited);858 assert!(saved.edited);
904- }
905 859
906- #[tokio::test]860+ // [edit issue] title and body change, and the rename is recorded.
907- async fn edit_issue_updates_title_and_records_rename() {861+ let f = fx
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
912 .store862 .store
913 .create_issue(&id, &owner.id, "old", "old body")863 .create_issue(&id, &owner.id, "old", "old body")
914 .await864 .await
@@ -917,104 +867,108 @@ mod tests {
917 let (status, location, _) = send(867 let (status, location, _) = send(
918 &fx.router,868 &fx.router,
919 "POST",869 "POST",
920- "/tahinli/demo/issues/1/edit",870+ &format!("/tahinli/demo/issues/{}/edit", f.number),
921 Some("tahinli"),871 Some("tahinli"),
922 Some(form),872 Some(form),
923 )873 )
924 .await;874 .await;
925- assert_eq!(status, 303);875+ assert_eq!(status, 303, "issue edit");
926- assert_eq!(location.unwrap(), "/tahinli/demo/issues/1");876+ assert_eq!(
927- let saved = fx.store.issue_by_number(&id, 1).await.unwrap().unwrap();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();
928 assert_eq!(886 assert_eq!(
929 (saved.title.as_str(), saved.body.as_str()),887 (saved.title.as_str(), saved.body.as_str()),
930 ("new", "new body")888 ("new", "new body")
931 );889 );
932 // The store writes the previous version to edit_history on every edit; the rename event890 // The store writes the previous version to edit_history on every edit; the rename event
933 // is the visible part of that write.891 // 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();
935 assert!(events.iter().any(|e| e.kind == "renamed"));893 assert!(events.iter().any(|e| e.kind == "renamed"));
936- }
937 894
938- #[tokio::test]895+ // [delete comment] deleting one of two comments drops the count to one.
939- async fn deleting_a_comment_decrements_the_count() {896+ let g = fx
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
944 .store897 .store
945- .create_issue(&id, &owner.id, "First", "body")898+ .create_issue(&id, &owner.id, "G", "body")
946 .await899 .await
947 .unwrap();900 .unwrap();
948 let first = fx901 let first = fx
949 .store902 .store
950- .add_comment(&issue.id, &owner.id, "one")903+ .add_comment(&g.id, &owner.id, "one")
951 .await904 .await
952 .unwrap();905 .unwrap();
953 fx.store906 fx.store
954- .add_comment(&issue.id, &owner.id, "two")907+ .add_comment(&g.id, &owner.id, "two")
955 .await908 .await
956 .unwrap();909 .unwrap();
957 assert_eq!(910 assert_eq!(
958 fx.store911 fx.store
959- .issue_by_number(&id, 1)912+ .issue_by_number(&id, g.number)
960 .await913 .await
961 .unwrap()914 .unwrap()
962 .unwrap()915 .unwrap()
963 .comment_count,916 .comment_count,
964- 2917+ 2,
918+ "two comments before delete"
919+ );
920+ let uri = format!(
921+ "/tahinli/demo/issues/{}/comments/{}/delete",
922+ g.number, first.id
965 );923 );
966-
967- let uri = format!("/tahinli/demo/issues/1/comments/{}/delete", first.id);
968 let form = csrf_form("tahinli", &[]);924 let form = csrf_form("tahinli", &[]);
969 let (status, _, _) = send(&fx.router, "POST", &uri, Some("tahinli"), Some(form)).await;925 let (status, _, _) = send(&fx.router, "POST", &uri, Some("tahinli"), Some(form)).await;
970- assert_eq!(status, 303);926+ assert_eq!(status, 303, "delete comment");
971 assert_eq!(927 assert_eq!(
972 fx.store928 fx.store
973- .issue_by_number(&id, 1)929+ .issue_by_number(&id, g.number)
974 .await930 .await
975 .unwrap()931 .unwrap()
976 .unwrap()932 .unwrap()
977 .comment_count,933 .comment_count,
978- 1934+ 1,
935+ "count after delete"
979 );936 );
980- }
981 937
982- #[tokio::test]938+ // [foreign comment] a comment id from another issue is 404 on edit and delete.
983- async fn comment_id_from_another_issue_is_404() {939+ let h1 = fx
984- let fx = Fixture::new(Visibility::Public).await;940+ .store
985- let owner = tahinli(&fx).await;941+ .create_issue(&id, &owner.id, "H1", "body")
986- let id = repo_id(&fx).await;
987- fx.store
988- .create_issue(&id, &owner.id, "First", "body")
989 .await942 .await
990 .unwrap();943 .unwrap();
991- let other = fx944+ let h2 = fx
992 .store945 .store
993- .create_issue(&id, &owner.id, "Second", "body")946+ .create_issue(&id, &owner.id, "H2", "body")
994 .await947 .await
995 .unwrap();948 .unwrap();
996 let foreign = fx949 let foreign = fx
997 .store950 .store
998- .add_comment(&other.id, &owner.id, "elsewhere")951+ .add_comment(&h2.id, &owner.id, "elsewhere")
999 .await952 .await
1000 .unwrap();953 .unwrap();
1001-954+ let edit = format!(
1002- let edit = format!("/tahinli/demo/issues/1/comments/{}/edit", foreign.id);955+ "/tahinli/demo/issues/{}/comments/{}/edit",
956+ h1.number, foreign.id
957+ );
1003 let (status, _, _) = send(&fx.router, "GET", &edit, Some("tahinli"), None).await;958 let (status, _, _) = send(&fx.router, "GET", &edit, Some("tahinli"), None).await;
1004- assert_eq!(status, 404);959+ assert_eq!(status, 404, "foreign edit");
1005- let delete = format!("/tahinli/demo/issues/1/comments/{}/delete", foreign.id);960+ let delete = format!(
961+ "/tahinli/demo/issues/{}/comments/{}/delete",
962+ h1.number, foreign.id
963+ );
1006 let form = csrf_form("tahinli", &[]);964 let form = csrf_form("tahinli", &[]);
1007 let (status, _, _) = send(&fx.router, "POST", &delete, Some("tahinli"), Some(form)).await;965 let (status, _, _) = send(&fx.router, "POST", &delete, Some("tahinli"), Some(form)).await;
1008- assert_eq!(status, 404);966+ assert_eq!(status, 404, "foreign delete");
1009- }
1010 967
1011- #[tokio::test]968+ // [archived] last, because it changes the repo: comments are 403 and the form is hidden.
1012- async fn archived_repo_rejects_writes() {969+ let i = fx
1013- let fx = Fixture::new(Visibility::Public).await;970+ .store
1014- let owner = tahinli(&fx).await;971+ .create_issue(&id, &owner.id, "I", "body")
1015- let id = repo_id(&fx).await;
1016- fx.store
1017- .create_issue(&id, &owner.id, "First", "body")
1018 .await972 .await
1019 .unwrap();973 .unwrap();
1020 fx.store.set_repo_archived(&id, true).await.unwrap();974 fx.store.set_repo_archived(&id, true).await.unwrap();
@@ -1022,13 +976,20 @@ mod tests {
1022 let (status, _, _) = send(976 let (status, _, _) = send(
1023 &fx.router,977 &fx.router,
1024 "POST",978 "POST",
1025- "/tahinli/demo/issues/1/comment",979+ &format!("/tahinli/demo/issues/{}/comment", i.number),
1026 Some("tahinli"),980 Some("tahinli"),
1027 Some(form),981 Some(form),
1028 )982 )
1029 .await;983 .await;
1030- assert_eq!(status, 403);984+ assert_eq!(status, 403, "archived comment");
1031- let (_, _, body) = send(&fx.router, "GET", ISSUE, Some("tahinli"), None).await;985+ let (_, _, body) = send(
1032- assert!(!body.contains("name=\"body\""));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");
1033 }994 }
1034 }995 }
crates/forge-web/src/pages/issues_list.rsmodified+130 -183
@@ -997,11 +997,16 @@ mod tests {
997 html.matches("class=\"issue-row\"").count()997 html.matches("class=\"issue-row\"").count()
998 }998 }
999 999
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.
1000 #[tokio::test]1003 #[tokio::test]
1001- async fn toolbar_links_to_labels_and_milestones() {1004+ async fn empty_create_and_locale_flow() {
1002 let fx = fixture(Visibility::Public).await;1005 let fx = fixture(Visibility::Public).await;
1003 let labels = format!("href=\"/{OWNER}/{REPO}/labels\"");1006 let labels = format!("href=\"/{OWNER}/{REPO}/labels\"");
1004 let milestones = format!("href=\"/{OWNER}/{REPO}/milestones\"");1007 let milestones = format!("href=\"/{OWNER}/{REPO}/milestones\"");
1008+
1009+ // [empty] toolbar links for signed-in and anonymous viewers; no rows yet.
1005 for signed_in in [true, false] {1010 for signed_in in [true, false] {
1006 let html = send(&fx.router, "GET", &base(), signed_in, None, &[])1011 let html = send(&fx.router, "GET", &base(), signed_in, None, &[])
1007 .await1012 .await
@@ -1009,21 +1014,61 @@ mod tests {
1009 assert!(html.contains(&labels), "signed_in={signed_in}");1014 assert!(html.contains(&labels), "signed_in={signed_in}");
1010 assert!(html.contains(&milestones), "signed_in={signed_in}");1015 assert!(html.contains(&milestones), "signed_in={signed_in}");
1011 }1016 }
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}");
1013 1033
1014- #[tokio::test]1034+ // [refusals] an empty-title draft keeps its body and creates nothing; bad CSRF is 403.
1015- async fn empty_list_says_so() {1035+ let draft = send(
1016- let fx = fixture(Visibility::Public).await;1036+ &fx.router,
1017- let reply = send(&fx.router, "GET", &base(), true, None, &[]).await;1037+ "POST",
1018- assert_eq!(reply.status, 200);1038+ &format!("{}/new", base()),
1019- assert!(reply.text().contains("No issues match these filters."));1039+ true,
1020- assert_eq!(rows(&reply.text()), 0);1040+ Some("csrf=issues-test-csrf&title=+++&body=kept+body"),
1021- }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");
1022 1058
1023- #[tokio::test]1059+ // [create] the owner sees the form, and a valid create redirects to issue 1.
1024- async fn newest_first_and_post_creates_an_issue() {1060+ let form = send(
1025- let fx = fixture(Visibility::Public).await;1061+ &fx.router,
1026- let reply = send(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(
1027 &fx.router,1072 &fx.router,
1028 "POST",1073 "POST",
1029 &format!("{}/new", base()),1074 &format!("{}/new", base()),
@@ -1032,35 +1077,77 @@ mod tests {
1032 &[],1077 &[],
1033 )1078 )
1034 .await;1079 .await;
1035- assert_eq!(reply.status, 303);1080+ assert_eq!(created.status, 303, "create");
1036 assert_eq!(1081 assert_eq!(
1037- reply.header("location").as_deref(),1082+ created.header("location").as_deref(),
1038 Some(format!("{}/1", base()).as_str())1083 Some(format!("{}/1", base()).as_str())
1039 );1084 );
1085+
1086+ // [order] two more issues; the list is newest first.
1040 let repo_id = fx.repo.id.clone();1087 let repo_id = fx.repo.id.clone();
1088+ for title in ["second issue", "third issue"] {
1041 fx.store1089 fx.store
1042- .create_issue(&repo_id, &fx.owner.id, "second issue", "")1090+ .create_issue(&repo_id, &fx.owner.id, title, "")
1043- .await
1044- .unwrap();
1045- fx.store
1046- .create_issue(&repo_id, &fx.owner.id, "third issue", "")
1047 .await1091 .await
1048 .unwrap();1092 .unwrap();
1049-1093+ }
1050 let html = send(&fx.router, "GET", &base(), true, None, &[])1094 let html = send(&fx.router, "GET", &base(), true, None, &[])
1051 .await1095 .await
1052 .text();1096 .text();
1053- assert_eq!(rows(&html), 3);1097+ assert_eq!(rows(&html), 3, "three rows");
1054 let third = html.find("third issue").unwrap();1098 let third = html.find("third issue").unwrap();
1055 let second = html.find("second issue").unwrap();1099 let second = html.find("second issue").unwrap();
1056 let first = html.find("first issue").unwrap();1100 let first = html.find("first issue").unwrap();
1057 assert!(third < second && second < first, "{html}");1101 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");
1058 }1140 }
1059 1141
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.
1060 #[tokio::test]1145 #[tokio::test]
1061- async fn pagination_with_thirty_issues() {1146+ async fn pagination_state_label_search_and_anonymous_reads() {
1062 let fx = fixture(Visibility::Public).await;1147 let fx = fixture(Visibility::Public).await;
1063 let repo_id = fx.repo.id.clone();1148 let repo_id = fx.repo.id.clone();
1149+
1150+ // [pagination] 30 issues: page 1 holds 25, page 2 the oldest 5.
1064 for n in 1..=30 {1151 for n in 1..=30 {
1065 fx.store1152 fx.store
1066 .create_issue(&repo_id, &fx.owner.id, &format!("bulk {n:02}"), "")1153 .create_issue(&repo_id, &fx.owner.id, &format!("bulk {n:02}"), "")
@@ -1070,10 +1157,9 @@ mod tests {
1070 let page1 = send(&fx.router, "GET", &base(), true, None, &[])1157 let page1 = send(&fx.router, "GET", &base(), true, None, &[])
1071 .await1158 .await
1072 .text();1159 .text();
1073- assert_eq!(rows(&page1), 25);1160+ assert_eq!(rows(&page1), 25, "page 1 rows");
1074 assert!(page1.contains(">Older<"));1161 assert!(page1.contains(">Older<"));
1075 assert!(!page1.contains(">Newer<"));1162 assert!(!page1.contains(">Newer<"));
1076-
1077 let page2 = send(1163 let page2 = send(
1078 &fx.router,1164 &fx.router,
1079 "GET",1165 "GET",
@@ -1084,18 +1170,13 @@ mod tests {
1084 )1170 )
1085 .await1171 .await
1086 .text();1172 .text();
1087- assert_eq!(rows(&page2), 5);1173+ assert_eq!(rows(&page2), 5, "page 2 rows");
1088 assert!(page2.contains(">Newer<"));1174 assert!(page2.contains(">Newer<"));
1089 assert!(!page2.contains(">Older<"));1175 assert!(!page2.contains(">Older<"));
1090 assert!(page2.contains("bulk 01"));1176 assert!(page2.contains("bulk 01"));
1091- }
1092 1177
1093- #[tokio::test]1178+ // [state] one open and one closed issue; the filters split them.
1094- async fn state_filter_and_counts() {1179+ fx.store
1095- let fx = fixture(Visibility::Public).await;
1096- let repo_id = fx.repo.id.clone();
1097- let open = fx
1098- .store
1099 .create_issue(&repo_id, &fx.owner.id, "still open", "")1180 .create_issue(&repo_id, &fx.owner.id, "still open", "")
1100 .await1181 .await
1101 .unwrap();1182 .unwrap();
@@ -1114,15 +1195,12 @@ mod tests {
1114 )1195 )
1115 .await1196 .await
1116 .unwrap();1197 .unwrap();
1117- assert_eq!(open.number, 1);
1118-
1119 let default = send(&fx.router, "GET", &base(), true, None, &[])1198 let default = send(&fx.router, "GET", &base(), true, None, &[])
1120 .await1199 .await
1121 .text();1200 .text();
1122 assert!(default.contains("still open"));1201 assert!(default.contains("still open"));
1123 assert!(!default.contains("already done"));1202 assert!(!default.contains("already done"));
1124 assert!(default.contains("Closed 1"), "{default}");1203 assert!(default.contains("Closed 1"), "{default}");
1125-
1126 let closed = send(1204 let closed = send(
1127 &fx.router,1205 &fx.router,
1128 "GET",1206 "GET",
@@ -1135,7 +1213,6 @@ mod tests {
1135 .text();1213 .text();
1136 assert!(closed.contains("already done"));1214 assert!(closed.contains("already done"));
1137 assert!(!closed.contains("still open"));1215 assert!(!closed.contains("still open"));
1138-
1139 let all = send(1216 let all = send(
1140 &fx.router,1217 &fx.router,
1141 "GET",1218 "GET",
@@ -1147,7 +1224,6 @@ mod tests {
1147 .await1224 .await
1148 .text();1225 .text();
1149 assert!(all.contains("already done") && all.contains("still open"));1226 assert!(all.contains("already done") && all.contains("still open"));
1150-
1151 let bogus = send(1227 let bogus = send(
1152 &fx.router,1228 &fx.router,
1153 "GET",1229 "GET",
@@ -1157,14 +1233,10 @@ mod tests {
1157 &[],1233 &[],
1158 )1234 )
1159 .await;1235 .await;
1160- assert_eq!(bogus.status, 200);1236+ assert_eq!(bogus.status, 200, "bogus state");
1161 assert!(bogus.text().contains("still open"));1237 assert!(bogus.text().contains("still open"));
1162- }
1163 1238
1164- #[tokio::test]1239+ // [label] the label filter shows only the tagged issue.
1165- async fn label_filter_uses_store_labels() {
1166- let fx = fixture(Visibility::Public).await;
1167- let repo_id = fx.repo.id.clone();
1168 let bug = fx1240 let bug = fx
1169 .store1241 .store
1170 .create_label(&repo_id, "bug", "#d73a4a", "")1242 .create_label(&repo_id, "bug", "#d73a4a", "")
@@ -1183,7 +1255,6 @@ mod tests {
1183 .set_issue_labels(&tagged.id, &fx.owner.id, std::slice::from_ref(&bug.id))1255 .set_issue_labels(&tagged.id, &fx.owner.id, std::slice::from_ref(&bug.id))
1184 .await1256 .await
1185 .unwrap();1257 .unwrap();
1186-
1187 let filtered = send(1258 let filtered = send(
1188 &fx.router,1259 &fx.router,
1189 "GET",1260 "GET",
@@ -1198,12 +1269,8 @@ mod tests {
1198 assert!(!filtered.contains("plain issue"));1269 assert!(!filtered.contains("plain issue"));
1199 assert!(filtered.contains(&format!("label-chip label-{}", bug.id)));1270 assert!(filtered.contains(&format!("label-chip label-{}", bug.id)));
1200 assert!(filtered.contains(&format!("/{OWNER}/{REPO}/labels.css")));1271 assert!(filtered.contains(&format!("/{OWNER}/{REPO}/labels.css")));
1201- }
1202 1272
1203- #[tokio::test]1273+ // [search] % is a literal character in the search term.
1204- async fn search_treats_percent_as_a_literal() {
1205- let fx = fixture(Visibility::Public).await;
1206- let repo_id = fx.repo.id.clone();
1207 for title in ["100% done", "100 done", "other thing"] {1274 for title in ["100% done", "100 done", "other thing"] {
1208 fx.store1275 fx.store
1209 .create_issue(&repo_id, &fx.owner.id, title, "")1276 .create_issue(&repo_id, &fx.owner.id, title, "")
@@ -1223,7 +1290,6 @@ mod tests {
1223 assert!(html.contains(">100% done</a>"), "{html}");1290 assert!(html.contains(">100% done</a>"), "{html}");
1224 assert!(!html.contains(">100 done</a>"), "{html}");1291 assert!(!html.contains(">100 done</a>"), "{html}");
1225 assert!(!html.contains(">other thing</a>"), "{html}");1292 assert!(!html.contains(">other thing</a>"), "{html}");
1226-
1227 let raw = send(1293 let raw = send(
1228 &fx.router,1294 &fx.router,
1229 "GET",1295 "GET",
@@ -1233,22 +1299,18 @@ mod tests {
1233 &[],1299 &[],
1234 )1300 )
1235 .await;1301 .await;
1236- assert_eq!(raw.status, 200);1302+ assert_eq!(raw.status, 200, "raw percent");
1237- }
1238 1303
1239- #[tokio::test]1304+ // [anonymous] reads are public; creates bounce to login and store nothing.
1240- async fn anonymous_reads_public_but_cannot_create() {
1241- let fx = fixture(Visibility::Public).await;
1242- let repo_id = fx.repo.id.clone();
1243 fx.store1305 fx.store
1244 .create_issue(&repo_id, &fx.owner.id, "public issue", "")1306 .create_issue(&repo_id, &fx.owner.id, "public issue", "")
1245 .await1307 .await
1246 .unwrap();1308 .unwrap();
1309+ let (before, _) = fx.store.issue_counts(&repo_id).await.unwrap();
1247 let list = send(&fx.router, "GET", &base(), false, None, &[]).await;1310 let list = send(&fx.router, "GET", &base(), false, None, &[]).await;
1248- assert_eq!(list.status, 200);1311+ assert_eq!(list.status, 200, "anonymous list");
1249 assert!(list.text().contains("public issue"));1312 assert!(list.text().contains("public issue"));
1250 assert!(!list.text().contains("New issue</a>"));1313 assert!(!list.text().contains("New issue</a>"));
1251-
1252 let form = send(1314 let form = send(
1253 &fx.router,1315 &fx.router,
1254 "GET",1316 "GET",
@@ -1258,9 +1320,8 @@ mod tests {
1258 &[],1320 &[],
1259 )1321 )
1260 .await;1322 .await;
1261- assert_eq!(form.status, 303);1323+ assert_eq!(form.status, 303, "anonymous form");
1262 assert!(form.header("location").unwrap().starts_with("/login"));1324 assert!(form.header("location").unwrap().starts_with("/login"));
1263-
1264 let post = send(1325 let post = send(
1265 &fx.router,1326 &fx.router,
1266 "POST",1327 "POST",
@@ -1270,24 +1331,21 @@ mod tests {
1270 &[],1331 &[],
1271 )1332 )
1272 .await;1333 .await;
1273- assert_eq!(post.status, 303);1334+ assert_eq!(post.status, 303, "anonymous create");
1274 assert!(post.header("location").unwrap().starts_with("/login"));1335 assert!(post.header("location").unwrap().starts_with("/login"));
1275 let (total, _) = fx.store.issue_counts(&repo_id).await.unwrap();1336 let (total, _) = fx.store.issue_counts(&repo_id).await.unwrap();
1276- assert_eq!(total, 1);1337+ assert_eq!(total, before, "anonymous create stores nothing");
1277 }1338 }
1278 1339
1340+ /// A private repo is 404 for anonymous viewers and visible to the owner, whose invalid
1341+ /// query values fall back to the defaults.
1279 #[tokio::test]1342 #[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() {
1281 let fx = fixture(Visibility::Private).await;1344 let fx = fixture(Visibility::Private).await;
1282 let list = send(&fx.router, "GET", &base(), false, None, &[]).await;1345 let list = send(&fx.router, "GET", &base(), false, None, &[]).await;
1283- assert_eq!(list.status, 404);1346+ assert_eq!(list.status, 404, "anonymous private");
1284 let owner = send(&fx.router, "GET", &base(), true, None, &[]).await;1347 let owner = send(&fx.router, "GET", &base(), true, None, &[]).await;
1285- assert_eq!(owner.status, 200);1348+ assert_eq!(owner.status, 200, "owner private");
1286- }
1287-
1288- #[tokio::test]
1289- async fn invalid_query_values_fall_back_to_defaults() {
1290- let fx = fixture(Visibility::Public).await;
1291 for query in [1349 for query in [
1292 "page=abc",1350 "page=abc",
1293 "page=0",1351 "page=0",
@@ -1307,115 +1365,4 @@ mod tests {
1307 assert!(reply.text().contains("Page 1"), "{query}");1365 assert!(reply.text().contains("Page 1"), "{query}");
1308 }1366 }
1309 }1367 }
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- }
1421 }1368 }