arnaucube
arnaucube/thoughtsPublic Self-hosted repository
thoughts/node_modules/jsonwebtoken/test/non_object_values.tests.js
node_modules/jsonwebtoken/test/non_object_values.tests.jsRaw
 1var jwt = require('../index');
 2var expect = require('chai').expect;
 3var JsonWebTokenError = require('../lib/JsonWebTokenError');
 4
 5describe('non_object_values values', function() {
 6
 7  it('should work with string', function () {
 8    var token = jwt.sign('hello', '123');
 9    var result = jwt.verify(token, '123');
10    expect(result).to.equal('hello');
11  });
12
13  //v6 version will throw in this case:
14  it('should throw with expiresIn', function () {
15    expect(function () {
16      jwt.sign('hello', '123', { expiresIn: '12h' });
17    }).to.throw(/invalid expiresIn option for string payload/);
18  });
19
20  it('should fail to validate audience when the payload is string', function () {
21    var token = jwt.sign('hello', '123');
22    expect(function () {
23      jwt.verify(token, '123', { audience: 'foo' });
24    }).to.throw(JsonWebTokenError);
25  });
26
27  it('should work with number', function () {
28    var token = jwt.sign(123, '123');
29    var result = jwt.verify(token, '123');
30    expect(result).to.equal('123');
31  });
32
33});