import { USER_API_URL as url } from '../../src/lib/constants' import { is, isNil, merge } from 'ramda' import Nock from 'nock' import { Utils } from '@oyst/utils' import user from '../../__fixtures__/user' const { removeUndefinedKeys } = Utils export class MockUserAPI { private _fixture: Object = null private _code: number = 200 public fixture (value: Object | string) { this._fixture = is(String, value) ? JSON.parse(value as string) : value return this } public success (code?: number): MockUserAPI { this._code = code ? code : 200 return this } public fail (code?: number): MockUserAPI { this._code = code ? code : 500 return this } public create (opts: Object): Promise { return new Promise((resolve, reject) => { Nock(url) .filteringRequestBody(_ => '*') .post(`/users`, '*').reply(this._code, this._fixture) resolve() }) } public find (userID: string): Promise { return Nock(url).get(`/users/${userID}`).reply(this._code, this._fixture) } public setPrimaryCard (userId: string, cardId: string) { return Nock(url) .post(`/users/${userId}/cards/${cardId}/set_primary`) .reply(this._code, this._fixture) } } export default MockUserAPI