Skip to content

Commit

Permalink
Adds some tests and update jest config
Browse files Browse the repository at this point in the history
  • Loading branch information
kbardi committed May 28, 2019
1 parent bc24504 commit 74a8c41
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 7 deletions.
20 changes: 16 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ module.exports = {
coverageDirectory: 'coverage',

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],
coveragePathIgnorePatterns: [
'/node_modules/',
'/__tests__/__util__',
'/src/imports',
'/webpack.dev.config.js',
'/src/server/server-test.js',
'/src/server/server.config.js'
],

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
Expand Down Expand Up @@ -142,7 +147,14 @@ module.exports = {
// testPathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],
testPathIgnorePatterns: ['/__tests__/__util__']
testPathIgnorePatterns: [
'/node_modules/',
'/__tests__/__util__',
'/src/imports',
'/webpack.dev.config.js',
'/src/server/server-test.js',
'/src/server/server.config.js'
]

// The regexp pattern Jest uses to detect test files
// testRegex: "",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "webpack --mode production --config webpack.server.config.js",
"test": "jest --forceExit --detectOpenHandles --maxWorkers=1",
"test:staging": "jest --forceExit --detectOpenHandles",
"coverage": "jest --forceExit --detectOpenHandles --coverage",
"coverage": "jest --forceExit --detectOpenHandles --coverage --maxWorkers=1",
"coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls",
"start": "node dist/server.js",
"start:dev": "webpack --mode development --config webpack.server.config.js --watch --verbose",
Expand Down
4 changes: 4 additions & 0 deletions src/server/blockchain/AdminWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ export class Wallet {
}
}

async getAddressBalance(address: string): Promise<number> {
return this.web3.eth.getBalance(address)
}

async getBalance(): Promise<number> {
return this.web3.eth
.getBalance(this.address)
Expand Down
11 changes: 11 additions & 0 deletions src/server/blockchain/__tests__/adminWallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ test('adminWallet can blacklist user', async () => {
test('adminWallet throws exception', async () => {
await expect(AdminWallet.blacklistUser('0x888')).rejects.toThrow()
})

test('adminWallet get balance correctly', async () => {
const balance = await AdminWallet.getBalance()
expect(balance > 0).toBeTruthy()
})

test('adminWallet top wallet throws an error when user is not whitelisted/verified', async () => {
const unverifiedAddress = '0xb999A6a8096dE62638f99157E5E05894303F5EA8'
await AdminWallet.blacklistUser(unverifiedAddress)
await expect(AdminWallet.topWallet(unverifiedAddress, null)).rejects.toThrow()
})
16 changes: 15 additions & 1 deletion src/server/send/__tests__/sendAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,28 @@ describe('sendAPÏ', () => {
.expect(401)
})

test('/send/linkemailwith creds', async () => {
test('/send/linkemail with creds', async () => {
const token = await getToken(server)
await request(server)
.post('/send/linkemail')
.set('Authorization', `Bearer ${token}`)
.expect(200, { ok: 1, onlyInEnv: { current: 'test', onlyIn: ['production', 'staging'] } })
})

test('/send/linksms without creds -> 401', async () => {
await request(server)
.post('/send/linksms')
.expect(401)
})

test('/send/linksms with creds', async () => {
const token = await getToken(server)
await request(server)
.post('/send/linksms')
.set('Authorization', `Bearer ${token}`)
.expect(200, { ok: 1, onlyInEnv: { current: 'test', onlyIn: ['production', 'staging'] } })
})

test('/verify/sendemail with creds', async () => {
const token = await getToken(server)
//make sure fullname is set for user which is required for sending the recovery email
Expand Down
20 changes: 20 additions & 0 deletions src/server/verification/__tests__/verificationAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ describe('verificationAPI', () => {
.expect(401)
})

test('/verify/sendotp without sms validation', async () => {
const userCredentials = {
signature:
'0x7acee1dc0d8a07d3e4f2cd1cbbebed9098afea5600bbb1f8a99bd7154e2de4a35e42b868dd373a831e78f0bbf2a8d0340cc63fa8345e433fd3fe64b01bcae0781c',
gdSignature:
'0xd2e95cd11e2b3148674f2207d4f054dbf25e4d2a6e763418ba9bd62c5a99be621f738a0419c4754cc95395c93ac76688f781d7cb00dda0b79693c05de0bee4971b',
nonce: 'a29344af372abf77dd68',
profileSignature:
'SEA{"m":"Login to GoodDAPPa29344af372abf77dd68","s":"nxiNDIdE714q1qTHGzXDy/uJqnXD4uE/QBQDym2ZTTN8cxQyBlODP7x/7+LQggC0K4uO6Y+tTddGLHdSyJGblQ=="}',
profilePublickey: 'kxudRZes6qS44fus50kd0knUVftOeyDTQnmsnMmiaWA.uzJ1fJM0evhtave7yZ5OWBa2O91MBU7DNAHau8xUXYw'
}
const token = await getToken(server, userCredentials)
await GunDBPrivate.updateUser({ identifier: token, smsValidated: false })

await request(server)
.post('/verify/sendotp')
.set('Authorization', `Bearer ${token}`)
.expect(200, { ok: 1, onlyInEnv: { current: 'test', onlyIn: ['production', 'staging'] } })
})

test('/verify/sendotp with creds', async () => {
const token = await getToken(server)
await request(server)
Expand Down
5 changes: 4 additions & 1 deletion src/server/verification/verificationAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import fs from 'fs'
const fsPromises = fs.promises
const setup = (app: Router, verifier: VerificationAPI, storage: StorageAPI) => {
var upload = multer({ dest: 'uploads/' }) // to handle blob parameters of faceReco

app.post(
'/verify/facerecognition',
passport.authenticate('jwt', { session: false }),
Expand Down Expand Up @@ -50,6 +51,7 @@ const setup = (app: Router, verifier: VerificationAPI, storage: StorageAPI) => {
res.json(result)
})
)

app.post(
'/verify/user',
passport.authenticate('jwt', { session: false }),
Expand All @@ -71,6 +73,7 @@ const setup = (app: Router, verifier: VerificationAPI, storage: StorageAPI) => {
}
})
)

app.post(
'/verify/sendotp',
passport.authenticate('jwt', { session: false }),
Expand All @@ -85,7 +88,6 @@ const setup = (app: Router, verifier: VerificationAPI, storage: StorageAPI) => {
if (!userRec.smsValidated) {
const [, code] = await sendOTP(body.user)
const expirationDate = Date.now() + +conf.otpTtlMinutes * 60 * 1000

await storage.updateUser({ identifier: user.loggedInAs, otp: { code, expirationDate } })
}
res.json({ ok: 1 })
Expand Down Expand Up @@ -134,6 +136,7 @@ const setup = (app: Router, verifier: VerificationAPI, storage: StorageAPI) => {
res.json(txRes)
})
)

/**
* Send verification email endpoint
*/
Expand Down

0 comments on commit 74a8c41

Please sign in to comment.