Files
klz-cables.com/.pnpm-store/v10/files/c4/e2f876fa24ed77d31918b1b3fa63ddd74b09a78135bbecde694341c6a29b193b304a97d1057c368ae7bb977851b85af590387cad739a6e5b0b9961c459482c
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

125 lines
4.2 KiB
Plaintext

import { describe, expect, it, vi } from 'vitest';
import { createLocalReq } from './createLocalReq.js';
describe('createLocalReq - URL construction', ()=>{
const mockPayload = {
config: {
serverURL: undefined,
i18n: {
fallbackLanguage: 'en',
supportedLanguages: {
en: {}
},
translations: {}
},
localization: undefined
},
logger: {
error: vi.fn()
}
};
it('should use req.url when provided and serverURL is undefined', async ()=>{
const req = {
url: 'http://example.com/api/test'
};
const result = await createLocalReq({
req
}, mockPayload);
expect(result.url).toBe('http://example.com/api/test');
expect(mockPayload.logger.error).not.toHaveBeenCalled();
});
it('should use serverURL when req.url is not provided', async ()=>{
const payloadWithServerURL = {
config: {
serverURL: 'http://configured-server.com',
i18n: {
fallbackLanguage: 'en',
supportedLanguages: {
en: {}
},
translations: {}
},
localization: undefined
},
logger: {
error: vi.fn()
}
};
const req = {};
const result = await createLocalReq({
req,
urlSuffix: '/api'
}, payloadWithServerURL);
expect(result.url).toContain('http://configured-server.com/api');
expect(payloadWithServerURL.logger.error).not.toHaveBeenCalled();
});
it('should prioritize req.url over serverURL', async ()=>{
const payloadWithServerURL = {
config: {
serverURL: 'http://configured-server.com',
i18n: {
fallbackLanguage: 'en',
supportedLanguages: {
en: {}
},
translations: {}
},
localization: undefined
},
logger: {
error: vi.fn()
}
};
const req = {
url: 'http://actual-request.com/api/test'
};
const result = await createLocalReq({
req
}, payloadWithServerURL);
expect(result.url).toBe('http://actual-request.com/api/test');
expect(payloadWithServerURL.logger.error).not.toHaveBeenCalled();
});
it('should fall back to localhost when neither req.url nor serverURL provided', async ()=>{
const req = {};
const result = await createLocalReq({
req
}, mockPayload);
expect(result.url).toBe('http://localhost/');
expect(mockPayload.logger.error).not.toHaveBeenCalled();
});
it('should append urlSuffix to serverURL when used', async ()=>{
const payloadWithServerURL = {
config: {
serverURL: 'http://configured-server.com',
i18n: {
fallbackLanguage: 'en',
supportedLanguages: {
en: {}
},
translations: {}
},
localization: undefined
},
logger: {
error: vi.fn()
}
};
const req = {};
const result = await createLocalReq({
req,
urlSuffix: '/api/preview'
}, payloadWithServerURL);
expect(result.url).toContain('/api/preview');
expect(payloadWithServerURL.logger.error).not.toHaveBeenCalled();
});
it('should append urlSuffix to fallback URL when neither req.url nor serverURL provided', async ()=>{
const req = {};
const result = await createLocalReq({
req,
urlSuffix: '/api/test'
}, mockPayload);
expect(result.url).toBe('http://localhost/api/test');
expect(mockPayload.logger.error).not.toHaveBeenCalled();
});
});
//# sourceMappingURL=createLocalReq.spec.js.map