|
1 | 1 | const TokenModel = require('../../../lib/models/token-model');
|
| 2 | +const InvalidArgumentError = require('../../../lib/errors/invalid-argument-error'); |
2 | 3 | const should = require('chai').should();
|
3 | 4 | /**
|
4 | 5 | * Test `Server`.
|
5 | 6 | */
|
6 | 7 |
|
7 | 8 | describe('Model', function() {
|
8 | 9 | describe('constructor()', function() {
|
| 10 | + it('throws, if data is empty', function () { |
| 11 | + try { |
| 12 | + new TokenModel(); |
| 13 | + should.fail(); |
| 14 | + } catch (e) { |
| 15 | + e.should.be.an.instanceOf(InvalidArgumentError); |
| 16 | + e.message.should.equal('Missing parameter: `accessToken`'); |
| 17 | + } |
| 18 | + }); |
| 19 | + it('throws, if `accessToken` is missing', function () { |
| 20 | + const atExpiresAt = new Date(); |
| 21 | + atExpiresAt.setHours(new Date().getHours() + 1); |
| 22 | + |
| 23 | + const data = { |
| 24 | + client: 'bar', |
| 25 | + user: 'tar', |
| 26 | + accessTokenExpiresAt: atExpiresAt |
| 27 | + }; |
| 28 | + |
| 29 | + try { |
| 30 | + new TokenModel(data); |
| 31 | + should.fail(); |
| 32 | + } catch (e) { |
| 33 | + e.should.be.an.instanceOf(InvalidArgumentError); |
| 34 | + e.message.should.equal('Missing parameter: `accessToken`'); |
| 35 | + } |
| 36 | + }); |
| 37 | + it('throws, if `client` is missing', function () { |
| 38 | + const atExpiresAt = new Date(); |
| 39 | + atExpiresAt.setHours(new Date().getHours() + 1); |
| 40 | + |
| 41 | + const data = { |
| 42 | + accessToken: 'foo', |
| 43 | + user: 'tar', |
| 44 | + accessTokenExpiresAt: atExpiresAt |
| 45 | + }; |
| 46 | + |
| 47 | + try { |
| 48 | + new TokenModel(data); |
| 49 | + should.fail(); |
| 50 | + } catch (e) { |
| 51 | + e.should.be.an.instanceOf(InvalidArgumentError); |
| 52 | + e.message.should.equal('Missing parameter: `client`'); |
| 53 | + } |
| 54 | + }); |
| 55 | + it('throws, if `user` is missing', function () { |
| 56 | + const atExpiresAt = new Date(); |
| 57 | + atExpiresAt.setHours(new Date().getHours() + 1); |
| 58 | + |
| 59 | + const data = { |
| 60 | + accessToken: 'foo', |
| 61 | + client: 'bar', |
| 62 | + accessTokenExpiresAt: atExpiresAt |
| 63 | + }; |
| 64 | + |
| 65 | + try { |
| 66 | + new TokenModel(data); |
| 67 | + should.fail(); |
| 68 | + } catch (e) { |
| 69 | + e.should.be.an.instanceOf(InvalidArgumentError); |
| 70 | + e.message.should.equal('Missing parameter: `user`'); |
| 71 | + } |
| 72 | + }); |
| 73 | + it('throws, if `accessTokenExpiresAt` is not a Date', function () { |
| 74 | + const data = { |
| 75 | + accessToken: 'foo', |
| 76 | + client: 'bar', |
| 77 | + user: 'tar', |
| 78 | + accessTokenExpiresAt: '11/10/2023' |
| 79 | + }; |
| 80 | + |
| 81 | + try { |
| 82 | + new TokenModel(data); |
| 83 | + should.fail(); |
| 84 | + } catch (e) { |
| 85 | + e.should.be.an.instanceOf(InvalidArgumentError); |
| 86 | + e.message.should.equal('Invalid parameter: `accessTokenExpiresAt`'); |
| 87 | + } |
| 88 | + }); |
| 89 | + it('throws, if `refreshTokenExpiresAt` is not a Date', function () { |
| 90 | + const data = { |
| 91 | + accessToken: 'foo', |
| 92 | + client: 'bar', |
| 93 | + user: 'tar', |
| 94 | + refreshTokenExpiresAt: '11/10/2023' |
| 95 | + }; |
| 96 | + |
| 97 | + try { |
| 98 | + new TokenModel(data); |
| 99 | + should.fail(); |
| 100 | + } catch (e) { |
| 101 | + e.should.be.an.instanceOf(InvalidArgumentError); |
| 102 | + e.message.should.equal('Invalid parameter: `refreshTokenExpiresAt`'); |
| 103 | + } |
| 104 | + }); |
9 | 105 | it('should calculate `accessTokenLifetime` if `accessTokenExpiresAt` is set', function() {
|
10 | 106 | const atExpiresAt = new Date();
|
11 | 107 | atExpiresAt.setHours(new Date().getHours() + 1);
|
|
0 commit comments