import { describe, it, expect, beforeEach } from 'vitest'; import * as mockBlockcypherResponse from '../mocks/mockBlockcypherResponse.json'; import { explorerApi } from '../../../src/explorers/bitcoin/blockcypher'; function getMockBlockcypherResponse (): typeof mockBlockcypherResponse { return JSON.parse(JSON.stringify(mockBlockcypherResponse)); } describe('Blockcypher Bitcoin Explorer test suite', function () { let mockResponse; beforeEach(function () { mockResponse = getMockBlockcypherResponse(); }); describe('given the transaction has enough confirmations', function () { const assertionTransactionData = { issuingAddress: '1AwdUWQzJgfDDjeKtpPzMfYMHejFBrxZfo', remoteHash: 'b2ceea1d52627b6ed8d919ad1039eca32f6e099ef4a357cbb7f7361c471ea6c8', revokedAddresses: ['1AwdUWQzJgfDDjeKtpPzMfYMHejFBrxZfo'], time: new Date('2018-02-08T00:23:03.358Z') }; it('should return the transaction data', function () { expect(explorerApi.parsingFunction({ jsonResponse: mockResponse })).toEqual(assertionTransactionData); }); }); describe('given the transaction does not have enough confirmations yet', function () { it('should throw the right error', async function () { mockResponse.confirmations = 0; await expect(async () => { await explorerApi.parsingFunction({ jsonResponse: mockResponse }); }).rejects.toThrowError('Number of transaction confirmations were less than the minimum required, according to Blockcypher API'); }); }); });