const app = require('vn-loopback/server/server'); const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; describe('zone zone_getLanded()', () => { it(`should return data for a shipped in the past`, async() => { let stmts = []; let stmt; stmts.push('START TRANSACTION'); const date = new Date(); date.setHours(0, 0, 0, 0); let params = { addressFk: 121, agencyModeFk: 7, warehouseFk: 1, showExpiredZones: true}; stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(?, INTERVAL -1 DAY), ?, ?, ?, ?)', [ date, params.addressFk, params.agencyModeFk, params.warehouseFk, params.showExpiredZones ]); stmts.push(stmt); let tableIndex = stmts.push('SELECT count(*) countZone FROM tmp.zoneGetLanded') - 1; stmts.push('ROLLBACK'); let sql = ParameterizedSQL.join(stmts, ';'); let result = await app.models.Ticket.rawStmt(sql); let [zoneTable] = result[tableIndex]; expect(zoneTable.countZone).toBe(1); }); it(`should return data for a shipped tomorrow`, async() => { let stmts = []; let stmt; const date = new Date(); date.setHours(0, 0, 0, 0); stmts.push('START TRANSACTION'); let params = { addressFk: 121, agencyModeFk: 7, warehouseFk: 1, showExpiredZones: false}; stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(?, INTERVAL +2 DAY), ?, ?, ?, ?)', [ date, params.addressFk, params.agencyModeFk, params.warehouseFk, params.showExpiredZones ]); stmts.push(stmt); let tableIndex = stmts.push('SELECT count(*) countZone FROM tmp.zoneGetLanded') - 1; stmts.push('ROLLBACK'); let sql = ParameterizedSQL.join(stmts, ';'); let result = await app.models.Ticket.rawStmt(sql); let [zoneTable] = result[tableIndex]; expect(zoneTable.countZone).toBe(1); }); });