Skip to content

Conversation

@IViol
Copy link
Contributor

@IViol IViol commented Nov 8, 2019

No description provided.

@IViol IViol requested a review from stcherenkov November 8, 2019 08:57
@IViol IViol changed the title Add tests for merge assets function JWWEB-687 Add tests for merge assets function Nov 8, 2019
Copy link
Contributor

@stcherenkov stcherenkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! But it needs some improvements.

@@ -0,0 +1,26 @@
// @flow strict

import addETHAsset from '../addETHAsset'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to import from index.js because it is the public interface you are testing for existence.

expect(eth.blockchainParams).toBeDefined()
expect(eth.blockchainParams.address).toEqual(ETH_ADDRESS)
})
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also tests required:

  • non-empty assets list
  • with ethereum already in assets list
  • with mock for getAssetsMainnet function returning various results (empty, non-empty, with ethereum)

const jnt: ?DigitalAsset = result[JNT_ADDRESS]

if (!jnt) {
throw new Error('JNT asset not found')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to throw here.

First, you are testing jnt existence in next assertion.

Second, if test continues execution on assertion not passed, you could use safe assertions after, for example: https://jestjs.io/docs/en/expect#tohavepropertykeypath-value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const eth: ?DigitalAsset = result[ETH_ADDRESS] means that eth can be null or undefined.
expect(eth).toBeDefined() will not throw if eth is null.

const azbit: ?DigitalAsset = result[AZBIT_ADDRESS_CS]

if (!azbit) {
throw new Error('Azbit asset not found')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

const azbit: ?DigitalAsset = result[AZBIT_ADDRESS_CS]

if (!azbit) {
throw new Error('Azbit asset not found')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

const jnt: ?DigitalAsset = result[JNT_ADDRESS]

if (!jnt) {
throw new Error('JNT asset not found')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants