describe('exchangeRateUpdate functionality', function() { const axios = require('axios'); const models = require('vn-loopback/server/server').models; beforeEach(function() { spyOn(axios, 'get').and.returnValue(Promise.resolve({ data: ` ` })); }); it('should process XML data and update or create rates in the database', async function() { spyOn(models.ReferenceRate, 'findOne').and.returnValue(Promise.resolve(null)); spyOn(models.ReferenceRate, 'create').and.returnValue(Promise.resolve()); await models.InvoiceIn.exchangeRateUpdate(); expect(models.ReferenceRate.create).toHaveBeenCalledTimes(2); }); it('should not create or update rates when no XML data is available', async function() { axios.get.and.returnValue(Promise.resolve({})); spyOn(models.ReferenceRate, 'create'); let thrownError = null; try { await models.InvoiceIn.exchangeRateUpdate(); } catch (error) { thrownError = error; } expect(thrownError.message).toBe('No cubes found. Exiting the method.'); }); it('should handle errors gracefully', async function() { axios.get.and.returnValue(Promise.reject(new Error('Network error'))); let error; try { await models.InvoiceIn.exchangeRateUpdate(); } catch (e) { error = e; } expect(error).toBeDefined(); expect(error.message).toBe('Network error'); }); });