feat(blog): implement domain-specific blog fetching and canonical URL handling
This commit is contained in:
@@ -2,10 +2,13 @@ import { describe, expect, it } from "vitest";
|
||||
import citiesData from "@/data/city.json";
|
||||
import { ROOT_CITY_ID } from "@/lib/rootCity";
|
||||
import {
|
||||
domainScopeCityId,
|
||||
extractEntityCityId,
|
||||
findDomainByCityId,
|
||||
isBlogVisibleOnDomain,
|
||||
resolveCityDisplayName,
|
||||
} from "@/lib/domainHelpers";
|
||||
import { getBlogCanonicalOrigin } from "@/lib/getCanonicalUrl";
|
||||
|
||||
const YASUJ = citiesData.find((c) => c.domain === "yasuj-nobat.ir");
|
||||
const ROOT = citiesData.find((c) => Number(c.id) === ROOT_CITY_ID);
|
||||
@@ -89,3 +92,53 @@ describe("شکل پاسخ بلاگ (city آبجکت یا null)", () => {
|
||||
expect(findDomainByCityId(extractEntityCityId(post))).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("scope دامنه برای API", () => {
|
||||
it("دامنهٔ ریشه scope ندارد (همهٔ پستها را میبیند)", () => {
|
||||
expect(domainScopeCityId({ matchedCity: ROOT, isRoot: true })).toBeNull();
|
||||
});
|
||||
|
||||
it("دامنهٔ شهری با شناسهٔ همان شهر scope میشود", () => {
|
||||
expect(domainScopeCityId({ matchedCity: YASUJ, isRoot: false })).toBe(Number(YASUJ.id));
|
||||
});
|
||||
|
||||
it("دامنهٔ ناشناخته (نمایندگی) scope ندارد", () => {
|
||||
expect(domainScopeCityId({ matchedCity: undefined, isRoot: false })).toBeNull();
|
||||
expect(domainScopeCityId()).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("دیدهشدن پست روی دامنه (آینهٔ فیلتر بکاند)", () => {
|
||||
const yasujScope = { matchedCity: YASUJ, isRoot: false };
|
||||
const rootScope = { matchedCity: ROOT, isRoot: true };
|
||||
|
||||
it("پست همان شهر روی دامنهٔ خودش دیده میشود", () => {
|
||||
expect(isBlogVisibleOnDomain({ city: { id: String(YASUJ.id) } }, yasujScope)).toBe(true);
|
||||
});
|
||||
|
||||
it("پست شهر دیگر روی این دامنه وجود ندارد", () => {
|
||||
const ahvaz = citiesData.find((c) => c.domain === "ahvaz-nobat.ir");
|
||||
expect(isBlogVisibleOnDomain({ city: { id: String(ahvaz.id) } }, yasujScope)).toBe(false);
|
||||
});
|
||||
|
||||
it("پستِ رکورد ریشه (nobat724) روی دامنهٔ شهری وجود ندارد — همان باگ گزارششده", () => {
|
||||
expect(isBlogVisibleOnDomain({ city: { id: String(ROOT_CITY_ID) } }, yasujScope)).toBe(false);
|
||||
expect(isBlogVisibleOnDomain({ city: { id: String(ROOT_CITY_ID) } }, rootScope)).toBe(true);
|
||||
});
|
||||
|
||||
it("پست سراسری (city: null) همهجا دیده میشود", () => {
|
||||
expect(isBlogVisibleOnDomain({ city: null }, yasujScope)).toBe(true);
|
||||
expect(isBlogVisibleOnDomain({ city: null }, rootScope)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("canonical پست بلاگ", () => {
|
||||
it("پست شهری → دامنهٔ همان شهر", () => {
|
||||
expect(getBlogCanonicalOrigin(YASUJ.id)).toBe("https://yasuj-nobat.ir");
|
||||
});
|
||||
|
||||
it("پست سراسری یا پستِ رکورد ریشه → دامنهٔ اصلی، نه دامنهٔ جاری", () => {
|
||||
expect(getBlogCanonicalOrigin(null)).toBe("https://nobat724.com");
|
||||
expect(getBlogCanonicalOrigin(ROOT_CITY_ID)).toBe("https://nobat724.com");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user