42d1047a74
* fix token expiration calculation * move authenticate to an ember concurrency task * don't show logged in nav while still on the auth route * move current tests to integration folder, add unit test for expiration calculation * fix auth form tests
30 lines
803 B
JavaScript
30 lines
803 B
JavaScript
import { module, test } from 'qunit';
|
|
import { setupTest } from 'ember-qunit';
|
|
|
|
module('Unit | Service | auth', function(hooks) {
|
|
setupTest(hooks);
|
|
|
|
[
|
|
['#calculateExpiration w/ttl', { ttl: 30 }, 30],
|
|
['#calculateExpiration w/lease_duration', { ttl: 15 }, 15],
|
|
].forEach(([testName, response, ttlValue]) => {
|
|
test(testName, function(assert) {
|
|
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'
|
|
);
|
|
});
|
|
});
|
|
});
|