-
Notifications
You must be signed in to change notification settings - Fork 19
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
Showing
7 changed files
with
188 additions
and
26 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
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
This file was deleted.
Oops, something went wrong.
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,95 @@ | ||
import { shouldTriggerOnSuccess } from '../../util/api-client'; | ||
import { Transaction } from '../../util'; | ||
|
||
jest.mock('axios'); | ||
|
||
global.fetch = jest.fn(); | ||
|
||
describe('API Client Util Tests', () => { | ||
describe('shouldTriggerOnSuccess', () => { | ||
it('should return true when all conditions match', () => { | ||
const transaction:Transaction = { | ||
amount: '100.00', | ||
paymentId: '123', | ||
message: 'test message', | ||
hash: '', | ||
timestamp: 0, | ||
address: '' | ||
}; | ||
expect(shouldTriggerOnSuccess(transaction, '123', '100.00', 'test message')).toBe(true); | ||
|
||
}); | ||
|
||
it('should return false when the payment ID does not match', () => { | ||
const transaction:Transaction = { | ||
amount: '100.00', | ||
paymentId: '123', | ||
message: 'test opReturn message', | ||
hash: '', | ||
timestamp: 0, | ||
address: '' | ||
}; | ||
expect(shouldTriggerOnSuccess(transaction, '999', '100.00', 'test opReturn message')).toBe(false); | ||
}); | ||
|
||
it('should return false when crypto amounts do not match', () => { | ||
const transaction:Transaction = { | ||
amount: '101.00', | ||
paymentId: '123', | ||
message: 'test opReturn message', | ||
hash: '', | ||
timestamp: 0, | ||
address: '' | ||
}; | ||
expect(shouldTriggerOnSuccess(transaction, '123', '100.00', 'test opReturn message')).toBe(false); | ||
}); // todo - check if amount higher than the one requested is also valid | ||
|
||
it('should return false when OpReturn data does not match', () => { | ||
const transaction:Transaction = { | ||
amount: '101.00', | ||
paymentId: '123', | ||
message: 'test opReturn message', | ||
hash: '', | ||
timestamp: 0, | ||
address: '' | ||
}; | ||
expect(shouldTriggerOnSuccess(transaction, '123', '100.00', 'test opReturn')).toBe(false); | ||
}); | ||
|
||
it('should ignore amount validation when amount is not set', () => { | ||
const transaction:Transaction = { | ||
amount: '101.00', | ||
paymentId: '123', | ||
message: 'test opReturn', | ||
hash: '', | ||
timestamp: 0, | ||
address: '' | ||
}; | ||
expect(shouldTriggerOnSuccess(transaction, '123', undefined, 'test opReturn')).toBe(true); | ||
}); | ||
|
||
it('should ignore paymentId validation when paymentId does not exists', () => { | ||
const transaction:Transaction = { | ||
amount: '101.00', | ||
paymentId: '123', | ||
message: 'test opReturn', | ||
hash: '', | ||
timestamp: 0, | ||
address: '' | ||
}; | ||
expect(shouldTriggerOnSuccess(transaction, undefined, '101.00', 'test opReturn')).toBe(true); | ||
}); | ||
|
||
it('should ignore opReturn validation when opReturn does not exists', () => { | ||
const transaction:Transaction = { | ||
amount: '101.00', | ||
paymentId: '123', | ||
message: 'test opReturn', | ||
hash: '', | ||
timestamp: 0, | ||
address: '' | ||
}; | ||
expect(shouldTriggerOnSuccess(transaction, '123', '101.00', undefined)).toBe(true); | ||
}); | ||
}); | ||
}); |
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,60 @@ | ||
import { isCrypto, isValidCurrency } from '../../util'; | ||
|
||
describe('API Client Util Tests', () => { | ||
describe('isCrypto', () => { | ||
it('recognizes valid crypto currencies', () => { | ||
expect(isCrypto('BCH')).toBeTruthy(); | ||
expect(isCrypto('XEC')).toBeTruthy(); | ||
}); | ||
|
||
it('does not recognize invalid crypto currencies', () => { | ||
expect(isCrypto('BTC')).toBeFalsy(); | ||
expect(isCrypto('ETH')).toBeFalsy(); | ||
}); | ||
|
||
it('is case-sensitive', () => { | ||
expect(isCrypto('bch')).toBeFalsy(); | ||
expect(isCrypto('xec')).toBeFalsy(); | ||
}); | ||
|
||
it('returns false for empty strings', () => { | ||
expect(isCrypto('')).toBeFalsy(); | ||
}); | ||
|
||
it('handles whitespace or special characters', () => { | ||
expect(isCrypto(' BCH ')).toBeFalsy(); | ||
expect(isCrypto('BCH@')).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('isValidCurrency', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('identifies fiat currencies correctly', () => { | ||
expect(isValidCurrency('USD')).toBeTruthy(); | ||
expect(isValidCurrency('EUR')).toBeTruthy(); | ||
}); | ||
|
||
it('identifies crypto currencies correctly', () => { | ||
expect(isValidCurrency('BCH')).toBeTruthy(); | ||
expect(isValidCurrency('XEC')).toBeTruthy(); | ||
}); | ||
|
||
it('returns false for unrecognized currencies', () => { | ||
expect(isValidCurrency('XYZ')).toBeFalsy(); | ||
expect(isValidCurrency('ABC')).toBeFalsy(); | ||
}); | ||
|
||
it('is case-sensitive', () => { | ||
expect(isValidCurrency('bch')).toBeFalsy(); | ||
expect(isValidCurrency('usd')).toBeFalsy(); | ||
}); | ||
|
||
it('handles strings with spaces or special characters', () => { | ||
expect(isValidCurrency(' BCH ')).toBeFalsy(); | ||
expect(isValidCurrency('USD@')).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
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
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