salix/back/methods/edi/specs/syncData.spec.js

60 lines
1.9 KiB
JavaScript
Raw Normal View History

2025-02-19 08:51:04 +00:00
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 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',
}
]));
2025-02-19 12:45:06 +00:00
await ediModel.syncData(options);
const data = await ediModel.rawSql('SELECT * FROM edi.genus', [], options);
// The table is deleted within the method itself; it will always be 2
expect(data.length).toEqual(2);
2025-02-19 08:51:04 +00:00
await tx.rollback();
} catch (e) {
error = e;
await tx.rollback();
}
expect(error).toBeUndefined();
});
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();
});
});