From 7d3cca5e4867fa47fabbc99921de8f67edacdc6a Mon Sep 17 00:00:00 2001 From: Mina Nagy Zaki Date: Thu, 15 Aug 2019 16:57:03 +0200 Subject: [PATCH] Update tests - run unit tests under proper NODE_ENV - fix fuelKeyWithEther call/test - minor typescript issues --- package.json | 4 ++-- src/config.ts | 6 ++++-- src/lib/storage/entities/verifiableCredentialEntity.ts | 1 - src/ui/registration/containers/entropy.tsx | 6 ++---- tests/actions/registration/index.test.ts | 7 ++----- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 19288519da..1e84fd3864 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,8 @@ }, "scripts": { "start": "adb reverse tcp:8081 tcp:8081 & node node_modules/react-native/local-cli/cli.js start", - "test": "jest", - "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand", + "test": "NODE_ENV=test jest", + "test:debug": "NODE_ENV=test node --inspect-brk node_modules/.bin/jest --runInBand", "run:ios": "react-native run-ios", "run:android": "react-native run-android --appIdSuffix debug", "run:android:staging": "react-native run-android --variant staging --appIdSuffix debugStaging", diff --git a/src/config.ts b/src/config.ts index edc0856947..840a003145 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,10 +2,12 @@ import typeOrmConf from '../ormconfig' const env = process.env['NODE_ENV'] || 'development' const isDev = env === 'development' +// @ts-ignore const isTest = env === 'test' +const isTestE2E = env === 'test-e2e' -export const skipEntropyCollection = isDev || isTest -export const skipIdentityRegisteration = isDev || isTest +export const skipEntropyCollection = isDev || isTest || isTestE2E +export const skipIdentityRegisteration = isDev || isTestE2E export default { fuelingEndpoint: 'https://faucet.jolocom.com/request', diff --git a/src/lib/storage/entities/verifiableCredentialEntity.ts b/src/lib/storage/entities/verifiableCredentialEntity.ts index abab11ef9b..8f2dd4fc59 100644 --- a/src/lib/storage/entities/verifiableCredentialEntity.ts +++ b/src/lib/storage/entities/verifiableCredentialEntity.ts @@ -5,7 +5,6 @@ import { OneToMany, ManyToOne, } from 'typeorm/browser' - import { Exclude, Expose, plainToClass, classToPlain } from 'class-transformer' import { SignedCredential } from 'jolocom-lib/js/credentials/signedCredential/signedCredential' import { ISignedCredentialAttrs } from 'jolocom-lib/js/credentials/signedCredential/types' diff --git a/src/ui/registration/containers/entropy.tsx b/src/ui/registration/containers/entropy.tsx index 11473a6486..2f3ca224b6 100644 --- a/src/ui/registration/containers/entropy.tsx +++ b/src/ui/registration/containers/entropy.tsx @@ -59,10 +59,8 @@ export class EntropyContainer extends React.Component { } private updateEntropyProgress = async (): Promise => { - let { entropyProgress } = this.state - if (skipEntropyCollection) { - entropyProgress = 1 - } + const entropyProgress = skipEntropyCollection ? 1 : this.state.entropyProgress + if (entropyProgress >= 1) { this.setState({ sufficientEntropy: true, entropyProgress: 1 }) while (this.entropyGenerator.getProgress() < 1) { diff --git a/tests/actions/registration/index.test.ts b/tests/actions/registration/index.test.ts index f990645a4c..80148efda2 100644 --- a/tests/actions/registration/index.test.ts +++ b/tests/actions/registration/index.test.ts @@ -1,6 +1,5 @@ import { registrationActions } from 'src/actions' import data from './data/mockRegistrationData' -import { JolocomLib } from 'jolocom-lib' import * as util from 'src/lib/util' import { withErrorScreen } from 'src/actions/modifiers' import { AppError, ErrorCode } from 'src/lib/errors' @@ -79,9 +78,6 @@ describe('Registration action creators', () => { it('should attempt to create an identity', async () => { MockDate.set(new Date(946681200000)) const { getPasswordResult, cipher, entropy, identityWallet } = data - const fuelSpy = jest - .spyOn(JolocomLib.util, 'fuelKeyWithEther') - .mockResolvedValueOnce(null) const mockMiddleware = { identityWallet, @@ -107,6 +103,7 @@ describe('Registration action creators', () => { create: () => identityWallet, }, setIdentityWallet: jest.fn(() => Promise.resolve()), + fuelKeyWithEther: jest.fn().mockResolvedValueOnce(null) } const mockState: Partial = { @@ -134,7 +131,7 @@ describe('Registration action creators', () => { expect( mockMiddleware.storageLib.store.derivedKey.mock.calls, ).toMatchSnapshot() - expect(fuelSpy.mock.calls).toMatchSnapshot() + expect(mockMiddleware.fuelKeyWithEther.mock.calls).toMatchSnapshot() MockDate.reset() })