2164 - Show confirmation only when data is not empty
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-03-04 09:26:12 +01:00
parent 3a8d061ef7
commit d6278e0df9
4 changed files with 70 additions and 29 deletions

View File

@ -554,30 +554,30 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des
INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `workerFk`, `created`) INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `workerFk`, `created`)
VALUES VALUES
(1, 16, 5 , DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), (1, 16, 5 , DATE_ADD(NOW(), INTERVAL -1 MONTH)),
(2, 16, 5 , DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), (2, 16, 5 , DATE_ADD(NOW(), INTERVAL -1 MONTH)),
(3, 16, 5 , DATE_ADD(CURDATE(), INTERVAL -2 MONTH)), (3, 16, 5 , DATE_ADD(NOW(), INTERVAL -2 MONTH)),
(4, 16, 5 , DATE_ADD(CURDATE(), INTERVAL -3 MONTH)), (4, 16, 5 , DATE_ADD(NOW(), INTERVAL -3 MONTH)),
(5, 16, 18, DATE_ADD(CURDATE(), INTERVAL -4 MONTH)), (5, 16, 18, DATE_ADD(NOW(), INTERVAL -4 MONTH)),
(6, 16, 18, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), (6, 16, 18, DATE_ADD(NOW(), INTERVAL -1 MONTH)),
(7, 10, 18, CURDATE()), (7, 10, 18, NOW()),
(8, 5, 19, CURDATE()), (8, 5, 19, NOW()),
(9, 5, 19, CURDATE()), (9, 5, 19, NOW()),
(10, 5, 19, CURDATE()), (10, 5, 19, NOW()),
(11, 3, 19, CURDATE()), (11, 3, 19, NOW()),
(12, 3, 19, CURDATE()), (12, 3, 19, NOW()),
(13, 3, 19, CURDATE()), (13, 3, 19, NOW()),
(14, 3, 19, CURDATE()), (14, 3, 19, NOW()),
(15, 3, 19, CURDATE()), (15, 3, 19, NOW()),
(16, 3, 19, CURDATE()), (16, 3, 19, NOW()),
(17, 3, 19, CURDATE()), (17, 3, 19, NOW()),
(18, 3, 19, CURDATE()), (18, 3, 19, NOW()),
(19, 17, 19, CURDATE()), (19, 17, 19, NOW()),
(20, 1, 19, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), (20, 1, 19, DATE_ADD(NOW(), INTERVAL +1 MONTH)),
(21, 1, 19, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), (21, 1, 19, DATE_ADD(NOW(), INTERVAL +1 MONTH)),
(22, 1, 19, DATE_ADD(CURDATE(), INTERVAL +1 MONTH)), (22, 1, 19, DATE_ADD(NOW(), INTERVAL +1 MONTH)),
(23, 16, 21, CURDATE()), (23, 16, 21, NOW()),
(24, 16, 21, CURDATE()); (24, 16, 21, NOW());
INSERT INTO `vn`.`stowaway`(`id`, `shipFk`, `created`) INSERT INTO `vn`.`stowaway`(`id`, `shipFk`, `created`)
VALUES VALUES

View File

@ -5,16 +5,27 @@ export default class Controller extends Component {
onSubmit() { onSubmit() {
const orgData = this.$.watcher.orgData; const orgData = this.$.watcher.orgData;
delete this.client.despiteOfClient; delete this.client.despiteOfClient;
if (!orgData.isTaxDataChecked && this.client.isTaxDataChecked) const hasContactData = this.client.email || this.client.phone || this.client.mobile;
if (!orgData.isTaxDataChecked && this.client.isTaxDataChecked && hasContactData)
this.checkExistingClient(); this.checkExistingClient();
else this.save(); else this.save();
} }
checkExistingClient() { checkExistingClient() {
const findParams = [];
if (this.client.email)
findParams.push({email: this.client.email});
if (this.client.phone)
findParams.push({phone: this.client.phone});
if (this.client.mobile)
findParams.push({mobile: this.client.mobile});
const filterObj = { const filterObj = {
where: { where: {
and: [ and: [
{or: [{email: this.client.email}, {phone: this.client.phone}]}, {or: findParams},
{id: {neq: this.client.id}} {id: {neq: this.client.id}}
] ]
} }

View File

@ -49,9 +49,31 @@ describe('Client', () => {
}); });
describe('checkExistingClient()', () => { describe('checkExistingClient()', () => {
it('should show a save confirmation when a duplicated client is found and then set the despiteOfClient property', () => { it(`should make a HTTP GET query filtering by email, phone and mobile`, () => {
controller.client.mobile = 222222222;
const filterObj = {
where: {
and: [
{or: [
{email: controller.client.email},
{phone: controller.client.phone},
{mobile: controller.client.mobile}
]},
{id: {neq: controller.client.id}}
]
}
};
const expectedClient = {id: 102};
const filter = encodeURIComponent(JSON.stringify(filterObj));
$httpBackend.expect('GET', `Clients/findOne?filter=${filter}`).respond(expectedClient);
controller.checkExistingClient();
$httpBackend.flush();
});
it(`should show a save confirmation and then set the despiteOfClient property`, () => {
controller.$.confirmDuplicatedClient = {show: () => {}}; controller.$.confirmDuplicatedClient = {show: () => {}};
jest.spyOn(controller.$.confirmDuplicatedClient, 'show'); jest.spyOn(controller.$.confirmDuplicatedClient, 'show');
const filterObj = { const filterObj = {
where: { where: {
and: [ and: [

View File

@ -8,8 +8,16 @@ describe('ticket makeInvoice()', () => {
let ticket = await app.models.Ticket.findById(11); let ticket = await app.models.Ticket.findById(11);
await ticket.updateAttributes({refFk: null}); await ticket.updateAttributes({refFk: null});
let ticketTracking = await app.models.TicketTracking.findOne({order: 'id DESC', limit: 1}); let ticketTrackings = await app.models.TicketTracking.find({
await ticketTracking.destroy(); where: {
ticketFk: ticketId,
stateFk: {neq: 3}
},
order: 'id DESC'
});
for (let state of ticketTrackings)
await state.destroy();
let invoiceOut = await app.models.InvoiceOut.findById(invoice.invoiceFk); let invoiceOut = await app.models.InvoiceOut.findById(invoice.invoiceFk);
await invoiceOut.destroy(); await invoiceOut.destroy();