import * as Querystring from 'querystring' import { CatalogAPI, IfindReference } from '../../src/apis/catalog' import { is, isNil, merge } from 'ramda' import { CATALOG_API_URL } from '../../src/lib/constants' import Merchant from '../../src/models/merchant' import Nock from 'nock' import { removeUndefinedKeys } from '@oyst/utils/lib/utils' export class MockCatalogAPI { private _fixture: Object = null private _code: number = 200 private endpoint: string = null constructor (init: any = {}) { this.endpoint = `${CATALOG_API_URL}/v1` } public fixture (value: Object | string) { this._fixture = is(String, value) ? JSON.parse(value as string) : value return this } public success (code?: number): MockCatalogAPI { this._code = code ? code : 200 return this } public fail (code?: number): MockCatalogAPI { this._code = code ? code : 500 return this } public findByReferences (opts: IfindReference): Promise { return new Promise((resolve, reject) => { Nock(this.endpoint) .persist() .get(`/merchants/${opts.merchant_id}/products/search`) .query({ product_reference: opts.product_reference, variation_reference: opts.variation_reference }) .reply(this._code, this._fixture) resolve(this._fixture) }) } public findShipments (merchantId: string): Promise { return new Promise((resolve, reject) => { Nock(this.endpoint) .persist() .get(`/merchants/${merchantId}/shipments`) .reply(this._code, this._fixture) resolve(this._fixture) }) } } export default MockCatalogAPI