-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bdc48f
commit 7b39f70
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(""); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |