| 387 |
387 |
|
let data: Value = resp.json();
|
| 388 |
388 |
|
assert_eq!(data["word_count"].as_u64(), Some(10), "Should count 10 words");
|
| 389 |
389 |
|
}
|
|
390 |
+ |
|
|
391 |
+ |
// create_item dedups slugs via the insert-retry on the per-project unique index
|
|
392 |
+ |
// (the redundant pre-insert SELECT was removed). Two items with the same title in
|
|
393 |
+ |
// one project must still get distinct slugs (base, base-2).
|
|
394 |
+ |
#[tokio::test]
|
|
395 |
+ |
async fn items_with_same_title_get_distinct_slugs() {
|
|
396 |
+ |
let mut h = TestHarness::new().await;
|
|
397 |
+ |
let user_id = h.signup("slugdedup", "slugdedup@test.com", "password123").await;
|
|
398 |
+ |
h.grant_creator(user_id).await;
|
|
399 |
+ |
h.client.post_form("/logout", "").await;
|
|
400 |
+ |
h.login("slugdedup", "password123").await;
|
|
401 |
+ |
|
|
402 |
+ |
let resp = h.client.post_form("/api/projects", "slug=slugdedup-proj&title=Project").await;
|
|
403 |
+ |
assert!(resp.status.is_success(), "create project: {}", resp.text);
|
|
404 |
+ |
let project: Value = resp.json();
|
|
405 |
+ |
let project_id = project["id"].as_str().unwrap().to_string();
|
|
406 |
+ |
|
|
407 |
+ |
for _ in 0..2 {
|
|
408 |
+ |
let resp = h
|
|
409 |
+ |
.client
|
|
410 |
+ |
.post_form(
|
|
411 |
+ |
&format!("/api/projects/{}/items", project_id),
|
|
412 |
+ |
"title=Same+Title&price_cents=0&item_type=digital",
|
|
413 |
+ |
)
|
|
414 |
+ |
.await;
|
|
415 |
+ |
assert!(resp.status.is_success(), "create item: {}", resp.text);
|
|
416 |
+ |
}
|
|
417 |
+ |
|
|
418 |
+ |
let mut slugs: Vec<String> = sqlx::query_scalar(
|
|
419 |
+ |
"SELECT slug FROM items WHERE project_id = $1::uuid",
|
|
420 |
+ |
)
|
|
421 |
+ |
.bind(&project_id)
|
|
422 |
+ |
.fetch_all(&h.db)
|
|
423 |
+ |
.await
|
|
424 |
+ |
.unwrap();
|
|
425 |
+ |
slugs.sort();
|
|
426 |
+ |
assert_eq!(
|
|
427 |
+ |
slugs,
|
|
428 |
+ |
vec!["same-title".to_string(), "same-title-2".to_string()],
|
|
429 |
+ |
"same-title items must get distinct slugs via the insert-retry dedup"
|
|
430 |
+ |
);
|
|
431 |
+ |
}
|