UNPKG

@yoroi/api

Version:
45 lines (44 loc) 2.17 kB
"use strict"; var _frontendFees = require("./frontend-fees"); var _frontendFees2 = require("./frontend-fees.mocks"); describe('isFrontendFeesResponse', () => { it.each` desc | data | expected ${'no fees and no aggregator'} | ${_frontendFees2.mockGetFrontendFees.noFeesAndNoAggregator} | ${true} ${'with fess'} | ${_frontendFees2.mockGetFrontendFees.withFees} | ${true} ${'with unknown aggregator'} | ${_frontendFees2.mockGetFrontendFees.withUnknownAggregator} | ${false} ${'empty'} | ${_frontendFees2.mockGetFrontendFees.empty} | ${true} ${'with malformat response'} | ${_frontendFees2.mockGetFrontendFees.withdMalformatdData} | ${false} `(`should be $expected when $desc`, ({ data, expected }) => { expect((0, _frontendFees.isFrontendFeesResponse)(data)).toEqual(expected); }); }); describe('getFrontendFees', () => { it('success', async () => { const fetch = jest.fn().mockResolvedValue(_frontendFees2.mockGetFrontendFees.withFees); const ffeeTiers = (0, _frontendFees.getFrontendFees)('https://localhost', fetch); const result = await ffeeTiers(); expect(result).toEqual(_frontendFees2.mockGetFrontendFees.withFees); }); it('throws if response is not valid', async () => { const fetch = jest.fn().mockResolvedValue(_frontendFees2.mockGetFrontendFees.withdMalformatdData); const ffeeTiers = (0, _frontendFees.getFrontendFees)('https://localhost', fetch); await expect(ffeeTiers()).rejects.toThrow('Invalid frontend fee response'); }); it('throws any other error', async () => { const networkError = { error: 'network' }; const fetch = jest.fn().mockRejectedValue(networkError); const ffeeTiers = (0, _frontendFees.getFrontendFees)('https://localhost', fetch); await expect(ffeeTiers()).rejects.toEqual(networkError); }); it('no deps for coverage', () => { const ffeeTiers = (0, _frontendFees.getFrontendFees)('https://localhost'); expect(ffeeTiers).toBeDefined(); }); }); //# sourceMappingURL=frontend-fees.test.js.map