Sim Greenbaum
03/14/2024, 6:07 PMcatch (e) {
if (typeof log !== "undefined") {
log.error({
title: `rate checkup Failed `,
details: e.message || JSON.stringify(e) || "No Meaningful message",
});
} else {
console.log(
`Rate checkup failed: ${
e.message || JSON.stringify(e) || "No meaningful message"
}`
);
}
}
}
battk
03/14/2024, 6:41 PMSim Greenbaum
03/14/2024, 7:22 PMdescribe('shipmentrates function', () => {
it('should log an error if <http://https.post|https.post> throws an error', () => {
// Mock the error object
const error = new Error('Network error');
// Mock the <http://https.post|https.post> function to throw an error
jest.spyOn(https, 'post').mockImplementation(() => { throw error; });
// Spy on log.error
jest.spyOn(log, 'error');
// Call the function
const result = shipment.shipmentrates(10, { shipaddress1: 'Address', city: 'City', state: 'State', zip: '12345' }, 'SKU');
// Check if log.error is called with the correct parameters
expect(log.error).toHaveBeenCalledWith({
title: 'rate checkup Failed',
details: error.message || JSON.stringify(error) || 'No Meaningful message',
});
// Restore the original implementation of <http://https.post|https.post>
https.post.mockRestore();
});
});
Sim Greenbaum
03/14/2024, 7:46 PMerictgrubaugh
03/14/2024, 8:07 PMconst log = require('N/log')
jest.mock(log, ...)
global.log = log
erictgrubaugh
03/14/2024, 8:07 PMlog
, util
, etc), but sadly I don't own that code so I can't share it offhand