github.com/sl1pm4t/consul@v1.4.5-0.20190325224627-74c31c540f9c/ui-v2/tests/unit/helpers/token/is-legacy-test.js (about) 1 import { isLegacy } from 'consul-ui/helpers/token/is-legacy'; 2 import { module, test } from 'qunit'; 3 4 module('Unit | Helper | token/is-legacy'); 5 6 test('it returns true if the token has a Legacy=true', function(assert) { 7 const actual = isLegacy([{ Legacy: true }]); 8 assert.ok(actual); 9 }); 10 test('it returns false if the token has a Legacy=false', function(assert) { 11 const actual = isLegacy([{ Legacy: false }]); 12 assert.notOk(actual); 13 }); 14 test('it returns true if the token has Rules', function(assert) { 15 const actual = isLegacy([{ Rules: 'some rules' }]); 16 assert.ok(actual); 17 }); 18 test('it returns false if the token has Rules but those rules are empty', function(assert) { 19 const actual = isLegacy([{ Rules: '' }]); 20 assert.notOk(actual); 21 }); 22 test('it returns false if the token has Rules but those rules is null', function(assert) { 23 const actual = isLegacy([{ Rules: null }]); 24 assert.notOk(actual); 25 }); 26 // passing arrays 27 test("it returns false if things don't have Legacy or Rules", function(assert) { 28 const actual = isLegacy([[{}, {}]]); 29 assert.notOk(actual); 30 }); 31 test('it returns true if the token has a Legacy=true', function(assert) { 32 const actual = isLegacy([[{}, { Legacy: true }]]); 33 assert.ok(actual); 34 }); 35 test('it returns false if the token has a Legacy=false', function(assert) { 36 const actual = isLegacy([[{}, { Legacy: false }]]); 37 assert.notOk(actual); 38 }); 39 test('it returns true if one token has Rules', function(assert) { 40 const actual = isLegacy([[{}, { Rules: 'some rules' }]]); 41 assert.ok(actual); 42 }); 43 test('it returns false if tokens have no Rules, or has Rules but those rules are empty', function(assert) { 44 const actual = isLegacy([[{}, { Rules: '' }]]); 45 assert.notOk(actual); 46 }); 47 test('it returns false if a token is marked as legacy, has Rules but those rules are empty', function(assert) { 48 // this may seem strange, but empty Rules should override Legacy, this only happens 49 // when a legacy token that has already been loaded has its rules wiped out 50 // WITHOUT then the ui refreshing 51 const actual = isLegacy([{ Legacy: true, Rules: '' }]); 52 assert.notOk(actual); 53 });