2018-09-25 16:28:26 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Unit | Service | auth', function (hooks) {
|
2018-09-25 16:28:26 +00:00
|
|
|
setupTest(hooks);
|
|
|
|
|
2018-10-02 13:53:39 +00:00
|
|
|
[
|
|
|
|
['#calculateExpiration w/ttl', { ttl: 30 }, 30],
|
|
|
|
['#calculateExpiration w/lease_duration', { ttl: 15 }, 15],
|
|
|
|
].forEach(([testName, response, ttlValue]) => {
|
2021-12-17 03:44:29 +00:00
|
|
|
test(testName, function (assert) {
|
2018-10-02 13:53:39 +00:00
|
|
|
let now = Date.now();
|
|
|
|
let service = this.owner.factoryFor('service:auth').create({
|
|
|
|
now() {
|
|
|
|
return now;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
let resp = service.calculateExpiration(response);
|
|
|
|
|
|
|
|
assert.equal(resp.ttl, ttlValue, 'returns the ttl');
|
|
|
|
assert.equal(
|
|
|
|
resp.tokenExpirationEpoch,
|
|
|
|
now + ttlValue * 1e3,
|
|
|
|
'calculates expiration from ttl as epoch timestamp'
|
|
|
|
);
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|