actualizar viaje padre
This commit is contained in:
@@ -177,8 +177,8 @@ test('POST /api/trips/:tripId/start inicia viaje asignado sin otro activo => 200
|
||||
assert.equal(params[1], 1);
|
||||
assert.equal(params[2], '58045340X');
|
||||
assert.equal(params[3], 2);
|
||||
assert.ok(params[7] instanceof Date);
|
||||
assert.equal(params[9], 1);
|
||||
assert.ok(params[8] instanceof Date);
|
||||
assert.equal(params[10], 1);
|
||||
return [{ insertId: 10, affectedRows: 1 }];
|
||||
}
|
||||
|
||||
|
||||
@@ -1048,6 +1048,79 @@ test('POST /api/trips/:id/status estado 5 sin id_punto usa flujo global legacy =
|
||||
assert.equal(step, 6);
|
||||
});
|
||||
|
||||
test('POST /api/trips/:id/status propaga estado global al viaje padre', async () => {
|
||||
let step = 0;
|
||||
|
||||
db.query = async (sql, params) => {
|
||||
step += 1;
|
||||
|
||||
if (step === 1) {
|
||||
assert.match(sql, /FROM t_viaje_estados/);
|
||||
assert.deepEqual(params, [6]);
|
||||
return [[{ id_estado: 6 }]];
|
||||
}
|
||||
|
||||
if (step === 2) {
|
||||
assert.match(sql, /FROM c_viajes/);
|
||||
assert.deepEqual(params, [248230]);
|
||||
return [[{ id_viaje: 248230, id_viaje_padre: 196854 }]];
|
||||
}
|
||||
|
||||
if (step === 3) {
|
||||
assert.match(sql, /FROM c_viajes_proveedor/);
|
||||
assert.deepEqual(params, [248230, '58045340X']);
|
||||
return [[{ n_proveedor: 1, id_proveedor: 675 }]];
|
||||
}
|
||||
|
||||
if (step === 4) {
|
||||
assert.match(sql, /UPDATE c_viajes/);
|
||||
assert.match(sql, /ind_edi_app = 1/);
|
||||
assert.deepEqual(params, [6, 1, 248230]);
|
||||
return [{ affectedRows: 1 }];
|
||||
}
|
||||
|
||||
if (step === 5) {
|
||||
assert.match(sql, /INSERT INTO c_cambios_estado/);
|
||||
assert.equal(params[0], 248230);
|
||||
assert.equal(params[3], 6);
|
||||
return [{ insertId: 6, affectedRows: 1 }];
|
||||
}
|
||||
|
||||
if (step === 6) {
|
||||
assert.match(sql, /UPDATE c_viajes/);
|
||||
assert.match(sql, /ind_edi_app = 1/);
|
||||
assert.deepEqual(params, [6, 1, 196854]);
|
||||
return [{ affectedRows: 1 }];
|
||||
}
|
||||
|
||||
if (step === 7) {
|
||||
assert.match(sql, /SELECT id_viaje_padre/);
|
||||
assert.deepEqual(params, [196854]);
|
||||
return [[{ id_viaje_padre: 0 }]];
|
||||
}
|
||||
|
||||
throw new Error(`Unexpected query step ${step}: ${sql}`);
|
||||
};
|
||||
|
||||
const response = await withServer(async (server) =>
|
||||
requestJson({
|
||||
port: server.address().port,
|
||||
method: 'POST',
|
||||
path: '/api/trips/248230/status',
|
||||
authorization: `Bearer ${createToken()}`,
|
||||
body: {
|
||||
id_estado: 6
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
assert.equal(response.statusCode, 200);
|
||||
assert.equal(response.body.success, true);
|
||||
assert.equal(response.body.trip_id, 248230);
|
||||
assert.equal(response.body.id_estado, 6);
|
||||
assert.equal(step, 7);
|
||||
});
|
||||
|
||||
test('POST /api/trips/:id/status estado intermedio con id_punto inválido => 400', async () => {
|
||||
db.query = async () => {
|
||||
throw new Error('db.query should not run for invalid id_punto');
|
||||
|
||||
Reference in New Issue
Block a user