Files
wehub-resource-sync 9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

47 lines
1.9 KiB
JavaScript

import { afterEach, describe, expect, it, vi } from 'vitest';
import { getRegistry } from '@jackwener/opencli/registry';
import { ArgumentError } from '@jackwener/opencli/errors';
import { decodeHtmlEntities, requireCountryCode } from './utils.js';
import './search.js';
import './app.js';
afterEach(() => {
vi.unstubAllGlobals();
});
describe('steam adapter helpers', () => {
it('decodes Steam HTML entities from API strings', () => {
expect(decodeHtmlEntities('"Perpetual Testing Initiative" & Co-op')).toBe('"Perpetual Testing Initiative" & Co-op');
expect(decodeHtmlEntities('Portal 2')).toBe('Portal 2');
});
it('validates storefront country code without silent fallback', () => {
expect(requireCountryCode(undefined)).toBe('us');
expect(requireCountryCode(' CN ')).toBe('cn');
expect(() => requireCountryCode('')).toThrow(ArgumentError);
expect(() => requireCountryCode('usd')).toThrow(ArgumentError);
expect(() => requireCountryCode('$$')).toThrow(ArgumentError);
});
});
describe('steam command argument contracts', () => {
it('rejects invalid search currency before fetching', async () => {
const fetchMock = vi.fn();
vi.stubGlobal('fetch', fetchMock);
const search = getRegistry().get('steam/search');
await expect(search.func({ query: 'portal', limit: 5, currency: '$$$' })).rejects.toThrow(ArgumentError);
await expect(search.func({ query: 'portal', limit: 5, currency: '' })).rejects.toThrow(ArgumentError);
expect(fetchMock).not.toHaveBeenCalled();
});
it('rejects invalid app currency before fetching', async () => {
const fetchMock = vi.fn();
vi.stubGlobal('fetch', fetchMock);
const app = getRegistry().get('steam/app');
await expect(app.func({ id: '620', currency: 'usd' })).rejects.toThrow(ArgumentError);
expect(fetchMock).not.toHaveBeenCalled();
});
});