/* global describe, it, before */
const path = require('path');
const should = require('should');
const session = require('express-session');
const FirebaseStore = require(path.normalize(`${__dirname}/../lib/connect-session-firebase.js`))(session);

const options = {
  database: {
    serviceAccount: process.env.FIREBASE_SERVICE_ACCOUNT,
    databaseURL: process.env.FIREBASE_DATABASE_URL
  }
};

describe('FirebaseStore', () => {
  describe('Instantiation', () => {
    it('should be able to be created', () => {
      const store = new FirebaseStore(options);

      store.should.be.an.instanceOf(FirebaseStore);
    });
  });

  describe('Setting', () => {
    it('should store data correctly', done => {
      const store = new FirebaseStore(options);

      store.set('1234_#$[]', {
        name: 'tj',
        cookie: {
          maxAge: 2000
        }
      }, (err, res) => {
        if (err) throw err;

        done();
      });
    });
  });

  describe('Getting', () => {
    before(() => {
      const store = new FirebaseStore(options);

      store.set('1234', {
        name: 'tj',
        cookie: {
          maxAge: 2000
        }
      }, () => {});
    });

    it('should get data correctly', done => {
      const store = new FirebaseStore(options);

      store.get('1234', (err, res) => {
        if (err) throw err;

        res.name.should.eql('tj');
        res.cookie.should.eql({
          maxAge: 2000
        });

        done();
      });
    });
  });

  describe('Destroying', () => {
    before(() => {
      const store = new FirebaseStore(options);

      store.set('12345', {
        name: 'tj',
        cookie: {
          maxAge: 2000
        }
      }, () => {});
    });

    it('should destroy data correctly', done => {
      const store = new FirebaseStore(options);

      store.destroy('12345', (err, res) => {
        if (err) throw err;

        store.get('12345', (err, res) => {
          if (err) throw err;

          should.not.exist(res);

          done();
        });
      });
    });
  });

  describe('Clearing', () => {
    before(() => {
      const store = new FirebaseStore(options);

      store.set('abcd', {
        name: 'tj',
        cookie: {
          maxAge: 2000
        }
      }, () => {});

      store.set('abcdef', {
        name: 'tj',
        cookie: {
          maxAge: 2000
        }
      }, () => {});
    });

    it('should clear sessions correctly', done => {
      const store = new FirebaseStore(options);

      store.clear((err, res) => {
        if (err) throw err;

        store.get('abcd', (err, res) => {
          if (err) throw err;

          should.not.exist(res);

          store.get('abcdef', (err, res) => {
            if (err) throw err;

            should.not.exist(res);

            done();
          });
        });
      });
    });
  });

  describe('Reaping', () => {
    before(done => {
      const store = new FirebaseStore(options);

      store.set('abcd', {
        name: 'tj',
        cookie: {
          maxAge: -2000
        }
      }, done);
    });

    it('should reap data correctly', done => {
      const store = new FirebaseStore(options);

      store.reap((err, res) => {
        if (err) throw err;

        store.get('abcd', (err, res) => {
          if (err) throw err;

          should.not.exist(res);

          done();
        });
      });
    });
  });

  describe('Touching', () => {
    before(done => {
      const store = new FirebaseStore(options);

      store.set('abcd', {
        name: 'tj',
        cookie: {
          maxAge: 2000
        }
      }, done);
    });

    it('should touch data correctly', done => {
      const store = new FirebaseStore(options);

      store.touch('abcd', {
        name: 'bn',
        cookie: {
          maxAge: 3000
        }
      }, function (err) {
        if (err) throw err;

        store.get('abcd', (err, res) => {
          if (err) throw err;

          res.name.should.eql('tj');
          res.cookie.should.eql({
            maxAge: 3000
          });

          done();
        });
      });
    });
  });
});

@@ -247,24 +247,85 @@
 );%0A%0A
-const options = 
+require('dotenv').config(%7B silent: true %7D);%0A%0Aconst store = new FirebaseStore(
 %7B%0A  
@@ -450,16 +450,17 @@
 RL%0A  %7D%0A%7D
+)
 ;%0A%0Adescr
@@ -575,57 +575,8 @@
 %3E %7B%0A
-      const store = new FirebaseStore(options);%0A%0A
     
@@ -720,57 +720,8 @@
 %3E %7B%0A
-      const store = new FirebaseStore(options);%0A%0A
     
@@ -966,57 +966,8 @@
 %3E %7B%0A
-      const store = new FirebaseStore(options);%0A%0A
     
@@ -1138,57 +1138,8 @@
 %3E %7B%0A
-      const store = new FirebaseStore(options);%0A%0A
     
@@ -1403,57 +1403,8 @@
 %3E %7B%0A
-      const store = new FirebaseStore(options);%0A%0A
     
@@ -1580,57 +1580,8 @@
 %3E %7B%0A
-      const store = new FirebaseStore(options);%0A%0A
     
@@ -1867,57 +1867,8 @@
 %3E %7B%0A
-      const store = new FirebaseStore(options);%0A%0A
     
@@ -2165,57 +2165,8 @@
 %3E %7B%0A
-      const store = new FirebaseStore(options);%0A%0A
     
@@ -2572,57 +2572,8 @@
 %3E %7B%0A
-      const store = new FirebaseStore(options);%0A%0A
     
@@ -2742,57 +2742,8 @@
 %3E %7B%0A
-      const store = new FirebaseStore(options);%0A%0A
     
@@ -3018,57 +3018,8 @@
 %3E %7B%0A
-      const store = new FirebaseStore(options);%0A%0A
     
@@ -3128,32 +3128,32 @@
 done);%0A    %7D);%0A%0A
+
     it('should t
@@ -3188,57 +3188,8 @@
 %3E %7B%0A
-      const store = new FirebaseStore(options);%0A%0A
     

Move FirebaseStore instance outside of test functions