mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-10 09:14:37 +00:00
43d07ca85f
Tighten the package model around the determinism invariant: everything the
engine imports must itself be deterministic.
- Rename core-public -> engine-public (package, dir, `engine-public/*` alias,
all 118 import sites). It is the deterministic public surface the engine
depends on and that client/server also use.
- Move the pure formatting helpers (renderNumber/renderTroops) from shared
into engine-public/format — the engine uses them and they're deterministic.
- Drop the now-empty shared package (and its alias). `shared` was intended for
client/server-shared, engine-forbidden code; there is none yet, so it is
removed and can be re-added when such code appears.
Final graph: engine-public (leaf) <- engine <- {client, server};
client/server also -> engine-public.
Verified: tsc clean; 1364 + 65 tests pass; prod build succeeds; engine-public
is a leaf; engine has no client/server imports. Lockfile regenerated.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
199 lines
4.9 KiB
TypeScript
199 lines
4.9 KiB
TypeScript
import { cosmeticRelationship } from "client/Cosmetics";
|
|
import { UserMeResponse } from "engine-public/ApiSchemas";
|
|
|
|
const product = { productId: "prod_123", priceId: "price_123", price: "$4.99" };
|
|
|
|
function makeUserMe(flares: string[]): UserMeResponse {
|
|
return {
|
|
player: { flares },
|
|
} as unknown as UserMeResponse;
|
|
}
|
|
|
|
describe("cosmeticRelationship", () => {
|
|
it("returns owned when user has wildcard flare", () => {
|
|
expect(
|
|
cosmeticRelationship(
|
|
{
|
|
wildcardFlare: "flag:*",
|
|
requiredFlare: "flag:cool",
|
|
product,
|
|
priceSoft: undefined,
|
|
priceHard: undefined,
|
|
affiliateCode: null,
|
|
itemAffiliateCode: null,
|
|
},
|
|
makeUserMe(["flag:*"]),
|
|
),
|
|
).toBe("owned");
|
|
});
|
|
|
|
it("returns owned when user has the specific flare", () => {
|
|
expect(
|
|
cosmeticRelationship(
|
|
{
|
|
wildcardFlare: "flag:*",
|
|
requiredFlare: "flag:cool",
|
|
product,
|
|
priceSoft: undefined,
|
|
priceHard: undefined,
|
|
affiliateCode: null,
|
|
itemAffiliateCode: null,
|
|
},
|
|
makeUserMe(["flag:cool"]),
|
|
),
|
|
).toBe("owned");
|
|
});
|
|
|
|
it("returns blocked when no product and user does not own it", () => {
|
|
expect(
|
|
cosmeticRelationship(
|
|
{
|
|
wildcardFlare: "flag:*",
|
|
requiredFlare: "flag:cool",
|
|
product: null,
|
|
priceSoft: undefined,
|
|
priceHard: undefined,
|
|
affiliateCode: null,
|
|
itemAffiliateCode: null,
|
|
},
|
|
makeUserMe([]),
|
|
),
|
|
).toBe("blocked");
|
|
});
|
|
|
|
it("returns blocked when affiliate codes do not match", () => {
|
|
expect(
|
|
cosmeticRelationship(
|
|
{
|
|
wildcardFlare: "flag:*",
|
|
requiredFlare: "flag:cool",
|
|
product,
|
|
priceSoft: undefined,
|
|
priceHard: undefined,
|
|
affiliateCode: "storeA",
|
|
itemAffiliateCode: "storeB",
|
|
},
|
|
makeUserMe([]),
|
|
),
|
|
).toBe("blocked");
|
|
});
|
|
|
|
it("returns purchasable when product exists and affiliate matches", () => {
|
|
expect(
|
|
cosmeticRelationship(
|
|
{
|
|
wildcardFlare: "flag:*",
|
|
requiredFlare: "flag:cool",
|
|
product,
|
|
priceSoft: undefined,
|
|
priceHard: undefined,
|
|
affiliateCode: null,
|
|
itemAffiliateCode: null,
|
|
},
|
|
makeUserMe([]),
|
|
),
|
|
).toBe("purchasable");
|
|
});
|
|
|
|
it("returns purchasable when affiliate codes match", () => {
|
|
expect(
|
|
cosmeticRelationship(
|
|
{
|
|
wildcardFlare: "pattern:*",
|
|
requiredFlare: "pattern:stripes:red",
|
|
product,
|
|
priceSoft: undefined,
|
|
priceHard: undefined,
|
|
affiliateCode: "storeA",
|
|
itemAffiliateCode: "storeA",
|
|
},
|
|
makeUserMe([]),
|
|
),
|
|
).toBe("purchasable");
|
|
});
|
|
|
|
it("returns blocked when user is not logged in and no product", () => {
|
|
expect(
|
|
cosmeticRelationship(
|
|
{
|
|
wildcardFlare: "flag:*",
|
|
requiredFlare: "flag:cool",
|
|
product: null,
|
|
priceSoft: undefined,
|
|
priceHard: undefined,
|
|
affiliateCode: null,
|
|
itemAffiliateCode: null,
|
|
},
|
|
false,
|
|
),
|
|
).toBe("blocked");
|
|
});
|
|
|
|
it("returns purchasable when user is not logged in but product exists", () => {
|
|
expect(
|
|
cosmeticRelationship(
|
|
{
|
|
wildcardFlare: "flag:*",
|
|
requiredFlare: "flag:cool",
|
|
product,
|
|
priceSoft: undefined,
|
|
priceHard: undefined,
|
|
affiliateCode: null,
|
|
itemAffiliateCode: null,
|
|
},
|
|
false,
|
|
),
|
|
).toBe("purchasable");
|
|
});
|
|
|
|
it("returns purchasable when item has currency price and no product", () => {
|
|
expect(
|
|
cosmeticRelationship(
|
|
{
|
|
wildcardFlare: "flag:*",
|
|
requiredFlare: "flag:cool",
|
|
product: null,
|
|
priceSoft: 100,
|
|
affiliateCode: null,
|
|
itemAffiliateCode: null,
|
|
},
|
|
makeUserMe([]),
|
|
),
|
|
).toBe("purchasable");
|
|
});
|
|
|
|
it("returns blocked when item has currency price but affiliate codes do not match", () => {
|
|
expect(
|
|
cosmeticRelationship(
|
|
{
|
|
wildcardFlare: "flag:*",
|
|
requiredFlare: "flag:cool",
|
|
product: null,
|
|
priceSoft: 100,
|
|
priceHard: 50,
|
|
affiliateCode: "storeA",
|
|
itemAffiliateCode: "storeB",
|
|
},
|
|
makeUserMe([]),
|
|
),
|
|
).toBe("blocked");
|
|
});
|
|
|
|
it("returns owned when user has wildcard flare for patterns", () => {
|
|
expect(
|
|
cosmeticRelationship(
|
|
{
|
|
wildcardFlare: "pattern:*",
|
|
requiredFlare: "pattern:stripes:red",
|
|
product,
|
|
priceSoft: undefined,
|
|
priceHard: undefined,
|
|
affiliateCode: null,
|
|
itemAffiliateCode: null,
|
|
},
|
|
makeUserMe(["pattern:*"]),
|
|
),
|
|
).toBe("owned");
|
|
});
|
|
});
|