feat(admin,shop-admin): content/brand management + merchant shop profile (add-content-admin-ui)
This commit is contained in:
@@ -182,3 +182,116 @@ async fn profile_writes_require_a_platform_admin() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async fn set_my_profile(
|
||||
app: &common::TestApp,
|
||||
token: &str,
|
||||
body: serde_json::Value,
|
||||
) -> reqwest::Response {
|
||||
client()
|
||||
.put(app.url("/api/shop/profile"))
|
||||
.bearer_auth(token)
|
||||
.json(&body)
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn merchant_profile_upsert_round_trips_to_the_public_read() {
|
||||
let app = spawn_app().await;
|
||||
let admin = login_admin(&app).await;
|
||||
let shop_id = create_shop(&app, &admin, "shop-self-profile").await;
|
||||
let owner = make_shop_owner(&app, &admin, &shop_id).await;
|
||||
|
||||
let body = serde_json::json!({
|
||||
"logo": "/mock/store-self.svg",
|
||||
"company": "Self Co.",
|
||||
"region": "California",
|
||||
"address": {"en": "2 Mission Street", "zh": "米申街 2 号"},
|
||||
"notice": {"en": "Self-service notice", "zh": "自助公告"},
|
||||
"after_sale": {"en": "Self returns.", "zh": "自助退货。"}
|
||||
});
|
||||
let res = set_my_profile(&app, &owner, body).await;
|
||||
assert_eq!(res.status(), 200, "{:?}", res.text().await);
|
||||
|
||||
let shop = find(&list_shops(&app).await, &shop_id).unwrap().clone();
|
||||
assert_eq!(shop["company"], "Self Co.");
|
||||
assert_eq!(shop["address"]["zh"], "米申街 2 号");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn merchant_profile_refuses_incomplete_bilingual_without_writing() {
|
||||
let app = spawn_app().await;
|
||||
let admin = login_admin(&app).await;
|
||||
let shop_id = create_shop(&app, &admin, "shop-self-bilingual").await;
|
||||
let owner = make_shop_owner(&app, &admin, &shop_id).await;
|
||||
|
||||
let good = serde_json::json!({
|
||||
"company": "Merchant Kept Co.",
|
||||
"notice": {"en": "Merchant notice", "zh": "商家公告"}
|
||||
});
|
||||
assert_eq!(set_my_profile(&app, &owner, good).await.status(), 200);
|
||||
|
||||
let bad = serde_json::json!({
|
||||
"company": "Merchant Changed Co.",
|
||||
"notice": {"en": "Only English"}
|
||||
});
|
||||
let res = set_my_profile(&app, &owner, bad).await;
|
||||
assert_eq!(res.status(), 400, "a label missing zh must be refused");
|
||||
|
||||
let shop = find(&list_shops(&app).await, &shop_id).unwrap().clone();
|
||||
assert_eq!(shop["company"], "Merchant Kept Co.");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn merchant_profile_never_stores_scores() {
|
||||
let app = spawn_app().await;
|
||||
let admin = login_admin(&app).await;
|
||||
let shop_id = create_shop(&app, &admin, "shop-self-scores").await;
|
||||
let owner = make_shop_owner(&app, &admin, &shop_id).await;
|
||||
|
||||
let admin_body = serde_json::json!({
|
||||
"company": "Scored Co.",
|
||||
"score_rating": 4.9,
|
||||
"score_service": 4.7
|
||||
});
|
||||
assert_eq!(set_profile(&app, &admin, &shop_id, admin_body).await.status(), 200);
|
||||
|
||||
let merchant_body = serde_json::json!({
|
||||
"company": "Scored Co. Renamed",
|
||||
"score_rating": 1.0,
|
||||
"score_service": 1.0
|
||||
});
|
||||
assert_eq!(set_my_profile(&app, &owner, merchant_body).await.status(), 200);
|
||||
|
||||
let shop = find(&list_shops(&app).await, &shop_id).unwrap().clone();
|
||||
assert_eq!(shop["company"], "Scored Co. Renamed");
|
||||
assert_eq!(shop["score_rating"], 4.9, "merchant writes must not touch scores");
|
||||
assert_eq!(shop["score_service"], 4.7);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn merchant_profile_requires_a_shop_and_scopes_to_it() {
|
||||
let app = spawn_app().await;
|
||||
let admin = login_admin(&app).await;
|
||||
let shop_a = create_shop(&app, &admin, "shop-self-scope-a").await;
|
||||
let shop_b = create_shop(&app, &admin, "shop-self-scope-b").await;
|
||||
let owner_a = make_shop_owner(&app, &admin, &shop_a).await;
|
||||
let (customer, _) = register_customer(&app, "shop-self-cust").await;
|
||||
|
||||
let body = serde_json::json!({ "company": "Scoped Co." });
|
||||
let res = set_my_profile(&app, &customer, body.clone()).await;
|
||||
assert_eq!(res.status(), 403, "a user without a shop must be refused");
|
||||
|
||||
assert_eq!(set_my_profile(&app, &owner_a, body).await.status(), 200);
|
||||
let shop_b_view = find(&list_shops(&app).await, &shop_b).unwrap().clone();
|
||||
assert!(
|
||||
shop_b_view["company"].is_null(),
|
||||
"another shop's profile must stay untouched"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user