const models = require('vn-loopback/server/server').models; describe('edi syncData()', function() { const ediModel = models.Edi; it('should be insert into the table', async() => { const tx = await ediModel.beginTransaction({}); const ctx = {req: {accessToken: {userId: 1}}}; const options = {transaction: tx}; let error; try { await models.FloricodeConfig.create({ id: 1, url: 'http://sample.com', user: 'sample', password: 'sample' }, options); spyOn(ediModel, 'getToken').and.returnValue(Promise.resolve('sampleToken')); spyOn(ediModel, 'getData').and.returnValue(Promise.resolve([ { expiry_date: '2001-01-01', entry_date: '2001-01-01', genus_id: 1, latin_genus_name: 'Oasis', change_date_time: '2001-03-15T10:30:15+01:00', }, { expiry_date: null, entry_date: '2001-01-02', genus_id: 2, latin_genus_name: 'Ibiza', change_date_time: '2001-02-03T18:20:42+00:00', } ])); await ediModel.syncData(ctx, options); await tx.rollback(); } catch (e) { error = e; await tx.rollback(); } expect(error).toBeUndefined(); const data = await ediModel.rawSql('SELECT * FROM edi.genus', [], options); expect(data.length).toEqual(2); }); it('should throw an error if floricode service is not configured', async function() { let error; try { await ediModel.syncData(); } catch (e) { error = e; } expect(error).toBeDefined(); }); });