Fixed mail notification bug #587

This commit is contained in:
Joan Sanchez 2018-10-08 13:09:30 +02:00
parent dff78922a1
commit f878751ff1
3 changed files with 31 additions and 44 deletions

View File

@ -8,20 +8,14 @@ export default class Controller {
this.translate = $translate;
}
set client(value) {
this._client = value;
if (value)
this.orgData = Object.assign({}, value);
}
get client() {
return this._client;
}
onSubmit() {
let shouldNotify = false;
if (this.hasPaymethodChanges())
shouldNotify = true;
this.$scope.watcher.submit().then(() => {
if (this.hasPaymethodChanged())
if (shouldNotify)
this.notifyChanges();
});
}
@ -32,10 +26,12 @@ export default class Controller {
);
}
hasPaymethodChanged() {
let payMethod = this.orgData.payMethodFk != this.client.payMethodFk;
let iban = this.orgData.iban != this.client.iban;
let dueDay = this.orgData.dueDay != this.client.dueDay;
hasPaymethodChanges() {
let orgData = this.$scope.watcher.orgData;
let payMethod = orgData.payMethodFk != this.client.payMethodFk;
let iban = orgData.iban != this.client.iban;
let dueDay = orgData.dueDay != this.client.dueDay;
return payMethod || iban || dueDay;
}

View File

@ -1,4 +1,5 @@
import './index';
import {watcher} from '../../../helpers/watcherHelper';
describe('Client', () => {
describe('Component vnClientBillingData', () => {
@ -16,38 +17,24 @@ describe('Client', () => {
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new();
$scope.watcher = {
submit: () => {
return {
then: callback => {
callback();
}
};
}
};
$scope.watcher = watcher;
controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.client = {id: 101, name: 'Client name', payMethodFk: 4};
$scope.watcher.orgData = {id: 101, name: 'Client name', payMethodFk: 4};
}));
describe('client()', () => {
it(`should call setter client`, () => {
expect(controller.orgData).toEqual(controller.client);
});
});
describe('onSubmit()', () => {
it(`should call notifyChanges() if there are changes on payMethod data`, () => {
spyOn(controller, 'notifyChanges');
controller.client.payMethodFk = 5;
controller.onSubmit();
expect(controller.hasPaymethodChanged()).toBeTruthy();
expect(controller.notifyChanges).toHaveBeenCalledWith();
});
});
describe('notifyChanges()', () => {
it(`should call notifyChanges() and perform a GET query`, () => {
it(`should perform a GET query`, () => {
$httpBackend.when('GET', `/mailer/notification/payment-update/101`).respond(true);
$httpBackend.expect('GET', `/mailer/notification/payment-update/101`);
controller.notifyChanges();
@ -55,17 +42,17 @@ describe('Client', () => {
});
});
describe('hasPaymethodChanged()', () => {
it(`should call hasPaymethodChanged() and return true if there are changes on payMethod data`, () => {
describe('hasPaymethodChanges()', () => {
it(`should return true if there are changes on payMethod data`, () => {
controller.client.payMethodFk = 5;
expect(controller.hasPaymethodChanged()).toBeTruthy();
expect(controller.hasPaymethodChanges()).toBeTruthy();
});
it(`should call hasPaymethodChanged() and return false if there are no changes on payMethod data`, () => {
it(`should return false if there are no changes on payMethod data`, () => {
controller.client.payMethodFk = 4;
expect(controller.hasPaymethodChanged()).toBeFalsy();
expect(controller.hasPaymethodChanges()).toBeFalsy();
});
});
});

View File

@ -1,13 +1,17 @@
module.exports.watcher = {
submit: () => {
return new Promise(accept => {
accept();
});
return {
then: callback => {
callback({data: {id: 1234}});
}
};
},
realSubmit: () => {
return new Promise(accept => {
accept();
});
return {
then: callback => {
callback({data: {id: 1234}});
}
};
},
check: () => {},
notifySaved: () => {},