// @ts-nocheck import { expect } from 'chai'; import * as sinon from 'sinon'; import { PaymentMethod } from '../../src/payment-method'; import { TestConfiguration } from '../../src/configuration'; import { PaymentMethodResponse } from '../../src/types/payment-method'; describe('Print fulfilment SDK', () => { const createTestPaymentMethodKey = 'secret'; const membershipApi = 'https://url'; let sandbox: any; let instance: PaymentMethod; let config; beforeEach(() => { sandbox = sinon.createSandbox(); config = new TestConfiguration({ createTestPaymentMethodKey, membershipApi, originSystemId: 'n-membership-sdk test', }); instance = new PaymentMethod(config); sandbox.stub(instance, 'requestPost').resolves({}); }); afterEach(() => { sandbox.restore(); }); it('throws an error when host and key configuration properties do not exist', () => { try { new PaymentMethod({} as any); expect.fail('It should throw'); } catch (error) { } }); describe('createTestPaymentMethod', () => { const mockResponse: PaymentMethodResponse = { id: '123', success: true, }; it('should pass parameters to requestPost', async () => { instance.requestPost.resolves(mockResponse); const url = `${membershipApi}/v1/payment-methods/`; await instance.createTestPaymentMethod(); const getParams = instance.requestPost.getCall(0).args[0]; // Path checks expect(getParams).to.have.property('url'); expect(getParams.url).to.equal(url); // Key checks expect(getParams).to.have.property('key'); expect(getParams.key).to.equal(createTestPaymentMethodKey); }); context('when no errors are returned', () => { beforeEach(() => { instance.requestPost.resolves(mockResponse); }); it('returns the a expected response', async () => { const data = await instance.createTestPaymentMethod(); expect(data).to.equal(mockResponse); }); }); context('when an error is thrown', () => { const errorResponse = new Error('Test failure'); beforeEach(() => { instance.requestPost.rejects(errorResponse); }); it('it throws the same error', async () => { try { await instance.createTestPaymentMethod(); expect.fail('Should have thrown the error!'); } catch (error) { expect(error).to.deep.equal(errorResponse); } }); }); }); });