tm-apps-list-api
Version:
79 lines (64 loc) • 2.15 kB
JavaScript
'use strict';
const assert = require('chai').assert;
const rewire = require('rewire');
const server = rewire('../../src/server');
const sinon = require('sinon');
describe('Pools Unit Tests', () => {
const configStub = {
server: {
host: 'localhost',
port: 8080
},
dynamodb: {
region: 'eu-west-1',
tableName: 'AppPools-test',
tableNamePools: 'AppsSectionPools-test',
endpoint: 'http://localhost:8000'
},
db: {
username: 'blah',
password: 'blah',
database: 'blah',
dialect: 'postgres',
host: 'localhost',
logging: false
},
cache: {
enabled: false,
redis: {
host: 'myRedis',
port: '6379'
},
duration: '2 minutes'
},
logging: {
enabled: false,
enhanced: false
},
articleEndpoint: 'http://org-apps-test-endpoint.com'
};
describe('redisCache', () => {
it('should create redisCache middleware', () => {
const clientStub = sinon.stub().returns({redis: 'client'});
const redis = {createClient: clientStub};
const middlewareStub = sinon.stub().returns({func: 'req,res,next'});
const optionsStub = sinon.stub().returns({middleware: middlewareStub});
const apicache = {options: optionsStub};
const redisCache = server.__get__('redisCache');
const result = redisCache(configStub, redis, apicache);
assert.deepEqual(result, {func: 'req,res,next'});
sinon.assert.calledWith(clientStub, {
host: 'myRedis',
port: '6379'
});
sinon.assert.calledWith(optionsStub, {
redisClient: {redis: 'client'},
statusCodes: {
exclude: [],
include: [200]
}
});
sinon.assert.calledWith(middlewareStub, '2 minutes');
});
});
});