|
| 1 | +/** |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | + |
| 6 | +define([ |
| 7 | + 'squire', |
| 8 | + 'ko' |
| 9 | +], function (Squire, ko) { |
| 10 | + 'use strict'; |
| 11 | + |
| 12 | + let injector = new Squire(), |
| 13 | + paymentService, |
| 14 | + methods = [ |
| 15 | + {title: 'Credit Card', method: 'credit_card'}, |
| 16 | + {title: 'Stored Cards', method: 'credit_card_vault'} |
| 17 | + ], |
| 18 | + mocksPaymentMethodCheckmo = { |
| 19 | + 'Magento_Checkout/js/model/quote': { |
| 20 | + paymentMethod: ko.observable({ |
| 21 | + 'method': 'checkmo' |
| 22 | + }) |
| 23 | + } |
| 24 | + }, |
| 25 | + mocksPaymentMethodVault = { |
| 26 | + 'Magento_Checkout/js/model/quote': { |
| 27 | + paymentMethod: ko.observable({ |
| 28 | + 'method': 'credit_card_vault_1' |
| 29 | + }) |
| 30 | + } |
| 31 | + }; |
| 32 | + |
| 33 | + beforeEach(function (done) { |
| 34 | + window.checkoutConfig = { |
| 35 | + vault: { |
| 36 | + credit_card_vault: {} |
| 37 | + }, |
| 38 | + payment: { |
| 39 | + vault: { |
| 40 | + credit_card_vault_1: {}, |
| 41 | + credit_card_vault_2: {} |
| 42 | + } |
| 43 | + } |
| 44 | + }; |
| 45 | + done(); |
| 46 | + }); |
| 47 | + |
| 48 | + afterEach(function () { |
| 49 | + try { |
| 50 | + injector.remove(); |
| 51 | + injector.clean(); |
| 52 | + } catch (e) {} |
| 53 | + }); |
| 54 | + |
| 55 | + describe('Magento_Checkout/js/model/payment-service', function () { |
| 56 | + beforeEach(function (done) { |
| 57 | + injector.mock(mocksPaymentMethodCheckmo); |
| 58 | + // eslint-disable-next-line max-nested-callbacks |
| 59 | + injector.require(['Magento_Checkout/js/model/payment-service'], function (instance) { |
| 60 | + paymentService = instance; |
| 61 | + done(); |
| 62 | + }); |
| 63 | + }); |
| 64 | + it('payment method is not enabled', function () { |
| 65 | + paymentService.setPaymentMethods(methods); |
| 66 | + expect(mocksPaymentMethodCheckmo['Magento_Checkout/js/model/quote'].paymentMethod()).toBeNull(); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + describe('Magento_Checkout/js/model/payment-service', function () { |
| 71 | + beforeEach(function (done) { |
| 72 | + injector.mock(mocksPaymentMethodVault); |
| 73 | + // eslint-disable-next-line max-nested-callbacks |
| 74 | + injector.require(['Magento_Checkout/js/model/payment-service'], function (instance) { |
| 75 | + paymentService = instance; |
| 76 | + done(); |
| 77 | + }); |
| 78 | + }); |
| 79 | + it('payment method is stored credit card', function () { |
| 80 | + paymentService.setPaymentMethods(methods); |
| 81 | + expect(mocksPaymentMethodVault['Magento_Checkout/js/model/quote'].paymentMethod().method) |
| 82 | + .toEqual('credit_card_vault_1'); |
| 83 | + }); |
| 84 | + }); |
| 85 | +}); |
0 commit comments