fix(prestashop): import dates in the shop time zone (1.1.15)
This commit is contained in:
@@ -86,3 +86,40 @@ test('mapping validation prevents two PrestaShop states from sharing one Orbito
|
||||
|
||||
assert.deepEqual(errors.map(error => error.field), ['state_2', 'state_3']);
|
||||
});
|
||||
|
||||
test('connection validates the shop time zone and defaults to Europe/Warsaw', async () => {
|
||||
const module = loadConfigModule({ states: [{ id: '2', name: 'New' }] });
|
||||
const blocks = await module.register();
|
||||
assert.equal(blocks.connection.schema.timeZone.default, 'Europe/Warsaw');
|
||||
const errors = [];
|
||||
const report = { addError: (field, message) => errors.push({ field, message }) };
|
||||
const connection = { apiUrl: 'https://shop.test', apiKey: 'secret' };
|
||||
await blocks.connection.validate({ ...connection, timeZone: 'Not/AZone' }, report);
|
||||
assert.deepEqual(errors.map(error => error.field), ['timeZone']);
|
||||
errors.length = 0;
|
||||
for (const timeZone of ['', 'Europe/Warsaw', 'UTC', 'Europe/London']) {
|
||||
await blocks.connection.validate({ ...connection, timeZone }, report);
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('config loading applies Warsaw to existing installations and passes a saved shop zone to jobs', async () => {
|
||||
let savedTimeZone;
|
||||
const originalLoad = Module._load;
|
||||
Module._load = function(request, parent, isMain) {
|
||||
if (request === '@orbito/api-lib') return { Config: {
|
||||
get: async (key, fallback) => key === 'connection.timeZone' ? savedTimeZone ?? fallback : fallback,
|
||||
} };
|
||||
return originalLoad.call(this, request, parent, isMain);
|
||||
};
|
||||
let loadConfig;
|
||||
try {
|
||||
delete require.cache[require.resolve('../src/module-config')];
|
||||
({ loadConfig } = require('../src/module-config'));
|
||||
} finally { Module._load = originalLoad; }
|
||||
assert.equal((await loadConfig()).timeZone, 'Europe/Warsaw');
|
||||
savedTimeZone = ' ';
|
||||
assert.equal((await loadConfig()).timeZone, 'Europe/Warsaw');
|
||||
savedTimeZone = ' Europe/London ';
|
||||
assert.equal((await loadConfig()).timeZone, 'Europe/London');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user