diff --git a/__tests__/commands.js b/__tests__/commands.js new file mode 100644 index 0000000..c0af6aa --- /dev/null +++ b/__tests__/commands.js @@ -0,0 +1,54 @@ +const { get_payment_details } = require('./../commands'); +const { get_user_limits } = require('./../deezy'); +const { satoshi_to_BTC } = require('./../utils'); + +jest.mock('./../deezy'); +jest.mock('./../utils'); + +describe('get_payment_details', () => { + it('should return payment details', async () => { + get_user_limits.mockResolvedValue({ + payment_address: 'test_address', + amount: '100', + days: '30', + subscription_cost: '200', + one_time_cost: '300', + user_volume: '400', + }); + + satoshi_to_BTC.mockImplementation((value) => value); + + const result = await get_payment_details(); + + expect(result).toEqual({ + payment_details: ` +Your current limits and payment info: + +BTC Volume Permitted Every 30 Days: 100. +Subscription Cost: 200. +Cost to purchase 1 additional BTC in scan volume: 300 satoshis. +You have scanned 400 BTC so far this billing period. +Payment Address: +`, + payment_address: 'test_address', + }); + }); + + + it('should return empty string when payment_address is empty', async () => { + get_user_limits.mockResolvedValue({ + payment_address: '...', + amount: '100', + days: '30', + subscription_cost: '200', + one_time_cost: '300', + user_volume: '400', + }); + + satoshi_to_BTC.mockImplementation((value) => value); + + const result = await get_payment_details(); + + expect(result).toBe(""); + }); +}); \ No newline at end of file diff --git a/__tests__/deezy.js b/__tests__/deezy.js new file mode 100644 index 0000000..c2fb36f --- /dev/null +++ b/__tests__/deezy.js @@ -0,0 +1,59 @@ +const axios = require('axios'); +const deezy = require('./../deezy'); +jest.mock('axios'); + +describe('deezy', () => { + + beforeEach(() => { + process.env.DEEZY_API_KEY = "00000000000000000000000000000000" + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + it('should throw an error when DEEZY_API_KEY is not set', async () => { + delete process.env.DEEZY_API_KEY; + + await expect(deezy.post_scan_request({ utxo: 'mockUtxo' })).rejects.toThrow('DEEZY_API_KEY must be set'); + await expect(deezy.get_scan_request({ scan_request_id: 'mockId' })).rejects.toThrow('DEEZY_API_KEY must be set'); + await expect(deezy.get_user_limits()).rejects.toThrow('DEEZY_API_KEY must be set'); + }); + + it('should throw an error when RARE_SAT_ADDRESS is not set', async () => { + delete process.env.RARE_SAT_ADDRESS; + + await expect(deezy.post_scan_request({ utxo: 'mockUtxo' })).rejects.toThrow('RARE_SAT_ADDRESS must be set'); + }); + + it('should post a scan request', async () => { + process.env.RARE_SAT_ADDRESS = "bc1qknfqya5asgwgkl5de36wqvcg65vsrvvs3x0fy0" + const mockResponse = { data: 'mockData' }; + axios.post.mockResolvedValue(mockResponse); + + const result = await deezy.post_scan_request({ utxo: 'mockUtxo' }); + + expect(axios.post).toHaveBeenCalled(); + expect(result).toEqual(mockResponse.data); + }); + + it('should get a scan request', async () => { + const mockResponse = { data: 'mockData' }; + axios.get.mockResolvedValue(mockResponse); + + const result = await deezy.get_scan_request({ scan_request_id: 'mockId' }); + + expect(axios.get).toHaveBeenCalled(); + expect(result).toEqual(mockResponse.data); + }); + + it('should get user limits', async () => { + const mockResponse = { data: 'mockData' }; + axios.get.mockResolvedValue(mockResponse); + + const result = await deezy.get_user_limits(); + + expect(axios.get).toHaveBeenCalled(); + expect(result).toEqual(mockResponse.data); + }); +}); \ No newline at end of file