text: 'use strict';
  
  const config = require('config');
  
  const jwt = require('jsonwebtoken');
  
  const chai = require('chai');
  chai.use(require('chai-string'));
  chai.use(require('chai-as-promised'));
  
  const should = chai.should();
  const expect = chai.expect;
  
  const Store = require('../../lib/store');
  
  const BASE_URL = config.get('base_url');
  const PORT = process.env.PORT || parseInt(config.get('port'), 10) || 3000;
  
  const JWT_CONFIG = config.get('jwt');
  
  const TEST_USER = 'testUser';
  const TEST_REPO = 'testRepo';
  const TEST_OID = 'testoid';
  
  describe('Abstract Store', function () {
      var store;
  
      beforeEach(() => {
          store = new Store();
      });
  
      it('should throw error for put', () => {
          expect(store.put()).to.be.rejectedWith(Error);
      });
  
      it('should throw error for get', () => {
          expect(store.get()).to.be.rejectedWith(Error);
      });
  
      it('should throw error for getSize', () => {
          expect(store.getSize()).to.be.rejectedWith(Error);
      });
  
      describe('#getUploadAction()', () => {
          it('should return upload action', () => {
              var action = store.getUploadAction(TEST_USER, TEST_REPO, TEST_OID, 0);
              action.href.should.equal(`${BASE_URL}:${PORT}/${TEST_USER}/${TEST_REPO}/objects/${TEST_OID}`);
              should.exist(action.expires_at);
              should.exist(action.header);
              action.header['Authorization'].should.startWith('JWT ');
  
              let authorization = action.header['Authorization'];
              let token = authorization.substring(4, authorization.length);
              let decoded = jwt.verify(token, JWT_CONFIG.secret, { issuer: JWT_CONFIG.issuer });
              decoded.user.should.equal(TEST_USER);
              decoded.repo.should.equal(TEST_REPO);
              decoded.oid.should.equal(TEST_OID);
              decoded.action.should.equal('upload');
              should.exist(decoded.iat);
              should.exist(decoded.exp);
          });
      });
  
      describe('#getDownloadAction()', () => {
          it('should return download action', () => {
              var action = store.getDownloadAction(TEST_USER, TEST_REPO, TEST_OID, 0);
              action.href.should.equal(`${BASE_URL}:${PORT}/${TEST_USER}/${TEST_REPO}/objects/${TEST_OID}`);
              should.exist(action.expires_at);
              should.exist(action.header);
              action.header['Authorization'].should.startWith('JWT ');
  
              let authorization = action.header['Authorization'];
              let token = authorization.substring(4, authorization.length);
              let decoded = jwt.verify(token, JWT_CONFIG.secret, { issuer: JWT_CONFIG.issuer });
              decoded.user.should.equal(TEST_USER);
              decoded.repo.should.equal(TEST_REPO);
              decoded.oid.should.equal(TEST_OID);
              decoded.action.should.equal('download');
              should.exist(decoded.iat);
              should.exist(decoded.exp);
          });
      });
  
      describe('#getVerifyAction()', () => {
          it('should return verify action', () => {
              var action = store.getVerifyAction(TEST_USER, TEST_REPO, TEST_OID, 0);
              action.href.should.equal(`${BASE_URL}:${PORT}/${TEST_USER}/${TEST_REPO}/objects/verify`);
              should.exist(action.expires_at);
              should.exist(action.header);
              action.header['Authorization'].should.startWith('JWT ');
  
              let authorization = action.header['Authorization'];
              let token = authorization.substring(4, authorization.length);
              let decoded = jwt.verify(token, JWT_CONFIG.secret, { issuer: JWT_CONFIG.issuer });
              decoded.user.should.equal(TEST_USER);
              decoded.repo.should.equal(TEST_REPO);
              decoded.action.should.equal('verify');
              should.exist(decoded.iat);
              should.exist(decoded.exp);
              should.not.exist(decoded.oid);
          });
      });
  });