Tests
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2022-10-04 07:41:40 +02:00
parent a065d77929
commit c8bad23621
12 changed files with 49 additions and 126 deletions

View File

@ -24,12 +24,13 @@ describe('Item Component vnClaimDescriptor', () => {
window.open = jasmine.createSpy('open');
const params = {
recipientId: claim.clientFk,
claimId: claim.id
recipientId: claim.clientFk
};
controller.showPickupOrder();
expect(controller.vnReport.show).toHaveBeenCalledWith('claim-pickup-order', params);
const expectedPath = `Claims/${claim.id}/claim-pickup-pdf`;
expect(controller.vnReport.show).toHaveBeenCalledWith(expectedPath, params);
});
});
@ -39,12 +40,13 @@ describe('Item Component vnClaimDescriptor', () => {
const params = {
recipient: claim.client.email,
recipientId: claim.clientFk,
claimId: claim.id
recipientId: claim.clientFk
};
controller.sendPickupOrder();
expect(controller.vnEmail.send).toHaveBeenCalledWith('claim-pickup-order', params);
const expectedPath = `Claims/${claim.id}/claim-pickup-email`;
expect(controller.vnEmail.send).toHaveBeenCalledWith(expectedPath, params);
});
});

View File

@ -34,15 +34,16 @@ describe('Client', () => {
controller.showReport();
const clientId = controller.client.id;
const expectedParams = {
recipientId: 1101,
recipientId: clientId,
from: now,
to: now
};
const serializedParams = $httpParamSerializer(expectedParams);
const path = `api/report/campaign-metrics?${serializedParams}`;
const expectedPath = `api/Clients/${clientId}/campaign-metrics-pdf?${serializedParams}`;
expect(window.open).toHaveBeenCalledWith(path);
expect(window.open).toHaveBeenCalledWith(expectedPath);
});
});
@ -53,16 +54,10 @@ describe('Client', () => {
from: now,
to: now
};
const expectedParams = {
recipientId: 1101,
from: now,
to: now
};
const clientId = controller.client.id;
const expectedPath = `Clients/${clientId}/campaign-metrics-email`;
const serializedParams = $httpParamSerializer(expectedParams);
const path = `email/campaign-metrics?${serializedParams}`;
$httpBackend.expect('GET', path).respond({});
$httpBackend.expect('POST', expectedPath).respond({});
controller.sendEmail();
$httpBackend.flush();
});

View File

