amount.test.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const { loadFixture } = require('./utils')
  2. const { coreTypes } = require('../dist/types')
  3. const { Amount } = coreTypes
  4. const fixtures = loadFixture('data-driven-tests.json')
  5. function amountErrorTests() {
  6. fixtures.values_tests
  7. .filter((obj) => obj.type === 'Amount')
  8. .forEach((f) => {
  9. // We only want these with errors
  10. if (!f.error) {
  11. return
  12. }
  13. const testName =
  14. `${JSON.stringify(f.test_json)}\n\tis invalid ` + `because: ${f.error}`
  15. it(testName, () => {
  16. expect(() => {
  17. Amount.from(f.test_json)
  18. JSON.stringify(f.test_json)
  19. }).toThrow()
  20. })
  21. })
  22. }
  23. describe('Amount', function () {
  24. it('can be parsed from', function () {
  25. expect(Amount.from('1000000') instanceof Amount).toBe(true)
  26. expect(Amount.from('1000000').toJSON()).toEqual('1000000')
  27. const fixture = {
  28. value: '1',
  29. issuer: '0000000000000000000000000000000000000000',
  30. currency: 'USD',
  31. }
  32. const amt = Amount.from(fixture)
  33. const rewritten = {
  34. value: '1',
  35. issuer: 'rrrrrrrrrrrrrrrrrrrrrhoLvTp',
  36. currency: 'USD',
  37. }
  38. expect(amt.toJSON()).toEqual(rewritten)
  39. })
  40. amountErrorTests()
  41. })