Skip to content

Commit

Permalink
corrections for tests and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
fedeatanasoff committed Jun 28, 2019
1 parent b32d7f8 commit 998110e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 34 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const cacheManager = new CacheManager('client-prefix');
```js

// save in all cache strategies
cacheManager.save('key', 'subkey', { message: 'hello friend' })
await cacheManager.save('key', 'subkey', { message: 'hello friend' })
```
### How to fetch data?
```js
Expand All @@ -66,7 +66,7 @@ await cacheManager.reset('key');
```

## API
- `save('key', 'subkey', 'some value')`
- `async save('key', 'subkey', 'some value')`
Save data in memory and redis. Receives a key [string], a subkey [string] and value [any] to save.
- `async fetch('key', 'subkey')`
Fetched data in the fastest strategy. Receives the key [string] and subkey [string] as parameter with which the value was saved. Returns a promise. In case of not found a value returns null
Expand Down Expand Up @@ -132,7 +132,7 @@ console.log(keymem) // undefined

#### API redis

- `set('key', 'subkey', 'some value')`
- `async set('key', 'subkey', 'some value')`
Save data. Receives a key [string], a subkey [string] and value [any] to save.

- `async get('key', 'subkey')`
Expand Down
2 changes: 1 addition & 1 deletion lib/memory-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class MemoryManager {
* @param {String} value Results
* @returns {boolean} true if success.
*/
set(key, subkey, value) {
async set(key, subkey, value) {
if(!key || !subkey || !value)
throw new CacheManagerError('SET - Missing parametres.', CacheManagerError.codes.MISSING_PARAMETRES);
const newParams = this._prepareParams(subkey);
Expand Down
4 changes: 2 additions & 2 deletions tests/memory-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ describe('Memory Manager Tests', () => {
});

context('when should throw erros', () => {
it('should detect the error when setting data wrong', () => {
assert.throws(() => memory.set('only key'), {
it('should detect the error when setting data wrong', async () => {
await assert.rejects(memory.set('only key'), {
name: 'CacheManagerError',
code: CacheManagerError.codes.MISSING_PARAMETRES
});
Expand Down
33 changes: 5 additions & 28 deletions tests/redis-manager-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-underscore-dangle */
/* eslint-disable prefer-arrow-callback */

'use strict';
Expand Down Expand Up @@ -35,45 +36,35 @@ describe('Redis Manager', function() {
context('should throws error', () => {


it('RESET ENTITY', async () => {
it('should throw an error when the redis del method fails', async () => {
sandbox.stub(newRedis.client, 'del').rejects();

await assert.rejects(newRedis._resetEntity('h'), {
name: 'CacheManagerError',
code: CacheManagerError.codes.REDIS_ERROR
});


sandbox.restore();
});

it('RESET ALL', async () => {
it('should throw an error when the redis flushall method fails', async () => {
sandbox.stub(newRedis.client, 'flushall').rejects();

await assert.rejects(newRedis._resetAll(), {
name: 'CacheManagerError',
code: CacheManagerError.codes.REDIS_ERROR
});


sandbox.restore();
});

it('HSET', async () => {

it('should throw an error when the redis hset method fails', async () => {
sandbox.stub(newRedis.client, 'hset').rejects('Error');

await assert.rejects(newRedis.set('fede', 'sk', 'value'), {
name: 'CacheManagerError',
code: CacheManagerError.codes.REDIS_ERROR
});

sandbox.restore();
});

it('HGET', async () => {
it('should throw an error when the redis hget method fails', async () => {
sandbox.stub(newRedis.client, 'hget').rejects('Error');

await assert.rejects(newRedis.get('k', 'sk'), {
name: 'CacheManagerError',
code: CacheManagerError.codes.REDIS_ERROR
Expand Down Expand Up @@ -136,7 +127,6 @@ describe('Redis Manager', function() {

assert.deepEqual(newRedis.configServer(), { host: 'fakehost', port: 1234 });
sandbox.restore();

});

it('should take the values ​​by default', () => {
Expand Down Expand Up @@ -182,17 +172,4 @@ describe('Redis Manager', function() {
});
});
});

context('errors await', () => {
/* it('set', async () => {
const red = new RedisManager('f');
red.close();
await assert.rejects(red.set('k', 'sk', () => console.log('REJECTS!!')), {
name: 'CacheManagerError',
code: CacheManagerError.codes.REDIS_ERROR
});
}); */
});
});

0 comments on commit 998110e

Please sign in to comment.