@ -85,7 +85,7 @@ export default class Controller extends Section {
this.$http.post('ClientConsumptionQueues', {params})
.then(() => this.$.filters.hide())
.then(() => this.vnApp.showSuccess(this.$t('Notifications queued')));
.then(() => this.vnApp.showSuccess(this.$t('Notifications sent!')));
}
exprBuilder(param, value) {

View File

@ -61,7 +61,6 @@ describe('Client notification', () => {
controller.$.filters = {hide: () => {}};
controller.campaign = {
id: 1,
from: new Date(),
to: new Date()
};
@ -71,10 +70,10 @@ describe('Client notification', () => {
data[1].$checked = true;
const params = Object.assign({
clientIds: [1101, 1102]
clients: [1101, 1102]
}, controller.campaign);
$httpBackend.expect('POST', `schedule/consumption`, params).respond(200, params);
$httpBackend.expect('POST', `ClientConsumptionQueues`, {params}).respond(200, params);
controller.onSendClientConsumption();
$httpBackend.flush();

View File

@ -40,58 +40,6 @@ class Controller extends Section {
this.$.watcher.realSubmit().then(() => this.send());
}
// showPreview() {
// this.send(true, res => {
// this.$.showPreview.show();
// const dialog = document.body.querySelector('div.vn-dialog');
// const body = dialog.querySelector('tpl-body');
// const scroll = dialog.querySelector('div:first-child');
// body.innerHTML = res.data;
// scroll.scrollTop = 0;
// });
// }
// sendSample() {
// this.send(false, () => {
// this.vnApp.showSuccess(this.$t('Notification sent!'));
// this.$state.go('client.card.sample.index');
// });
// }
// send(isPreview, cb) {
// const sampleType = this.$.sampleType.selection;
// const params = {
// recipientId: this.$params.id,
// recipient: this.clientSample.recipient,
// replyTo: this.clientSample.replyTo
// };
// if (!params.recipient)
// return this.vnApp.showError(this.$t('Email cannot be blank'));
// if (!sampleType)
// return this.vnApp.showError(this.$t('Choose a sample'));
// if (sampleType.hasCompany && !this.clientSample.companyFk)
// return this.vnApp.showError(this.$t('Choose a company'));
// if (sampleType.hasCompany)
// params.companyId = this.clientSample.companyFk;
// if (sampleType.datepickerEnabled && !this.clientSample.from)
// return this.vnApp.showError(this.$t('Choose a date'));
// if (sampleType.datepickerEnabled)
// params.from = this.clientSample.from;
// let query = `email/${sampleType.code}`;
// if (isPreview)
// query = `email/${sampleType.code}/preview`;
// this.$http.get(query, {params}).then(cb);
// }
validateParams(params) {
const sampleType = this.$.sampleType.selection;

View File

@ -40,6 +40,7 @@ describe('Client', () => {
$httpParamSerializer = _$httpParamSerializer_;
$element = angular.element('<vn-client-sample-create></vn-client-sample-create>');
controller = $componentController('vnClientSampleCreate', {$element, $scope});
controller.client = {id: 1101};
const element = document.createElement('div');
document.body.querySelector = () => {
return {
@ -51,11 +52,11 @@ describe('Client', () => {
}));
describe('onSubmit()', () => {
it(`should call sendSample() method`, () => {
jest.spyOn(controller, 'sendSample');
it(`should call send() method`, () => {
jest.spyOn(controller, 'send');
controller.onSubmit();
expect(controller.sendSample).toHaveBeenCalledWith();
expect(controller.send).toHaveBeenCalledWith();
});
});
@ -65,7 +66,8 @@ describe('Client', () => {
controller.$.sampleType.selection = {
hasCompany: false,
code: 'MyReport'
code: 'MyReport',
model: 'Clients'
};
controller.clientSample = {
recipientId: 1101

View File

@ -17,13 +17,10 @@ describe('Entry Component vnEntryDescriptor', () => {
jest.spyOn(controller.vnReport, 'show');
window.open = jasmine.createSpy('open');
const params = {
clientId: controller.vnConfig.storage.currentUserWorkerId,
entryId: entry.id
};
controller.showEntryReport();
const expectedPath = `Entries/${entry.id}/entry-order-pdf`;
expect(controller.vnReport.show).toHaveBeenCalledWith('entry-order', params);
expect(controller.vnReport.show).toHaveBeenCalledWith(expectedPath);
});
});

View File

@ -41,11 +41,10 @@ describe('vnInvoiceOutDescriptorMenu', () => {
jest.spyOn(window, 'open').mockReturnThis();
const expectedParams = {
recipientId: invoiceOut.client.id,
refFk: invoiceOut.ref
recipientId: invoiceOut.client.id
};
const serializedParams = $httpParamSerializer(expectedParams);
const expectedPath = `api/csv/invoice/download?${serializedParams}`;
const expectedPath = `api/InvoiceOuts/${invoiceOut.ref}/invoice-csv?${serializedParams}`;
controller.showCsvInvoice();
expect(window.open).toHaveBeenCalledWith(expectedPath);
@ -84,14 +83,8 @@ describe('vnInvoiceOutDescriptorMenu', () => {
jest.spyOn(controller.vnApp, 'showMessage');
const $data = {email: 'brucebanner@gothamcity.com'};
const expectedParams = {
recipient: $data.email,
recipientId: invoiceOut.client.id,
refFk: invoiceOut.ref
};
const serializedParams = $httpParamSerializer(expectedParams);
$httpBackend.expectGET(`email/invoice?${serializedParams}`).respond();
$httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.ref}/invoice-email`).respond();
controller.sendPdfInvoice($data);
$httpBackend.flush();
@ -104,14 +97,8 @@ describe('vnInvoiceOutDescriptorMenu', () => {
jest.spyOn(controller.vnApp, 'showMessage');
const $data = {email: 'brucebanner@gothamcity.com'};
const expectedParams = {
recipient: $data.email,
recipientId: invoiceOut.client.id,
refFk: invoiceOut.ref
};
const serializedParams = $httpParamSerializer(expectedParams);
$httpBackend.expectGET(`csv/invoice/send?${serializedParams}`).respond();
$httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.ref}/invoice-csv-email`).respond();
controller.sendCsvInvoice($data);
$httpBackend.flush();

View File

@ -42,7 +42,7 @@ describe('Supplier', () => {
to: now
};
const serializedParams = $httpParamSerializer(expectedParams);
const path = `api/report/supplier-campaign-metrics?${serializedParams}`;
const path = `api/Suppliers/${supplierId}/campaign-metrics-pdf?${serializedParams}`;
expect(window.open).toHaveBeenCalledWith(path);
});
@ -66,7 +66,8 @@ describe('Supplier', () => {
controller.sendEmail();
$httpBackend.flush();
expect(controller.vnApp.showError).toHaveBeenCalledWith(`This supplier doesn't have a contact with an email address`);
expect(controller.vnApp.showError)
.toHaveBeenCalledWith(`This supplier doesn't have a contact with an email address`);
});
it('should make a GET query sending the report', () => {
@ -91,16 +92,15 @@ describe('Supplier', () => {
to: now
};
const expectedParams = {
recipientId: 2,
recipient: 'batman@gothamcity.com',
from: now,
to: now
};
serializedParams = $httpParamSerializer(expectedParams);
const path = `email/supplier-campaign-metrics?${serializedParams}`;
const path = `Suppliers/${supplierId}/campaign-metrics-email`;
$httpBackend.expect('GET', path).respond({});
$httpBackend.expect('POST', path).respond({});
controller.sendEmail();
$httpBackend.flush();
});

View File

@ -124,12 +124,11 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
jest.spyOn(window, 'open').mockReturnThis();
const type = 'deliveryNote';
const expectedParams = {
ticketId: ticket.id,
recipientId: ticket.client.id,
type: type
};
const serializedParams = $httpParamSerializer(expectedParams);
const expectedPath = `api/report/delivery-note?${serializedParams}`;
const expectedPath = `api/tickets/${ticket.id}/delivery-note-pdf?${serializedParams}`;
controller.showPdfDeliveryNote(type);
expect(window.open).toHaveBeenCalledWith(expectedPath);
@ -143,12 +142,13 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
const $data = {email: 'brucebanner@gothamcity.com'};
const params = {
recipient: $data.email,
recipientId: ticket.client.id,
ticketId: ticket.id
recipientId: ticket.client.id
};
controller.sendPdfDeliveryNote($data);
expect(controller.vnEmail.send).toHaveBeenCalledWith('delivery-note', params);
const expectedPath = `tickets/${ticket.id}/delivery-note-email`;
expect(controller.vnEmail.send).toHaveBeenCalledWith(expectedPath, params);
});
});
@ -157,11 +157,10 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
jest.spyOn(window, 'open').mockReturnThis();
const expectedParams = {
ticketId: ticket.id,
recipientId: ticket.client.id
};
const serializedParams = $httpParamSerializer(expectedParams);
const expectedPath = `api/csv/delivery-note/download?${serializedParams}`;
const expectedPath = `api/tickets/${ticket.id}/delivery-note-csv?${serializedParams}`;
controller.showCsvDeliveryNote();
expect(window.open).toHaveBeenCalledWith(expectedPath);
@ -170,21 +169,18 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
describe('sendCsvDeliveryNote()', () => {
it('should make a query to the csv delivery-note send endpoint and show a message snackbar', () => {
jest.spyOn(controller.vnApp, 'showMessage');
jest.spyOn(controller.vnEmail, 'send');
const $data = {email: 'brucebanner@gothamcity.com'};
const expectedParams = {
ticketId: ticket.id,
recipient: $data.email,
recipientId: ticket.client.id,
};
const serializedParams = $httpParamSerializer(expectedParams);
$httpBackend.expectGET(`csv/delivery-note/send?${serializedParams}`).respond();
controller.sendCsvDeliveryNote($data);
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalled();
const expectedPath = `tickets/${ticket.id}/delivery-note-csv-email`;
expect(controller.vnEmail.send).toHaveBeenCalledWith(expectedPath, expectedParams);
});
});

View File

@ -29,11 +29,8 @@ export default class Controller extends Section {
}
openDeliveryNotes(ids) {
for (let id of ids) {
this.vnReport.show('delivery-note', {
ticketId: id,
});
}
for (let id of ids)
this.vnReport.show(`Tickets/${id}/delivery-note-pdf`);
}
openBalanceDialog() {

View File

@ -96,8 +96,8 @@ describe('Component vnTicketIndex', () => {
controller.setDelivered();
$httpBackend.flush();
expect($window.open).toHaveBeenCalledWith(`api/report/delivery-note?ticketId=${tickets[1].id}`);
expect($window.open).toHaveBeenCalledWith(`api/report/delivery-note?ticketId=${tickets[2].id}`);
expect($window.open).toHaveBeenCalledWith(`Tickets/${tickets[1].id}/delivery-note-pdf`);
expect($window.open).toHaveBeenCalledWith(`Tickets/${tickets[2].id}/delivery-note-pdf`);
});
});