const sinon = require('sinon');
const expect = require('chai').expect;
const assert = require('chai').assert;
const needle = require('needle');

const config = require('../config');
const validator = require('../lib/validator');
@@ -221,8 +221,978 @@
 dator');
+%0A%0Adescribe('API key and rate validation', function () %7B%0A    it('should return 401 if key is wrong', function()%7B%0A        process.env.CLIENT_KEYS = %5B'key1'%5D;%0A        var req = %7B%0A            query:%7B%0A                key:'wrong-key'%0A            %7D%0A        %7D;%0A        var res = %7Bstatus: function()%7B%7D,json: function()%7B%7D%7D;%0A        var json = sinon.spy(res, %22json%22);%0A        var status = sinon.spy(res, %22status%22);%0A        validator.validateKey(req,res);%0A        expect(res.status.args%5B0%5D).to.deep.equal(%5B401%5D);%0A        expect(res.json.args%5B0%5D).to.deep.equal(%5B%7B%0A            %22status%22: %22401%22,%0A            %22message%22: %22Invalid credentials%22%0A        %7D%5D);%0A    %7D);%0A    it('should call next if key is correct', function()%7B%0A        process.env.CLIENT_KEYS = %5B'key1'%5D;%0A        var req = %7B%0A            query:%7B%0A                key:'key1'%0A            %7D%0A        %7D;%0A        var next = sinon.spy();%0A        validator.validateKey(req, null, next);%0A        expect(next.called).to.be.true;%0A    %7D);%0A%7D);

Test cases for key validator