-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Patrick Ammann
committed
Jul 13, 2021
1 parent
8aece4e
commit e9f2908
Showing
19 changed files
with
1,240 additions
and
988 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
import { AccessTokenEvents } from '../../src/AccessTokenEvents'; | ||
import { Timer } from '../../src/Timer'; | ||
import { User } from '../../src/User'; | ||
|
||
describe("AccessTokenEvents", () => { | ||
|
||
let subject: AccessTokenEvents; | ||
let accessTokenExpiringTimer: StubTimer; | ||
let accessTokenExpiredTimer: StubTimer; | ||
|
||
beforeEach(() => { | ||
accessTokenExpiringTimer = new StubTimer("stub expiring timer"); | ||
accessTokenExpiredTimer = new StubTimer("stub expired timer"); | ||
subject = new AccessTokenEvents({ | ||
accessTokenExpiringTimer, accessTokenExpiredTimer | ||
}); | ||
}); | ||
|
||
/* TODO: port-ts | ||
describe("constructor", () => { | ||
it("should use default expiringNotificationTime", () => { | ||
subject._accessTokenExpiringNotificationTime.should.equal(60); | ||
}); | ||
});*/ | ||
|
||
describe("load", () => { | ||
|
||
it("should cancel existing timers", () => { | ||
// act | ||
subject.load({} as User); | ||
|
||
// assert | ||
expect(accessTokenExpiringTimer.cancelWasCalled).toBe(true); | ||
expect(accessTokenExpiredTimer.cancelWasCalled).toBe(true); | ||
}); | ||
|
||
it("should initialize timers", () => { | ||
// act | ||
subject.load({ | ||
access_token:"token", | ||
expires_in : 70 | ||
} as User); | ||
|
||
// assert | ||
expect(accessTokenExpiringTimer.duration).toBe(10); | ||
expect(accessTokenExpiredTimer.duration).toBe(71); | ||
}); | ||
|
||
it("should immediately schedule expiring timer if expiration is soon", () => { | ||
// act | ||
subject.load({ | ||
access_token:"token", | ||
expires_in : 10 | ||
} as User); | ||
|
||
// assert | ||
expect(accessTokenExpiringTimer.duration).toBe(1); | ||
}); | ||
|
||
it("should not initialize expiring timer if already expired", () => { | ||
// act | ||
subject.load({ | ||
access_token:"token", | ||
expires_in : 0 | ||
} as User); | ||
|
||
// assert | ||
expect(accessTokenExpiringTimer.duration).toBe(undefined); | ||
}); | ||
|
||
it("should initialize expired timer if already expired", () => { | ||
// act | ||
subject.load({ | ||
access_token:"token", | ||
expires_in : 0 | ||
} as User); | ||
|
||
// assert | ||
expect(accessTokenExpiredTimer.duration).toBe(1); | ||
}); | ||
|
||
it("should not initialize timers if no access token", () => { | ||
// act | ||
subject.load({ | ||
expires_in : 70 | ||
} as User); | ||
|
||
// assert | ||
expect(accessTokenExpiringTimer.duration).toBe(undefined); | ||
expect(accessTokenExpiredTimer.duration).toBe(undefined); | ||
}); | ||
|
||
it("should not initialize timers if no expiration on access token", () => { | ||
// act | ||
subject.load({ | ||
access_token:"token" | ||
} as User); | ||
|
||
// assert | ||
expect(accessTokenExpiringTimer.duration).toBe(undefined); | ||
expect(accessTokenExpiredTimer.duration).toBe(undefined); | ||
}); | ||
}); | ||
|
||
describe("unload", () => { | ||
|
||
it("should cancel timers", () => { | ||
// act | ||
subject.unload(); | ||
|
||
// assert | ||
expect(accessTokenExpiringTimer.cancelWasCalled).toBe(true); | ||
expect(accessTokenExpiredTimer.cancelWasCalled).toBe(true); | ||
}); | ||
}); | ||
}); | ||
|
||
class StubTimer extends Timer { | ||
cancelWasCalled: boolean; | ||
duration: any; | ||
|
||
constructor(name: string) { | ||
super(name) | ||
this.cancelWasCalled = false; | ||
} | ||
|
||
init(duration: number) { | ||
this.duration = duration; | ||
} | ||
|
||
cancel() { | ||
this.cancelWasCalled = true; | ||
} | ||
|
||
addHandler() {} | ||
removeHandler() {} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.