/** * @jest-environment jsdom */ import LiFi from '.' import Mpc from '../../../mpc' import portalMock from '../../../__mocks/portal/portal' import { mockHost, mockLifiGetRoutesRequest, mockLifiGetRoutesResponse, mockLifiGetQuoteRequest, mockLifiGetQuoteResponse, mockLifiGetStatusRequest, mockLifiGetStatusResponse, mockLifiGetRouteStepRequest, mockLifiGetRouteStepResponse, } from '../../../__mocks/constants' describe('LiFi', () => { let lifi: LiFi let mpc: Mpc beforeEach(() => { jest.clearAllMocks() portalMock.host = mockHost mpc = new Mpc({ portal: portalMock, }) lifi = new LiFi({ mpc }) }) describe('getRoutes', () => { it('should call mpc.getLifiRoutes with the correct arguments', async () => { const spy = jest .spyOn(mpc, 'getLifiRoutes') .mockResolvedValue(mockLifiGetRoutesResponse) const result = await lifi.getRoutes(mockLifiGetRoutesRequest) expect(spy).toHaveBeenCalledWith(mockLifiGetRoutesRequest) expect(result).toEqual(mockLifiGetRoutesResponse) }) it('should propagate errors from mpc.getLifiRoutes', async () => { const error = new Error('Test error') jest.spyOn(mpc, 'getLifiRoutes').mockRejectedValue(error) await expect(lifi.getRoutes(mockLifiGetRoutesRequest)).rejects.toThrow( 'Test error', ) }) }) describe('getQuote', () => { it('should call mpc.getLifiQuote with the correct arguments', async () => { const spy = jest .spyOn(mpc, 'getLifiQuote') .mockResolvedValue(mockLifiGetQuoteResponse) const result = await lifi.getQuote(mockLifiGetQuoteRequest) expect(spy).toHaveBeenCalledWith(mockLifiGetQuoteRequest) expect(result).toEqual(mockLifiGetQuoteResponse) }) it('should propagate errors from mpc.getLifiQuote', async () => { const error = new Error('Test error') jest.spyOn(mpc, 'getLifiQuote').mockRejectedValue(error) await expect(lifi.getQuote(mockLifiGetQuoteRequest)).rejects.toThrow( 'Test error', ) }) }) describe('getStatus', () => { it('should call mpc.getLifiStatus with the correct arguments', async () => { const spy = jest .spyOn(mpc, 'getLifiStatus') .mockResolvedValue(mockLifiGetStatusResponse) const result = await lifi.getStatus(mockLifiGetStatusRequest) expect(spy).toHaveBeenCalledWith(mockLifiGetStatusRequest) expect(result).toEqual(mockLifiGetStatusResponse) }) it('should propagate errors from mpc.getLifiStatus', async () => { const error = new Error('Test error') jest.spyOn(mpc, 'getLifiStatus').mockRejectedValue(error) await expect(lifi.getStatus(mockLifiGetStatusRequest)).rejects.toThrow( 'Test error', ) }) }) describe('getRouteStep', () => { it('should call mpc.getLifiRouteStep with the correct arguments', async () => { const spy = jest .spyOn(mpc, 'getLifiRouteStep') .mockResolvedValue(mockLifiGetRouteStepResponse) const result = await lifi.getRouteStep(mockLifiGetRouteStepRequest) expect(spy).toHaveBeenCalledWith(mockLifiGetRouteStepRequest) expect(result).toEqual(mockLifiGetRouteStepResponse) }) it('should propagate errors from mpc.getLifiRouteStep', async () => { const error = new Error('Test error') jest.spyOn(mpc, 'getLifiRouteStep').mockRejectedValue(error) await expect( lifi.getRouteStep(mockLifiGetRouteStepRequest), ).rejects.toThrow('Test error') }) }) })