refactor: make ebay auth env-only
This commit is contained in:
41
packages/core/test/ebay-core.test.ts
Normal file
41
packages/core/test/ebay-core.test.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
||||
import fetchEbayItems from "../src/scrapers/ebay";
|
||||
|
||||
const originalFetch = global.fetch;
|
||||
const originalWarn = console.warn;
|
||||
|
||||
describe("eBay Scraper Cookie Handling", () => {
|
||||
beforeEach(() => {
|
||||
global.fetch = mock(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
text: () => Promise.resolve("<html><body></body></html>"),
|
||||
}),
|
||||
) as typeof fetch;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
global.fetch = originalFetch;
|
||||
console.warn = originalWarn;
|
||||
delete process.env.EBAY_COOKIE;
|
||||
});
|
||||
|
||||
test("should ignore request cookie overrides and rely on EBAY_COOKIE", async () => {
|
||||
const warnMock = mock(() => {});
|
||||
console.warn = warnMock;
|
||||
|
||||
await fetchEbayItems("laptop", 1000, {
|
||||
cookies: "s=from-request",
|
||||
});
|
||||
|
||||
expect(global.fetch).toHaveBeenCalledTimes(1);
|
||||
|
||||
const [, init] = (global.fetch as ReturnType<typeof mock>).mock.calls[0];
|
||||
const headers = (init as RequestInit).headers as Record<string, string>;
|
||||
|
||||
expect(headers.Cookie).toBeUndefined();
|
||||
expect(warnMock).toHaveBeenCalledWith(
|
||||
"No valid eBay cookies found in EBAY_COOKIE. eBay may block requests without a raw Cookie header string.",
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user