-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct set, get, keys, and ttl functions. Also wait for client ready in global setup
- Loading branch information
Showing
7 changed files
with
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ server/.env | |
nginx.conf | ||
server/logs/ | ||
**/*.log | ||
coverage/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,21 @@ | ||
const { promisify } = require('util'); | ||
const cryptoRandomString = require('crypto-random-string'); | ||
const { client, rediskeys } = require('../../../db/redis'); | ||
const service = require('../services/evalPassReset.service'); | ||
const { ErrorTest } = require('../../util/util'); | ||
const config = require('../../../config'); | ||
|
||
const keys = promisify(client.keys).bind(client); | ||
const ttl = promisify(client.ttl).bind(client); | ||
|
||
describe('evalPassReset service', () => { | ||
test('Valid request returns confirmation and redis key', async () => { | ||
const email = '[email protected]'; | ||
const rand = cryptoRandomString({ length: config.verificationTokenLength, type: 'url-safe' }); | ||
await client.SET(rediskeys.passReset(rand), email, { EX: config.verificationTimeout * 60 }); | ||
|
||
// Check to make sure the redis key was set | ||
const redisOutput = await keys('passReset:*'); | ||
const redisOutput = await client.KEYS('passReset:*'); | ||
expect(redisOutput.length).toBeGreaterThan(0); | ||
const thekey = redisOutput[0]; | ||
expect(redisOutput[0].split('passReset:')[1].length).toBe(config.verificationTokenLength); | ||
const thettl = await ttl(thekey).then(Number); | ||
const thettl = await client.TTL(thekey).then(Number); | ||
expect(thettl).toBeGreaterThan(0); | ||
|
||
const output = await service({ token: rand, password: '12345678', confirmPassword: '12345678' }); | ||
|
@@ -32,11 +28,11 @@ describe('evalPassReset service', () => { | |
await client.SET(rediskeys.passReset(rand), email, { EX: config.verificationTimeout * 60 }); | ||
|
||
// Check to make sure the redis key was set | ||
const redisOutput = await keys('passReset:*'); | ||
const redisOutput = await client.KEYS('passReset:*'); | ||
expect(redisOutput.length).toBeGreaterThan(0); | ||
const thekey = redisOutput[0]; | ||
expect(redisOutput[0].split('passReset:')[1].length).toBe(config.verificationTokenLength); | ||
const thettl = await ttl(thekey).then(Number); | ||
const thettl = await client.TTL(thekey).then(Number); | ||
expect(thettl).toBeGreaterThan(0); | ||
|
||
try { | ||
|
@@ -58,11 +54,11 @@ describe('evalPassReset service', () => { | |
await client.SET(rediskeys.passReset(rand), email, { EX: config.verificationTimeout * 60 }); | ||
|
||
// Check to make sure the redis key was set | ||
const redisOutput = await keys('passReset:*'); | ||
const redisOutput = await client.KEYS('passReset:*'); | ||
expect(redisOutput.length).toBeGreaterThan(0); | ||
const thekey = redisOutput[0]; | ||
expect(redisOutput[0].split('passReset:')[1].length).toBe(config.verificationTokenLength); | ||
const thettl = await ttl(thekey).then(Number); | ||
const thettl = await client.TTL(thekey).then(Number); | ||
expect(thettl).toBeGreaterThan(0); | ||
|
||
try { | ||
|
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 |
---|---|---|
@@ -1,24 +1,20 @@ | ||
const { promisify } = require('util'); | ||
const service = require('../services/genPassReset.service'); | ||
const { ErrorTest } = require('../../util/util'); | ||
|
||
const { client } = require('../../../db/redis'); | ||
const config = require('../../../config'); | ||
|
||
const keys = promisify(client.keys).bind(client); | ||
const ttl = promisify(client.ttl).bind(client); | ||
|
||
describe('genPassReset service', () => { | ||
test('Valid request returns confirmation and redis key', async () => { | ||
const output = await service({ email: '[email protected]' }); | ||
expect(output).toMatch(/^.*resetPassword.*$/); | ||
|
||
// Check to make sure the redis key was set | ||
const redisOutput = await keys('passReset:*'); | ||
const redisOutput = await client.KEYS('passReset:*'); | ||
expect(redisOutput.length).toBeGreaterThan(0); | ||
const thekey = redisOutput[0]; | ||
expect(redisOutput[0].split('passReset:')[1].length).toBe(config.verificationTokenLength); | ||
const thettl = await ttl(thekey).then(Number); | ||
const thettl = await client.TTL(thekey).then(Number); | ||
expect(thettl).toBeGreaterThan(0); | ||
}); | ||
|
||
|
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 |
---|---|---|
@@ -1,24 +1,20 @@ | ||
const { promisify } = require('util'); | ||
const service = require('../services/genVerify.service'); | ||
const { ErrorTest } = require('../../util/util'); | ||
|
||
const { client } = require('../../../db/redis'); | ||
const config = require('../../../config'); | ||
|
||
const keys = promisify(client.keys).bind(client); | ||
const ttl = promisify(client.ttl).bind(client); | ||
|
||
describe('genVerify service', () => { | ||
test('Valid request returns confirmation and redis key', async () => { | ||
const output = await service({ email: '[email protected]' }); | ||
expect(output).toStrictEqual({ needsVerification: true }); | ||
|
||
// Check to make sure the redis key was set | ||
const redisOutput = await keys('emailVer:*'); | ||
const redisOutput = await client.KEYS('emailVer:*'); | ||
expect(redisOutput.length).toBeGreaterThan(0); | ||
const thekey = redisOutput[0]; | ||
expect(redisOutput[0].split('emailVer:')[1].length).toBe(config.verificationTokenLength); | ||
const thettl = await ttl(thekey).then(Number); | ||
const thettl = await client.TTL(thekey).then(Number); | ||
expect(thettl).toBeGreaterThan(0); | ||
}); | ||
|
||
|
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