$httpBackend.when and .expect no longer misused
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2020-07-23 17:10:07 +02:00
parent 4ca004f833
commit 6913f2db72
27 changed files with 43 additions and 76 deletions

View File

@ -91,7 +91,7 @@ describe('claim', () => {
$httpBackend.flush();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.$.lastTicketsPopover.hide).toHaveBeenCalledWith();
});
});
@ -106,7 +106,7 @@ describe('claim', () => {
$httpBackend.flush();
expect(controller.card.reload).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});

View File

@ -80,7 +80,7 @@ describe('claim', () => {
controller.deleteClaimedSale();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
@ -91,7 +91,7 @@ describe('claim', () => {
controller.setClaimedQuantity(1, 1);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
@ -126,7 +126,7 @@ describe('claim', () => {
expect(controller.calculateTotals).toHaveBeenCalledWith();
expect(controller.clearDiscount).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.$.editPopover.hide).toHaveBeenCalledWith();
});
});

View File

@ -20,8 +20,7 @@ describe('Claim', () => {
describe('getSummary()', () => {
it('should perform a query to set summary', () => {
$httpBackend.when('GET', `Claims/1/getSummary`).respond(200, 24);
$httpBackend.expect('GET', `Claims/1/getSummary`);
$httpBackend.expect('GET', `Claims/1/getSummary`).respond(200, 24);
controller.getSummary();
$httpBackend.flush();

View File

@ -28,8 +28,7 @@ describe('Client', () => {
let data = {defaultAddressFk: address.id};
let expectedResult = {defaultAddressFk: address.id};
$httpBackend.when('PATCH', `Clients/1`, data).respond(200, expectedResult);
$httpBackend.expect('PATCH', `Clients/1`, data);
$httpBackend.expect('PATCH', `Clients/1`, data).respond(200, expectedResult);
controller.setDefault(address);
$httpBackend.flush();

View File

@ -77,8 +77,7 @@ describe('Client', () => {
it('should call the returnDialog method and perform a PATCH query, then call _getClassifications method', () => {
jest.spyOn(controller, '_getClassifications').mockReturnThis();
controller.classificationId = 1;
$httpBackend.when('PATCH', `CreditClassifications/1`).respond(200);
$httpBackend.expect('PATCH', `CreditClassifications/1`);
$httpBackend.expect('PATCH', `CreditClassifications/1`).respond(200);
controller.returnDialog('accept');
$httpBackend.flush();

View File

@ -39,8 +39,7 @@ describe('Client', () => {
where: {code: 'paymentsLaw'}
}};
let serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 12, code: 'paymentsLaw'});
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`);
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 12, code: 'paymentsLaw'});
controller.setDefaultParams();
$httpBackend.flush();
@ -63,8 +62,7 @@ describe('Client', () => {
describe('getAllowedContentTypes()', () => {
it('should make an HTTP GET request to get the allowed content types', () => {
const expectedResponse = ['image/png', 'image/jpg'];
$httpBackend.when('GET', `clientDms/allowedContentTypes`).respond(expectedResponse);
$httpBackend.expect('GET', `clientDms/allowedContentTypes`);
$httpBackend.expect('GET', `clientDms/allowedContentTypes`).respond(expectedResponse);
controller.getAllowedContentTypes();
$httpBackend.flush();

View File

@ -45,7 +45,6 @@ describe('Client', () => {
hasFileAttached: false
};
$httpBackend.when('GET', `Dms/${dmsId}`).respond(expectedResponse);
$httpBackend.expect('GET', `Dms/${dmsId}`).respond(expectedResponse);
controller.setDefaultParams();
$httpBackend.flush();
@ -70,8 +69,7 @@ describe('Client', () => {
describe('getAllowedContentTypes()', () => {
it('should make an HTTP GET request to get the allowed content types', () => {
const expectedResponse = ['image/png', 'image/jpg'];
$httpBackend.when('GET', `clientDms/allowedContentTypes`).respond(expectedResponse);
$httpBackend.expect('GET', `clientDms/allowedContentTypes`);
$httpBackend.expect('GET', `clientDms/allowedContentTypes`).respond(expectedResponse);
controller.getAllowedContentTypes();
$httpBackend.flush();

View File

@ -126,8 +126,7 @@ describe('Client', () => {
describe('onAcceptEt()', () => {
it('should request to patch the propagation of tax status', () => {
controller.client = {id: 123, isEqualizated: false};
$httpBackend.when('PATCH', `Clients/${controller.client.id}/addressesPropagateRe`, {isEqualizated: controller.client.isEqualizated}).respond('done');
$httpBackend.expectPATCH(`Clients/${controller.client.id}/addressesPropagateRe`, {isEqualizated: controller.client.isEqualizated});
$httpBackend.expectPATCH(`Clients/${controller.client.id}/addressesPropagateRe`, {isEqualizated: controller.client.isEqualizated}).respond('done');
controller.onAcceptEt();
$httpBackend.flush();
});

View File

@ -22,8 +22,7 @@ describe('Client', () => {
controller.data = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
jest.spyOn(controller.vnApp, 'showMessage');
$httpBackend.when('PATCH', `postcodes`, params).respond(200, params);
$httpBackend.expect('PATCH', `postcodes`, params).respond(params);
$httpBackend.expect('PATCH', `postcodes`, params).respond(200, params);
controller.onAccept();
$httpBackend.flush();

View File

@ -21,8 +21,7 @@ describe('Client', () => {
let res = {name: 'Superman', classifications: []};
jest.spyOn(controller, 'sumRisk').mockReturnThis();
$httpBackend.when('GET', `Clients/101/summary`).respond(200, res);
$httpBackend.expect('GET', `Clients/101/summary`);
$httpBackend.expect('GET', `Clients/101/summary`).respond(200, res);
controller.$onChanges();
$httpBackend.flush();

View File

@ -57,8 +57,7 @@ describe('Component VnClientWebAccess', () => {
expect(controller.canEnableCheckBox).toBeTruthy();
$httpBackend.when('GET', `Clients/${controller.client.id}/isValidClient`).respond(false);
$httpBackend.expectGET(`Clients/${controller.client.id}/isValidClient`);
$httpBackend.expectGET(`Clients/${controller.client.id}/isValidClient`).respond(false);
controller.checkConditions();
$httpBackend.flush();
@ -83,8 +82,7 @@ describe('Component VnClientWebAccess', () => {
controller.newPassword = 'm24x8';
controller.repeatPassword = 'm24x8';
controller.canChangePassword = true;
$httpBackend.when('PATCH', 'Accounts/1234').respond('done');
$httpBackend.expectPATCH('Accounts/1234', {password: 'm24x8'});
$httpBackend.expectPATCH('Accounts/1234', {password: 'm24x8'}).respond('done');
controller.onPassChange('accept');
$httpBackend.flush();
});

View File

@ -25,8 +25,7 @@ describe('Component vnClientWebPayment', () => {
let query = 'Clients/confirmTransaction';
controller.confirm(transaction);
$httpBackend.when('POST', query, transaction).respond('ok');
$httpBackend.expect('POST', query, transaction);
$httpBackend.expect('POST', query, transaction).respond('ok');
$httpBackend.flush();
});
});

View File

@ -19,7 +19,6 @@ describe('InvoiceOut', () => {
describe('getSummary()', () => {
it('should perform a query to set summary', () => {
$httpBackend.when('GET', `InvoiceOuts/1/summary`).respond(200, 'the data you are looking for');
$httpBackend.expect('GET', `InvoiceOuts/1/summary`);
controller.getSummary();
$httpBackend.flush();

View File

@ -19,8 +19,7 @@ describe('Item', () => {
describe('getSummary()', () => {
it('should perform a query to set summary', () => {
let data = {id: 1, name: 'Gem of mind'};
$httpBackend.when('GET', `Items/1/getSummary`).respond(200, data);
$httpBackend.expect('GET', `Items/1/getSummary`);
$httpBackend.expect('GET', `Items/1/getSummary`).respond(200, data);
controller.getSummary();
$httpBackend.flush();

View File

@ -91,12 +91,11 @@ describe('Order', () => {
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.$state, 'go');
$httpBackend.when('POST', 'Orders/new', {landed: 101, addressId: 101, agencyModeId: 101}).respond(200, 1);
$httpBackend.expect('POST', 'Orders/new', {landed: 101, addressId: 101, agencyModeId: 101});
$httpBackend.expect('POST', 'Orders/new', {landed: 101, addressId: 101, agencyModeId: 101}).respond(200, 1);
controller.createOrder();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.$state.go).toHaveBeenCalledWith('order.card.catalog', {id: 1});
});
});

View File

@ -17,7 +17,6 @@ describe('Route', () => {
describe('getSummary()', () => {
it('should perform a query to set summary', () => {
$httpBackend.when('GET', `Routes/1/summary`).respond(200, 24);
$httpBackend.expect('GET', `Routes/1/summary`);
controller.getSummary();
$httpBackend.flush();

View File

@ -101,7 +101,7 @@ describe('Route', () => {
controller.setPriority(ticketId, priority);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
});
});
@ -318,7 +318,7 @@ describe('Route', () => {
controller.insert(ticketId);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
});
});

View File

@ -251,8 +251,7 @@ describe('Ticket', () => {
};
filter = encodeURIComponent(JSON.stringify(filter));
$httpBackend.when('GET', `Clients/${clientId}/addresses?filter=${filter}`).respond(200);
$httpBackend.expect('GET', `Clients/${clientId}/addresses?filter=${filter}`);
$httpBackend.expect('GET', `Clients/${clientId}/addresses?filter=${filter}`).respond(200);
controller.clientAddressesList(clientId);
$httpBackend.flush();
});
@ -262,8 +261,7 @@ describe('Ticket', () => {
it('should return the default address from choosed client', async() => {
const clientId = 102;
$httpBackend.when('GET', `Clients/${clientId}`).respond(200);
$httpBackend.expect('GET', `Clients/${clientId}`);
$httpBackend.expect('GET', `Clients/${clientId}`).respond(200);
controller.getClientDefaultAddress(clientId);
$httpBackend.flush();
});
@ -273,8 +271,7 @@ describe('Ticket', () => {
it('should return an available zone', async() => {
const zoneId = 5;
const agencyModeFk = 8;
$httpBackend.when('GET', `Zones/${zoneId}`).respond(200, {agencyModeFk});
$httpBackend.expect('GET', `Zones/${zoneId}`);
$httpBackend.expect('GET', `Zones/${zoneId}`).respond(200, {agencyModeFk});
controller.onChangeZone(zoneId);
$httpBackend.flush();
@ -337,8 +334,7 @@ describe('Ticket', () => {
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `Agencies/getLanded?${serializedParams}`).respond(200, expectedResult);
$httpBackend.expect('GET', `Agencies/getLanded?${serializedParams}`);
$httpBackend.expect('GET', `Agencies/getLanded?${serializedParams}`).respond(200, expectedResult);
controller.getLanded(params);
$httpBackend.flush();
@ -359,8 +355,7 @@ describe('Ticket', () => {
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `Agencies/getShipped?${serializedParams}`).respond(200, expectedResult);
$httpBackend.expect('GET', `Agencies/getShipped?${serializedParams}`);
$httpBackend.expect('GET', `Agencies/getShipped?${serializedParams}`).respond(200, expectedResult);
controller.getShipped(params);
$httpBackend.flush();

View File

@ -44,8 +44,7 @@ describe('Ticket', () => {
where: {code: 'ticket'}
}};
let serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 14, code: 'ticket'});
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`);
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 14, code: 'ticket'});
controller.setDefaultParams();
$httpBackend.flush();
@ -68,8 +67,7 @@ describe('Ticket', () => {
describe('getAllowedContentTypes()', () => {
it('should make an HTTP GET request to get the allowed content types', () => {
const expectedResponse = ['image/png', 'image/jpg'];
$httpBackend.when('GET', `ticketDms/allowedContentTypes`).respond(expectedResponse);
$httpBackend.expect('GET', `ticketDms/allowedContentTypes`);
$httpBackend.expect('GET', `ticketDms/allowedContentTypes`).respond(expectedResponse);
controller.getAllowedContentTypes();
$httpBackend.flush();

View File

@ -45,7 +45,6 @@ describe('Ticket', () => {
hasFileAttached: false
};
$httpBackend.when('GET', `Dms/${dmsId}`).respond(expectedResponse);
$httpBackend.expect('GET', `Dms/${dmsId}`).respond(expectedResponse);
controller.setDefaultParams();
$httpBackend.flush();
@ -70,8 +69,7 @@ describe('Ticket', () => {
describe('getAllowedContentTypes()', () => {
it('should make an HTTP GET request to get the allowed content types', () => {
const expectedResponse = ['image/png', 'image/jpg'];
$httpBackend.when('GET', `ticketDms/allowedContentTypes`).respond(expectedResponse);
$httpBackend.expect('GET', `ticketDms/allowedContentTypes`);
$httpBackend.expect('GET', `ticketDms/allowedContentTypes`).respond(expectedResponse);
controller.getAllowedContentTypes();
$httpBackend.flush();

View File

@ -248,7 +248,7 @@ describe('Ticket', () => {
$httpBackend.flush();
expect(controller.card.reload).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.resetChanges).toHaveBeenCalledWith();
});
});
@ -267,7 +267,7 @@ describe('Ticket', () => {
$httpBackend.flush();
expect(controller.removeSelectedSales).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.resetChanges).toHaveBeenCalledWith();
});
});
@ -371,7 +371,7 @@ describe('Ticket', () => {
expect(selectedSale.price).toEqual(2);
expect(controller.refreshTotal).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.$.editPricePopover.hide).toHaveBeenCalledWith();
expect(controller.resetChanges).toHaveBeenCalledWith();
});
@ -472,7 +472,7 @@ describe('Ticket', () => {
expect(firstSelectedSale.discount).toEqual(expectedDiscount);
expect(secondSelectedSale.discount).toEqual(expectedDiscount);
expect(controller.refreshTotal).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.resetChanges).toHaveBeenCalledWith();
});
});
@ -678,7 +678,7 @@ describe('Ticket', () => {
controller.addSale(newSale);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.refreshTotal).toHaveBeenCalledWith();
expect(controller.resetChanges).toHaveBeenCalledWith();
});
@ -719,7 +719,7 @@ describe('Ticket', () => {
controller.calculateSalePrice();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.refreshTotal).toHaveBeenCalledWith();
});

View File

@ -18,7 +18,6 @@ describe('Ticket', () => {
it('should perform a GET query and define the summary property', () => {
let res = {id: 1, nickname: 'Batman'};
$httpBackend.when('GET', `Tickets/1/summary`).respond(200, res);
$httpBackend.expect('GET', `Tickets/1/summary`);
controller.ticket = {id: 1};
$httpBackend.flush();

View File

@ -23,7 +23,7 @@ describe('ticket weekly', () => {
controller.onUpdate('ticketFk', 'field', 'value');
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
@ -38,7 +38,7 @@ describe('ticket weekly', () => {
controller.onDeleteWeeklyAccept('ticketFk');
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
expect(controller.$.model.remove).toHaveBeenCalledWith(0);
});
});

View File

@ -40,8 +40,7 @@ describe('Ticket', () => {
where: {code: 'miscellaneous'}
}};
let serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: dmsTypeId, code: 'miscellaneous'});
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`);
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: dmsTypeId, code: 'miscellaneous'});
controller.setDefaultParams();
$httpBackend.flush();
@ -54,8 +53,7 @@ describe('Ticket', () => {
describe('getAllowedContentTypes()', () => {
it('should make an HTTP GET request to get the allowed content types', () => {
const expectedResponse = ['application/pdf', 'image/png', 'image/jpg'];
$httpBackend.when('GET', `TravelThermographs/allowedContentTypes`).respond(expectedResponse);
$httpBackend.expect('GET', `TravelThermographs/allowedContentTypes`);
$httpBackend.expect('GET', `TravelThermographs/allowedContentTypes`).respond(expectedResponse);
controller.getAllowedContentTypes();
$httpBackend.flush();

View File

@ -79,8 +79,7 @@ describe('Worker', () => {
describe('getAllowedContentTypes()', () => {
it('should make an HTTP GET request to get the allowed content types', () => {
const expectedResponse = ['image/png', 'image/jpg'];
$httpBackend.when('GET', `TravelThermographs/allowedContentTypes`).respond(expectedResponse);
$httpBackend.expect('GET', `TravelThermographs/allowedContentTypes`);
$httpBackend.expect('GET', `TravelThermographs/allowedContentTypes`).respond(expectedResponse);
controller.getAllowedContentTypes();
$httpBackend.flush();

View File

@ -64,8 +64,7 @@ describe('Client', () => {
describe('getAllowedContentTypes()', () => {
it('should make an HTTP GET request to get the allowed content types', () => {
const expectedResponse = ['image/png', 'image/jpg'];
$httpBackend.when('GET', `workerDms/allowedContentTypes`).respond(expectedResponse);
$httpBackend.expect('GET', `workerDms/allowedContentTypes`);
$httpBackend.expect('GET', `workerDms/allowedContentTypes`).respond(expectedResponse);
controller.getAllowedContentTypes();
$httpBackend.flush();

View File

@ -46,7 +46,6 @@ describe('Worker', () => {
hasFileAttached: false
};
$httpBackend.when('GET', `Dms/${dmsId}`).respond(expectedResponse);
$httpBackend.expect('GET', `Dms/${dmsId}`).respond(expectedResponse);
controller.setDefaultParams();
$httpBackend.flush();
@ -71,8 +70,7 @@ describe('Worker', () => {
describe('getAllowedContentTypes()', () => {
it('should make an HTTP GET request to get the allowed content types', () => {
const expectedResponse = ['image/png', 'image/jpg'];
$httpBackend.when('GET', `WorkerDms/allowedContentTypes`).respond(expectedResponse);
$httpBackend.expect('GET', `WorkerDms/allowedContentTypes`);
$httpBackend.expect('GET', `WorkerDms/allowedContentTypes`).respond(expectedResponse);
controller.getAllowedContentTypes();
$httpBackend.flush();