1 | 'use strict';
|
2 |
|
3 | var expect = require('chai').expect;
|
4 | var cache = require('../lib/cache');
|
5 |
|
6 | describe('config', function(){
|
7 | var config, mockConfig, configName = 'base';
|
8 |
|
9 | beforeEach(function(){
|
10 | cache.enable();
|
11 | cache.clear();
|
12 | mockConfig = {
|
13 | get: function(configName, ptr) { return this[ptr]; }
|
14 | };
|
15 | config = require('../lib/config')(mockConfig, configName);
|
16 | });
|
17 |
|
18 | describe('config', function(){
|
19 | it('should return value config class', function(){
|
20 | var ptr = '#/dummy';
|
21 | mockConfig[ptr] = 'expected value';
|
22 | return config(ptr).then(function(val){
|
23 | expect(val).to.eql('expected value');
|
24 | });
|
25 | });
|
26 | it('should return value from cache instead of getting again', function(){
|
27 | var ptr = '#/dummy';
|
28 | mockConfig[ptr] = 'expected value';
|
29 | return config(ptr).then(function(){
|
30 | mockConfig.get = function() { throw new Error('should not get here'); };
|
31 | return config(ptr);
|
32 | }).then(function(val){
|
33 | expect(val).to.eql('expected value');
|
34 | });
|
35 | });
|
36 | });
|
37 |
|
38 | describe('#authCacheTTL', function(){
|
39 | var ptr = '#/trusted_endpoint/auth_cache_timeout_ms';
|
40 |
|
41 | beforeEach(function(){
|
42 | mockConfig[ptr] = 2000;
|
43 | });
|
44 |
|
45 | it('should return value config class', function(){
|
46 | return config.authCacheTTL().then(function(val){
|
47 | expect(val).to.eql(2000);
|
48 | });
|
49 | });
|
50 | it('should return default value when config does not have it', function(){
|
51 | mockConfig[ptr] = undefined;
|
52 | return config.authCacheTTL().then(function(val){
|
53 | expect(val).to.eql(300000);
|
54 | });
|
55 | });
|
56 | it('should return value from cache instead of getting again', function(){
|
57 | return config.authCacheTTL().then(function(){
|
58 | mockConfig.get = function() { throw new Error('should not get here'); };
|
59 | return config.authCacheTTL();
|
60 | }).then(function(val){
|
61 | expect(val).to.eql(2000);
|
62 | });
|
63 | });
|
64 | });
|
65 | });
|