Fixed mail notification bug #587
This commit is contained in:
parent
dff78922a1
commit
f878751ff1
|
@ -8,20 +8,14 @@ export default class Controller {
|
||||||
this.translate = $translate;
|
this.translate = $translate;
|
||||||
}
|
}
|
||||||
|
|
||||||
set client(value) {
|
|
||||||
this._client = value;
|
|
||||||
|
|
||||||
if (value)
|
|
||||||
this.orgData = Object.assign({}, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
get client() {
|
|
||||||
return this._client;
|
|
||||||
}
|
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
|
let shouldNotify = false;
|
||||||
|
|
||||||
|
if (this.hasPaymethodChanges())
|
||||||
|
shouldNotify = true;
|
||||||
|
|
||||||
this.$scope.watcher.submit().then(() => {
|
this.$scope.watcher.submit().then(() => {
|
||||||
if (this.hasPaymethodChanged())
|
if (shouldNotify)
|
||||||
this.notifyChanges();
|
this.notifyChanges();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -32,10 +26,12 @@ export default class Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
hasPaymethodChanged() {
|
hasPaymethodChanges() {
|
||||||
let payMethod = this.orgData.payMethodFk != this.client.payMethodFk;
|
let orgData = this.$scope.watcher.orgData;
|
||||||
let iban = this.orgData.iban != this.client.iban;
|
|
||||||
let dueDay = this.orgData.dueDay != this.client.dueDay;
|
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;
|
return payMethod || iban || dueDay;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import './index';
|
import './index';
|
||||||
|
import {watcher} from '../../../helpers/watcherHelper';
|
||||||
|
|
||||||
describe('Client', () => {
|
describe('Client', () => {
|
||||||
describe('Component vnClientBillingData', () => {
|
describe('Component vnClientBillingData', () => {
|
||||||
|
@ -16,38 +17,24 @@ describe('Client', () => {
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
$scope.watcher = {
|
$scope.watcher = watcher;
|
||||||
submit: () => {
|
|
||||||
return {
|
|
||||||
then: callback => {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
controller = $componentController('vnClientBillingData', {$scope: $scope});
|
controller = $componentController('vnClientBillingData', {$scope: $scope});
|
||||||
controller.client = {id: 101, name: 'Client name', payMethodFk: 4};
|
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()', () => {
|
describe('onSubmit()', () => {
|
||||||
it(`should call notifyChanges() if there are changes on payMethod data`, () => {
|
it(`should call notifyChanges() if there are changes on payMethod data`, () => {
|
||||||
spyOn(controller, 'notifyChanges');
|
spyOn(controller, 'notifyChanges');
|
||||||
controller.client.payMethodFk = 5;
|
controller.client.payMethodFk = 5;
|
||||||
controller.onSubmit();
|
controller.onSubmit();
|
||||||
|
|
||||||
expect(controller.hasPaymethodChanged()).toBeTruthy();
|
|
||||||
expect(controller.notifyChanges).toHaveBeenCalledWith();
|
expect(controller.notifyChanges).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('notifyChanges()', () => {
|
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.when('GET', `/mailer/notification/payment-update/101`).respond(true);
|
||||||
$httpBackend.expect('GET', `/mailer/notification/payment-update/101`);
|
$httpBackend.expect('GET', `/mailer/notification/payment-update/101`);
|
||||||
controller.notifyChanges();
|
controller.notifyChanges();
|
||||||
|
@ -55,17 +42,17 @@ describe('Client', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('hasPaymethodChanged()', () => {
|
describe('hasPaymethodChanges()', () => {
|
||||||
it(`should call hasPaymethodChanged() and return true if there are changes on payMethod data`, () => {
|
it(`should return true if there are changes on payMethod data`, () => {
|
||||||
controller.client.payMethodFk = 5;
|
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;
|
controller.client.payMethodFk = 4;
|
||||||
|
|
||||||
expect(controller.hasPaymethodChanged()).toBeFalsy();
|
expect(controller.hasPaymethodChanges()).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
module.exports.watcher = {
|
module.exports.watcher = {
|
||||||
submit: () => {
|
submit: () => {
|
||||||
return new Promise(accept => {
|
return {
|
||||||
accept();
|
then: callback => {
|
||||||
});
|
callback({data: {id: 1234}});
|
||||||
|
}
|
||||||
|
};
|
||||||
},
|
},
|
||||||
realSubmit: () => {
|
realSubmit: () => {
|
||||||
return new Promise(accept => {
|
return {
|
||||||
accept();
|
then: callback => {
|
||||||
});
|
callback({data: {id: 1234}});
|
||||||
|
}
|
||||||
|
};
|
||||||
},
|
},
|
||||||
check: () => {},
|
check: () => {},
|
||||||
notifySaved: () => {},
|
notifySaved: () => {},
|
||||||
|
|
Loading…
Reference in New Issue