import { IAuthorize, ICreate } from '../../src/interfaces/commun' import { is, isNil, merge } from 'ramda' import Nock from 'nock' import { PAYMENT_API_URL } from '../../src/lib/constants' import { PaymentAPI } from '../../src/apis/payment' import { Utils } from '@oyst/utils' const { removeUndefinedKeys } = Utils export class MockPaymentAPI { private _fixture: Object = null private _code: number = 200 private endpoint: string = null constructor (init: any = {}) { this.endpoint = PAYMENT_API_URL } public fixture (value: Object | string) { this._fixture = is(String, value) ? JSON.parse(value as string) : value return this } public success (code?: number): MockPaymentAPI { this._code = code ? code : 200 return this } public fail (code?: number): MockPaymentAPI { this._code = code ? code : 500 return this } public authorize (merchantID: string, opts: IAuthorize): Promise { return new Promise((resolve, reject) => { Nock(this.endpoint) .filteringRequestBody(_ => '*') .post(`/merchants/${merchantID}/payments/authorise`, '*').reply(this._code, this._fixture) resolve() }) } public addCard (opts: Object): Promise { return new Promise((resolve, reject) => { Nock(this.endpoint) .filteringRequestBody(_ => '*') .post(`/cards`, '*').reply(this._code, this._fixture) resolve() }) } public create (merchantID: string, opts: ICreate): Promise { return new Promise((resolve, reject) => { Nock(this.endpoint) .filteringRequestBody(_ => '*') .post(`/merchants/${merchantID}/payments`, '*').reply(this._code, this._fixture) resolve() }) } } export default MockPaymentAPI