|
| 1 | +/** |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | + |
| 6 | +/*eslint max-nested-callbacks: 0*/ |
| 7 | +define([ |
| 8 | + 'squire' |
| 9 | +], function (Squire) { |
| 10 | + 'use strict'; |
| 11 | + |
| 12 | + describe('Magento_Checkout/js/model/error-processor', function () { |
| 13 | + var injector = new Squire(), |
| 14 | + mocks = { |
| 15 | + 'mage/url': { |
| 16 | + /** Method stub. */ |
| 17 | + build: jasmine.createSpy() |
| 18 | + }, |
| 19 | + 'Magento_Ui/js/model/messageList': jasmine.createSpy('globalList') |
| 20 | + }, |
| 21 | + model; |
| 22 | + |
| 23 | + beforeEach(function (done) { |
| 24 | + injector.mock(mocks); |
| 25 | + injector.require([ |
| 26 | + 'Magento_Checkout/js/model/error-processor' |
| 27 | + ], function (processor) { |
| 28 | + model = processor; |
| 29 | + |
| 30 | + done(); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + describe('Check process method', function () { |
| 35 | + it('check on success response with valid response data', function () { |
| 36 | + var messageObject = { |
| 37 | + message: 'Valid error message!' |
| 38 | + }, |
| 39 | + messageContainer = jasmine.createSpyObj('globalMessageList', ['addErrorMessage']); |
| 40 | + |
| 41 | + model.process({ |
| 42 | + status: 200, |
| 43 | + responseText: JSON.stringify(messageObject) |
| 44 | + }, messageContainer); |
| 45 | + expect(messageContainer.addErrorMessage).toHaveBeenCalledWith(messageObject); |
| 46 | + }); |
| 47 | + |
| 48 | + it('check on success response with invalid response data', function () { |
| 49 | + var messageContainer = jasmine.createSpyObj('globalMessageList', ['addErrorMessage']); |
| 50 | + |
| 51 | + model.process({ |
| 52 | + status: 200, |
| 53 | + responseText: '' |
| 54 | + }, messageContainer); |
| 55 | + expect(messageContainer.addErrorMessage) |
| 56 | + .toHaveBeenCalledWith('Something went wrong with your request. Please try again later.'); |
| 57 | + }); |
| 58 | + |
| 59 | + it('check on failed status', function () { |
| 60 | + var messageContainer = jasmine.createSpyObj('globalMessageList', ['addErrorMessage']); |
| 61 | + |
| 62 | + spyOn(window.location, 'replace').and.callFake(function () {}); |
| 63 | + model.process({ |
| 64 | + status: 401, |
| 65 | + responseText: '' |
| 66 | + }, messageContainer); |
| 67 | + expect(mocks['mage/url'].build) |
| 68 | + .toHaveBeenCalled(); |
| 69 | + }); |
| 70 | + }); |
| 71 | + }); |
| 72 | +}); |
0 commit comments