{"size": 3020, "ext": "js", "max_stars_repo_path": "test/disabled_memory_test.js", "max_stars_repo_name": "yunnysunny/session-token", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/disabled_memory_test.js", "max_issues_repo_name": "yunnysunny/session-token", "max_issues_repo_issues_event_min_datetime": "2019-04-21T04:03:09.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-16T04:55:44.000Z", "max_forks_repo_path": "test/disabled_memory_test.js", "max_forks_repo_name": "yunnysunny/session-token", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 29.0384615385, "max_line_length": 80, "alphanum_fraction": 0.5251655629}
const {expect} = require('chai');
const Redis = require('ioredis');
const SessionToken = require('../index');
const redisClient = new Redis();//connect to the redis server of localhost:6379
const redisSub = new Redis();//the redis client for subscribe
const sessionToken = new SessionToken({
    expireTime:7200,//the time of seconds before the session data expired
    redisKeyPrefix:'disabled_mem:mytoken:',//the redis key's prefix
    redis:redisClient,//the redis client object
    subRedis:redisSub,
    maxSize:-1
});
const VALUE = {name:'sunny',id:1};
const VALUE_UPDATE = {name:'sunny_new',id:1};
let token = null;

describe('disabled memeory cache test#',function() {
    it ('should generate the first session success',function(done) {
        sessionToken.generate(VALUE,function(err,tokenViaCreate) {//save session
            if (err) {
                return done(err);
            }
            token = tokenViaCreate;
            done();
        });
    });

    it ('should generate the second session success',function(done) {
        sessionToken.generate(VALUE,function(err,tokenViaCreate) {//save session
            if (err) {
                return done(err);
            }
            done();
        });
    });

    it('the memeory cache size should be zero',function(done) {
        sessionToken.getStorageSize(function(err, size) {
            if (err) {
                return done(err);
            }

            expect(size).to.be.equal(0);
            done();
        });
        
    });

    it ('should get success',function(done) {
        sessionToken.get(token,function(err,obj) {
            if (err) {
                return done(err);
            }
            expect(obj).to.have.property('name').and.equal(VALUE.name);
            done();
        });
    });

    it('should update success',function(done) {
        sessionToken.update(token,VALUE_UPDATE,function(err) {
            if (err) {
                return done(err);
            }
            done();
        });
    });
    it('should get new data success',function(done) {
        sessionToken.get(token,function(err,obj) {
            if (err) {
                return done(err);
            }
            expect(obj).to.have.property('name').and.equal(VALUE_UPDATE.name);
            done();
        });
    });

    it('should refresh expire time success',function(done) {
        sessionToken.refresh(token,function(err) {
            if (err) {
                return done(err);
            }
            done();
        });
    });

    it('shold delete token success',function(done) {
        sessionToken.delete(token,function(err) {
            if (err) {
                return done(err);
            }
            done();
        });
    });

    it ('should call get with no data',function(done) {
        sessionToken.get(token,function(err,obj) {
            if (err) {
                return done(err);
            }
            expect(obj).equal(false);
            done();
        });
    });
});