Merge pull request 'fix: refs #6404 fix cancel shipment' (!2486) from 6404-mrwIntegrationWebService into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2486
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Pablo Natek 2024-05-20 12:02:48 +00:00
commit dab8ae92ef
3 changed files with 8 additions and 14 deletions

View File

@ -39,8 +39,6 @@ module.exports = Self => {
const xmlString = response.data; const xmlString = response.data;
const parser = new DOMParser(); const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlString, 'text/xml'); const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
const [resultElement] = xmlDoc.getElementsByTagName('Mensaje'); return xmlDoc.getElementsByTagName('Mensaje')[0].textContent;
return resultElement.textContent;
}; };
}; };

View File

@ -42,7 +42,8 @@ module.exports = Self => {
throw new UserError(`Some mrwConfig parameters are not set`); throw new UserError(`Some mrwConfig parameters are not set`);
const query = const query =
`SELECT CASE co.code `SELECT
CASE co.code
WHEN 'ES' THEN a.postalCode WHEN 'ES' THEN a.postalCode
WHEN 'PT' THEN LEFT(a.postalCode, 4) WHEN 'PT' THEN LEFT(a.postalCode, 4)
WHEN 'AD' THEN REPLACE(a.postalCode, 'AD', '00') WHEN 'AD' THEN REPLACE(a.postalCode, 'AD', '00')
@ -89,14 +90,9 @@ module.exports = Self => {
const getLabelResponse = await sendXmlDoc('getLabel', {mrw, shipmentId}, 'text/xml'); const getLabelResponse = await sendXmlDoc('getLabel', {mrw, shipmentId}, 'text/xml');
const file = getTextByTag(getLabelResponse, 'EtiquetaFile'); const file = getTextByTag(getLabelResponse, 'EtiquetaFile');
try { if (tx) await tx.commit();
await models.Expedition.updateAll({id: expeditionFk}, {externalId: shipmentId}, myOptions);
if (tx) await tx.commit(); return {shipmentId, file};
} catch (error) {
if (tx) await tx.rollback();
throw error;
}
return file;
}; };
function getTextByTag(xmlDoc, tag) { function getTextByTag(xmlDoc, tag) {

View File

@ -81,9 +81,9 @@ describe('MRWConfig createShipment()', () => {
spyOn(axios, 'post').and.callFake(() => Promise.resolve(mockPostResponses.pop())); spyOn(axios, 'post').and.callFake(() => Promise.resolve(mockPostResponses.pop()));
const base64Binary = await models.MrwConfig.createShipment(expedition1.id, options); const {file} = await models.MrwConfig.createShipment(expedition1.id, options);
expect(base64Binary).toEqual(mockBase64Binary); expect(file).toEqual(mockBase64Binary);
}); });
it('should fail if mrwConfig has no data', async() => { it('should fail if mrwConfig has no data', async() => {