Skip to content

Commit

Permalink
chore: init deezy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
topether21 committed Dec 11, 2023
1 parent 6bdc48f commit 7b39f70
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
54 changes: 54 additions & 0 deletions __tests__/commands.js
Original file line number Diff line number Diff line change
@@ -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("");
});
});
59 changes: 59 additions & 0 deletions __tests__/deezy.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 7b39f70

Please sign in to comment.