-
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.
Merge branch 'master' into multiplex
- Loading branch information
Showing
29 changed files
with
3,100 additions
and
84 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 |
---|---|---|
|
@@ -7,3 +7,4 @@ node_modules | |
|
||
dist/ | ||
*.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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 'test-file-stub'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {}; |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
moduleNameMapper: { | ||
'\\.(css|less|sass|scss)$': '<rootDir>/__mocks__/styleMock.js', | ||
'\\.(gif|ttf|eot|svg)$': '<rootDir>/__mocks__/fileMock.js' | ||
}, | ||
transform: { | ||
'^.+\\.jsx?$': 'babel-jest' | ||
}, | ||
verbose: true, | ||
collectCoverage: true, | ||
collectCoverageFrom: [ | ||
'server/**/*.{js,jsx}', | ||
'src/**/*.{js,jsx}', | ||
'!**/node_modules/**', | ||
'!**/vendor/**' | ||
] | ||
}; |
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
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 |
---|---|---|
@@ -0,0 +1,160 @@ | ||
// import MockRedis from 'ioredis-mock'; | ||
|
||
import redis from './redis'; | ||
import config from './config'; | ||
|
||
const mocks = { redis: null }; | ||
|
||
jest.mock('ioredis', () => { | ||
const Redis = require('ioredis-mock'); | ||
if (typeof Redis === 'object') { | ||
// the first mock is an ioredis shim because ioredis-mock depends on it | ||
// https://github.com/stipsan/ioredis-mock/blob/master/src/index.js#L101-L111 | ||
return { | ||
Command: { _transformer: { argument: {}, reply: {} } } | ||
}; | ||
} | ||
// second mock for our code | ||
return function(...args) { | ||
const dummyData = { | ||
data: { | ||
jobId: { | ||
'status': 'done', | ||
'otherKey': 'testValue' | ||
} | ||
} | ||
}; | ||
const instance = new Redis({...args, ...dummyData}); | ||
mocks.redis = instance; | ||
return instance; | ||
} | ||
}); | ||
|
||
jest.mock('../config/config', () => { | ||
return { | ||
redis: { | ||
sentinelEnabled: false | ||
} | ||
}; | ||
}); | ||
|
||
describe('Redis tests', () => { | ||
|
||
beforeEach(() => { | ||
if (mocks.redis != null) { | ||
mocks.redis.hmset('jobId', ['status', 'done', 'otherKey', 'testValue']); | ||
} | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('Test HGET', () => { | ||
|
||
it('should get the correct value', async done => { | ||
let value = await redis.hget('jobId', 'status'); | ||
expect(value).toBe('done'); | ||
|
||
config.redis.sentinelEnabled = true; | ||
value = await redis.hget('jobId', 'status'); | ||
expect(value).toBe('done'); | ||
|
||
done(); | ||
}); | ||
|
||
}); | ||
|
||
describe('Test HMGET', () => { | ||
|
||
it('should get the correct values', async done => { | ||
let value = await redis.hmget('jobId', ['status', 'otherKey']); | ||
expect(value).toMatchObject(['done', 'testValue']); | ||
|
||
config.redis.sentinelEnabled = true; | ||
value = await redis.hmget('jobId', ['status', 'otherKey']); | ||
expect(value).toMatchObject(['done', 'testValue']); | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
describe('Test EXPIRE', () => { | ||
|
||
it('should expire the key', async done => { | ||
let value = await redis.expire('jobId', 1); | ||
expect(value).toBe(1); | ||
|
||
config.redis.sentinelEnabled = true; | ||
value = await redis.expire('jobId', 1); | ||
expect(value).toBe(1); | ||
done(); | ||
}); | ||
|
||
it('should return 0 if no valid key', async done => { | ||
let value = await redis.expire('otherKey', 1); | ||
expect(value).toBe(0); | ||
|
||
config.redis.sentinelEnabled = true; | ||
value = await redis.expire('anotherKey', 1); | ||
expect(value).toBe(0); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe('Test LPUSH', () => { | ||
|
||
it('should push a single value to a queue', async done => { | ||
let value = await redis.lpush('testQueue0', 'newKey'); | ||
expect(value).toBe(1); | ||
|
||
let response = await mocks.redis.llen('testQueue0'); | ||
expect(response).toBe(1); | ||
|
||
config.redis.sentinelEnabled = true; | ||
value = await redis.lpush('testQueue1', 'newKey'); | ||
expect(value).toBe(1); | ||
|
||
response = await mocks.redis.llen('testQueue1'); | ||
expect(response).toBe(1); | ||
done(); | ||
}); | ||
|
||
it('should push an array of values to a queue', async done => { | ||
let value = await redis.lpush('testQueue2', ['newKey', 'otherNewKey']); | ||
expect(value).toBe(2); | ||
|
||
let response = await mocks.redis.llen('testQueue2'); | ||
expect(response).toBe(2); | ||
|
||
config.redis.sentinelEnabled = true; | ||
value = await redis.lpush('testQueue3', ['newKey', 'otherNewKey']); | ||
expect(value).toBe(2); | ||
|
||
response = await mocks.redis.llen('testQueue3'); | ||
expect(response).toBe(2); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe('Test HMSET', () => { | ||
|
||
it('should set multiple values', async done => { | ||
const newStatus = 'success'; | ||
let value = await redis.hmset('jobId', ['status', newStatus]); | ||
expect(value).toBe('OK'); | ||
|
||
let response = await mocks.redis.hget('jobId', 'status'); | ||
expect(response).toBe(newStatus); | ||
|
||
config.redis.sentinelEnabled = true; | ||
value = await redis.hmset('jobId', ['status', newStatus]); | ||
expect(value).toBe('OK'); | ||
|
||
response = await mocks.redis.hget('jobId', 'status'); | ||
expect(response).toBe(newStatus); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import supertest from 'supertest'; | ||
|
||
import app from '../index'; | ||
import swaggerSpec from '../config/swagger'; | ||
|
||
describe('Miscellaneous Controller Tests', () => { | ||
|
||
describe('GET /api/swagger.json', () => { | ||
|
||
it('should return a JSON Swagger spec', async done => { | ||
const request = supertest(app); | ||
const response = await request.get('/api/swagger.json'); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body).toMatchObject(swaggerSpec); | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
describe('GET /api/health-check', () => { | ||
|
||
it('should return 200 OK', async done => { | ||
const request = supertest(app); | ||
const response = await request.get('/api/health-check'); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body).toHaveProperty('message'); | ||
expect(response.body.message).toBe('OK'); | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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
Oops, something went wrong.