54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
/**
|
|||
|
|
* shopify-admin-urls unit tests (node:test).
|
||
|
|
* Pure URL / handle helpers for Shopify connect deep links (no network).
|
||
|
|
*
|
||
|
|
* Run from apps/web:
|
||
|
|
* node --experimental-strip-types --test src/lib/shopify-admin-urls.test.ts
|
||
|
|
*/
|
||
|
|
import assert from "node:assert/strict";
|
||
|
|
import { describe, it } from "node:test";
|
||
|
|
|
||
|
|
import {
|
||
|
|
SHOPIFY_DEV_DASHBOARD_URL,
|
||
|
|
SHOPIFY_REQUIRED_SCOPES_CSV,
|
||
|
|
shopifyAdminDevelopAppsUrl,
|
||
|
|
shopifyShopHandle
|
||
|
|
} from "./shopify-admin-urls.ts";
|
||
|
|
|
||
|
|
describe("shopifyShopHandle", () => {
|
||
|
|
it("returns null for empty or invalid input", () => {
|
||
|
|
assert.equal(shopifyShopHandle(""), null);
|
||
|
|
assert.equal(shopifyShopHandle(" "), null);
|
||
|
|
assert.equal(shopifyShopHandle("not a shop"), null);
|
||
|
|
assert.equal(shopifyShopHandle("custom.example.com"), null);
|
||
|
|
assert.equal(shopifyShopHandle("localhost"), null);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("accepts bare handle and myshopify host", () => {
|
||
|
|
assert.equal(shopifyShopHandle("acme-store"), "acme-store");
|
||
|
|
assert.equal(shopifyShopHandle("acme-store.myshopify.com"), "acme-store");
|
||
|
|
assert.equal(shopifyShopHandle("https://acme-store.myshopify.com/admin"), "acme-store");
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe("shopifyAdminDevelopAppsUrl", () => {
|
||
|
|
it("returns null until a valid shop handle is known", () => {
|
||
|
|
assert.equal(shopifyAdminDevelopAppsUrl(""), null);
|
||
|
|
assert.equal(shopifyAdminDevelopAppsUrl("https://example.com"), null);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("builds admin.shopify.com develop-apps URL", () => {
|
||
|
|
assert.equal(
|
||
|
|
shopifyAdminDevelopAppsUrl("acme-store"),
|
||
|
|
"https://admin.shopify.com/store/acme-store/settings/apps/development"
|
||
|
|
);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe("shopify constants", () => {
|
||
|
|
it("exposes Dev Dashboard and required scopes CSV", () => {
|
||
|
|
assert.match(SHOPIFY_DEV_DASHBOARD_URL, /^https:\/\/dev\.shopify\.com\//);
|
||
|
|
assert.equal(SHOPIFY_REQUIRED_SCOPES_CSV, "write_products, read_products, read_orders");
|
||
|
|
});
|
||
|
|
});
|