Initial Commit
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import { readdirSync, readFileSync, statSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
|
||||
const PKG_ROOT = join(__dirname, "..");
|
||||
const SRC_ROOT = join(PKG_ROOT, "src");
|
||||
|
||||
interface PackageJson {
|
||||
readonly dependencies?: Record<string, string>;
|
||||
readonly devDependencies?: Record<string, string>;
|
||||
readonly peerDependencies?: Record<string, string>;
|
||||
}
|
||||
|
||||
function walkTypescript(dir: string): string[] {
|
||||
const entries = readdirSync(dir);
|
||||
const files: string[] = [];
|
||||
for (const entry of entries) {
|
||||
const full = join(dir, entry);
|
||||
const st = statSync(full);
|
||||
if (st.isDirectory()) {
|
||||
files.push(...walkTypescript(full));
|
||||
} else if (
|
||||
entry.endsWith(".ts") &&
|
||||
!entry.endsWith(".test.ts") &&
|
||||
!entry.endsWith(".spec.ts")
|
||||
) {
|
||||
files.push(full);
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
describe("universal dep graph", () => {
|
||||
it("declares only universal dependencies", { timeout: 5000 }, () => {
|
||||
const pkg = JSON.parse(
|
||||
readFileSync(join(PKG_ROOT, "package.json"), "utf8")
|
||||
) as PackageJson;
|
||||
const runtime = Object.keys(pkg.dependencies ?? {}).sort();
|
||||
expect(runtime).toEqual(
|
||||
[
|
||||
"@suaveplan/error",
|
||||
"@suaveplan/payment",
|
||||
"@suaveplan/payment-providers",
|
||||
"tslib",
|
||||
].sort()
|
||||
);
|
||||
});
|
||||
|
||||
it("source imports only @suaveplan/* siblings, tslib, and node-free intrinsics", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
// Match any "from 'X'" or "from \"X\"" import specifier.
|
||||
const importPattern = /from\s+['"]([^'"]+)['"]/g;
|
||||
const offenders: string[] = [];
|
||||
for (const file of walkTypescript(SRC_ROOT)) {
|
||||
const text = readFileSync(file, "utf8");
|
||||
for (const match of text.matchAll(importPattern)) {
|
||||
const spec = match[1] ?? "";
|
||||
if (spec.startsWith("node:") || spec.startsWith("bun:")) {
|
||||
offenders.push(`${file}: ${spec}`);
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
spec === "fs" ||
|
||||
spec === "path" ||
|
||||
spec === "crypto" ||
|
||||
spec === "stream" ||
|
||||
spec === "net" ||
|
||||
spec === "http" ||
|
||||
spec === "https" ||
|
||||
spec === "react" ||
|
||||
spec === "react-dom"
|
||||
) {
|
||||
offenders.push(`${file}: ${spec}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
});
|
||||
111
packages/money/payment/payment-provider-paypal/tests/fixtures/paypal-recorder.ts
vendored
Normal file
111
packages/money/payment/payment-provider-paypal/tests/fixtures/paypal-recorder.ts
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
import type { FetchLike } from "@suaveplan/payment-providers";
|
||||
import { PayPalProvider } from "../../src/paypal/paypal.js";
|
||||
|
||||
export interface Recorded {
|
||||
readonly method: string;
|
||||
readonly url: string;
|
||||
readonly headers: Record<string, string>;
|
||||
readonly body: string | undefined;
|
||||
}
|
||||
|
||||
export interface Recorder {
|
||||
readonly fetch: FetchLike;
|
||||
readonly calls: Recorded[];
|
||||
}
|
||||
|
||||
export function recorder(
|
||||
handler: (recorded: Recorded) => Response | Promise<Response>
|
||||
): Recorder {
|
||||
const calls: Recorded[] = [];
|
||||
const fetchImpl: FetchLike = async (url, init) => {
|
||||
const headers: Record<string, string> = {};
|
||||
const raw = init?.headers as Record<string, string> | undefined;
|
||||
if (raw !== undefined) {
|
||||
for (const [k, v] of Object.entries(raw)) {
|
||||
headers[k] = v;
|
||||
}
|
||||
}
|
||||
const body = init?.body;
|
||||
const bodyStr =
|
||||
typeof body === "string"
|
||||
? body
|
||||
: body === undefined
|
||||
? undefined
|
||||
: String(body);
|
||||
const recorded: Recorded = {
|
||||
method: init?.method ?? "GET",
|
||||
url,
|
||||
headers,
|
||||
body: bodyStr,
|
||||
};
|
||||
calls.push(recorded);
|
||||
return handler(recorded);
|
||||
};
|
||||
return { fetch: fetchImpl, calls };
|
||||
}
|
||||
|
||||
export function jsonResponse(data: unknown, status = 200): Response {
|
||||
return new Response(JSON.stringify(data), {
|
||||
status,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
}
|
||||
|
||||
export const TOKEN_RESPONSE = {
|
||||
access_token: "tok_abc",
|
||||
expires_in: 3600,
|
||||
};
|
||||
export const TOKEN_RESPONSE_REFRESH = {
|
||||
access_token: "tok_xyz",
|
||||
expires_in: 3600,
|
||||
};
|
||||
|
||||
export function baseOrder(): Record<string, unknown> {
|
||||
return {
|
||||
id: "ORDER_123",
|
||||
status: "CREATED",
|
||||
intent: "CAPTURE",
|
||||
purchase_units: [
|
||||
{
|
||||
amount: { currency_code: "USD", value: "50.00" },
|
||||
description: "Test order",
|
||||
payments: { captures: [], refunds: [] },
|
||||
},
|
||||
],
|
||||
create_time: "2026-01-01T00:00:00Z",
|
||||
update_time: "2026-01-01T00:00:00Z",
|
||||
};
|
||||
}
|
||||
|
||||
export function baseRefund(): Record<string, unknown> {
|
||||
return {
|
||||
id: "REFUND_123",
|
||||
amount: { value: "20.00", currency_code: "USD" },
|
||||
status: "COMPLETED",
|
||||
create_time: "2026-01-02T00:00:00Z",
|
||||
};
|
||||
}
|
||||
|
||||
export interface MakeArgs {
|
||||
readonly fetch: FetchLike;
|
||||
readonly now?: () => number;
|
||||
readonly base64Encode?: (input: string) => string;
|
||||
readonly baseUrl?: string;
|
||||
readonly sandbox?: boolean;
|
||||
}
|
||||
|
||||
export function make(args: MakeArgs): PayPalProvider {
|
||||
return new PayPalProvider({
|
||||
clientId: "client_x",
|
||||
clientSecret: "secret_y",
|
||||
fetch: args.fetch,
|
||||
...(args.now !== undefined ? { now: args.now } : {}),
|
||||
...(args.base64Encode !== undefined
|
||||
? { base64Encode: args.base64Encode }
|
||||
: {}),
|
||||
...(args.baseUrl !== undefined ? { baseUrl: args.baseUrl } : {}),
|
||||
...(args.sandbox !== undefined ? { sandbox: args.sandbox } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
export const PROD = "https://api-m.paypal.com";
|
||||
@@ -0,0 +1,6 @@
|
||||
// Polyfills for the payment-provider-paypal test environment — none required.
|
||||
// The package consumes the slim core's `FetchLike` seam and the `Base64EncodeFn`
|
||||
// injectable; every test passes an explicit recorder closure, so no platform
|
||||
// `fetch` or `btoa` dependency is needed. This file exists to mirror the
|
||||
// sibling-package layout and to give vitest a stable setup-file path.
|
||||
export {};
|
||||
Reference in New Issue
Block a user