UNPKG

wayforpay-ts-integration

Version:

Library for forms to go to the Wayforpay payment page.

66 lines (65 loc) 2.49 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const __1 = require(".."); const messages_1 = require("../messages"); const test_merchant_1 = __importDefault(require("./test-merchant")); describe('Wayforpay.purchase', () => { let wayforpay; beforeEach(() => { wayforpay = new __1.Wayforpay(test_merchant_1.default); }); it('should throw an error if merchantSecret is not specified', async () => { const instanceWithoutSecret = new __1.Wayforpay({ merchantLogin: 'testMerchant', merchantSecret: undefined, }); await expect(instanceWithoutSecret.purchase([])).rejects.toThrowError(messages_1.secretSpecifiedError); }); it('should generate a valid HTML form for the purchase', async () => { const cart = [ { product: { name: 'Product 1', price: 100 }, quantity: 2, }, { product: { name: 'Product "2"', price: 200 }, quantity: 1, }, ]; const form = await wayforpay.purchase(cart, { domain: 'example.com', currency: 'UAH' }); console.log('Purchase form:\n', form); expect(typeof form).toBe('string'); }); it('should include additional fields passed in the data parameter', async () => { const cart = [ { product: { name: 'Product 1', price: 50 }, quantity: 3, }, ]; const form = await wayforpay.purchase(cart, { domain: 'example.com', currency: 'USD', deliveryList: ['nova', 'other'], }); expect(form).toContain('<input type="hidden" name="deliveryList" value="nova;other" />'); }); it('should calculate the correct total price', async () => { const cart = [ { product: { name: 'Product 1', price: 50 }, quantity: 3, }, { product: { name: 'Product 2', price: 30 }, quantity: 2, }, ]; const form = await wayforpay.purchase(cart, { domain: 'example.com', currency: 'USD' }); // 50*3 + 30*2 = 150 + 60 = 210 expect(form).toContain('<input type="hidden" name="amount" value="210" />'); }); });