fix(prestashop): import customer messages across checkout sources (1.1.8)
This commit is contained in:
@@ -107,3 +107,89 @@ test('does not turn an unsafe reference filter into an empty combination match',
|
||||
|
||||
assert.equal(await api.findProductCombinationsByReference('1', 'SKU[1]'), null);
|
||||
});
|
||||
|
||||
test('collects public customer notes from order, cart and customer thread without cross-order leakage', async t => {
|
||||
const originalFetch = Core.fetch;
|
||||
t.after(() => { Core.fetch = originalFetch; });
|
||||
const calls = [];
|
||||
Core.fetch = async url => {
|
||||
const parsed = new URL(url);
|
||||
calls.push(parsed);
|
||||
const orderId = parsed.searchParams.get('filter[id_order]');
|
||||
const cartId = parsed.searchParams.get('filter[id_cart]');
|
||||
const threadId = parsed.searchParams.get('filter[id_customer_thread]');
|
||||
if (parsed.pathname.endsWith('/messages') && orderId === '[7]') return response(200, {
|
||||
messages: [
|
||||
{ id: '1', id_order: '7', id_cart: '11', private: '0', id_employee: '0', message: 'Dostawa rano' },
|
||||
{ id: '2', id_order: '7', id_cart: '11', private: '1', id_employee: '0', message: 'Prywatna' },
|
||||
{ id: '3', id_order: '7', id_cart: '11', private: '0', id_employee: '5', message: 'Pracownik' },
|
||||
{ id: '4', id_order: '8', id_cart: '11', private: '0', id_employee: '0', message: 'Obce zamówienie' },
|
||||
{ id: '7', id_order: '7', id_cart: '11', private: '0', id_employee: '0', message: 42 },
|
||||
{ id: '8', id_order: '7', id_cart: '11', private: '0', id_employee: '0', message: {} },
|
||||
{ id: '9', id_order: '7', id_cart: '11', private: '0', id_employee: '0', message: ' ' },
|
||||
{ id: '10', id_order: '7', id_cart: '11', private: '0', id_employee: '0', message: 'Proszę o kontakt\r\npo 17:00' },
|
||||
],
|
||||
});
|
||||
if (parsed.pathname.endsWith('/messages') && cartId === '[11]') return response(200, {
|
||||
messages: [
|
||||
{ id: '1', id_order: '7', id_cart: '11', private: '0', id_employee: '0', message: 'Dostawa rano' },
|
||||
{ id: '5', id_order: '0', id_cart: '11', private: 'false', id_employee: '', message: 'Kod bramy: 1234' },
|
||||
{ id: '6', id_order: '8', id_cart: '11', private: '0', id_employee: '0', message: 'Drugi order z koszyka' },
|
||||
],
|
||||
});
|
||||
if (parsed.pathname.endsWith('/customer_threads')) return response(200, {
|
||||
customer_threads: [{ id: '30', id_order: '7' }, { id: '31', id_order: '8' }],
|
||||
});
|
||||
if (parsed.pathname.endsWith('/customer_messages') && threadId === '[30]') return response(200, {
|
||||
customer_messages: [
|
||||
{ id: '40', id_customer_thread: '30', id_employee: '0', message: 'Dostawa rano' },
|
||||
{ id: '41', id_customer_thread: '30', id_employee: '2', message: 'Odpowiedź pracownika' },
|
||||
{ id: '42', id_customer_thread: '31', id_employee: '0', message: 'Obcy wątek' },
|
||||
{ id: '43', id_customer_thread: '30', id_employee: '0', private: '2', message: 'Prywatny niestandardowy' },
|
||||
{ id: '44', id_customer_thread: '30', id_employee: '0', message: 'Proszę o kontakt\npo 17:00' },
|
||||
{ id: '45', id_customer_thread: '30', id_employee: '0', message: 'Dzwonek nie działa' },
|
||||
],
|
||||
});
|
||||
assert.fail(`Unexpected endpoint: ${url}`);
|
||||
};
|
||||
const api = new PrestashopApi('https://shop.example', 'secret', true, { maxGetAttempts: 1 });
|
||||
|
||||
assert.deepEqual(await api.getCustomerNotes('7', '11', 'Dla Ani'), [
|
||||
'Wiadomość dołączona do prezentu: Dla Ani',
|
||||
'Dostawa rano',
|
||||
'Proszę o kontakt\r\npo 17:00',
|
||||
'Dzwonek nie działa',
|
||||
'Kod bramy: 1234',
|
||||
]);
|
||||
assert.equal(calls.filter(call => call.pathname.endsWith('/customer_messages')).length, 1);
|
||||
});
|
||||
|
||||
test('keeps notes from available sources when one customer-note endpoint is forbidden', async t => {
|
||||
const originalFetch = Core.fetch;
|
||||
t.after(() => { Core.fetch = originalFetch; });
|
||||
Core.fetch = async url => {
|
||||
const parsed = new URL(url);
|
||||
if (parsed.pathname.endsWith('/messages') && parsed.searchParams.get('filter[id_order]') === '[7]') {
|
||||
return response(403, { errors: [] });
|
||||
}
|
||||
if (parsed.pathname.endsWith('/messages') && parsed.searchParams.get('filter[id_cart]') === '[11]') {
|
||||
return response(200, { messages: [{ id_cart: '11', id_order: '0', private: '0', id_employee: '0', message: 'Checkout działa' }] });
|
||||
}
|
||||
if (parsed.pathname.endsWith('/customer_threads')) return response(200, { customer_threads: [] });
|
||||
assert.fail(`Unexpected endpoint: ${url}`);
|
||||
};
|
||||
const api = new PrestashopApi('https://shop.example', 'secret', true, { maxGetAttempts: 1 });
|
||||
|
||||
assert.deepEqual(await api.getCustomerNotes('7', '11'), ['Checkout działa']);
|
||||
});
|
||||
|
||||
test('retains gift_message when every customer-note endpoint is unavailable', async t => {
|
||||
const originalFetch = Core.fetch;
|
||||
t.after(() => { Core.fetch = originalFetch; });
|
||||
Core.fetch = async () => response(403, { errors: [] });
|
||||
const api = new PrestashopApi('https://shop.example', 'secret', true, { maxGetAttempts: 1 });
|
||||
|
||||
assert.deepEqual(await api.getCustomerNotes('7', '11', 'Dla Ani'), [
|
||||
'Wiadomość dołączona do prezentu: Dla Ani',
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user