Skip to content

Commit

Permalink
fixed failing passport tests (make test time independent)
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Oct 6, 2023
1 parent 8af4305 commit 3c446db
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/modules/passport/PassportResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export class PassportResolver {
return passportInfo._score;

// calculate score
let now = Math.floor((new Date()).getTime() / 1000);
let now = this.getVerifyTime();
let totalScore = 0;
if(passportInfo.found && passportInfo.stamps) {
passportInfo.stamps.forEach((stamp) => {
Expand Down
7 changes: 7 additions & 0 deletions tests/modules/PassportModule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe("Faucet module: passport", () => {
globalStubs["fetch"].returns(returnDelayedPromise(true, {
json: () => Promise.resolve((testData as any).testPassport1Rsp)
}));
globalStubs["PassportResolver.getVerifyTime"] = sinon.stub(PassportResolver.prototype as any, "getVerifyTime").returns(1686844923);
await ServiceManager.GetService(ModuleManager).initialize();
let sessionManager = ServiceManager.GetService(SessionManager);
let testSession = await sessionManager.createSession("::ffff:8.8.8.8", {
Expand Down Expand Up @@ -138,6 +139,7 @@ describe("Faucet module: passport", () => {
globalStubs["fetch"].returns(returnDelayedPromise(true, {
json: () => Promise.resolve((testData as any).testPassport1Rsp)
}));
globalStubs["PassportResolver.getVerifyTime"] = sinon.stub(PassportResolver.prototype as any, "getVerifyTime").returns(1686844923);
await ServiceManager.GetService(ModuleManager).initialize();
ServiceManager.GetService(ModuleManager).addActionHook(null, ModuleHookAction.SessionStart, 100, "test-task", (session: FaucetSession, userInput: any) => {
session.addBlockingTask("test", "test", 1);
Expand Down Expand Up @@ -168,6 +170,7 @@ describe("Faucet module: passport", () => {
globalStubs["fetch"].returns(returnDelayedPromise(true, {
json: () => Promise.resolve((testData as any).testPassport1Rsp)
}));
globalStubs["PassportResolver.getVerifyTime"] = sinon.stub(PassportResolver.prototype as any, "getVerifyTime").returns(1686844923);
await ServiceManager.GetService(ModuleManager).initialize();
ServiceManager.GetService(ModuleManager).addActionHook(null, ModuleHookAction.SessionStart, 100, "test-task", (session: FaucetSession, userInput: any) => {
session.addBlockingTask("test", "test", 1);
Expand Down Expand Up @@ -269,6 +272,7 @@ describe("Faucet module: passport", () => {
globalStubs["fetch"].returns(returnDelayedPromise(true, {
json: () => Promise.resolve((testData as any).testPassport1Rsp)
}));
globalStubs["PassportResolver.getVerifyTime"] = sinon.stub(PassportResolver.prototype as any, "getVerifyTime").returns(1686844923);
await ServiceManager.GetService(ModuleManager).initialize();
let sessionManager = ServiceManager.GetService(SessionManager);
let testSession = await sessionManager.createSession("::ffff:8.8.8.8", {
Expand Down Expand Up @@ -306,6 +310,7 @@ describe("Faucet module: passport", () => {
globalStubs["fetch"].returns(returnDelayedPromise(true, {
json: () => Promise.resolve((testData as any).testPassport1Rsp)
}));
globalStubs["PassportResolver.getVerifyTime"] = sinon.stub(PassportResolver.prototype as any, "getVerifyTime").returns(1686844923);
await ServiceManager.GetService(ModuleManager).initialize();
let sessionManager = ServiceManager.GetService(SessionManager);
let testSession = await sessionManager.createSession("::ffff:8.8.8.8", {
Expand Down Expand Up @@ -343,6 +348,7 @@ describe("Faucet module: passport", () => {
globalStubs["fetch"].returns(returnDelayedPromise(true, {
json: () => Promise.resolve((testData as any).testPassport1Rsp)
}));
globalStubs["PassportResolver.getVerifyTime"] = sinon.stub(PassportResolver.prototype as any, "getVerifyTime").returns(1686844923);
await ServiceManager.GetService(ModuleManager).initialize();
let sessionManager = ServiceManager.GetService(SessionManager);
let [testSession] = await Promise.all([
Expand Down Expand Up @@ -391,6 +397,7 @@ describe("Faucet module: passport", () => {
globalStubs["fetch"].returns(returnDelayedPromise(true, {
json: () => Promise.resolve((testData as any).testPassport1Rsp)
}));
globalStubs["PassportResolver.getVerifyTime"] = sinon.stub(PassportResolver.prototype as any, "getVerifyTime").returns(1686844923);
let passportRefreshRsp = await ServiceManager.GetService(FaucetWebApi).onApiRequest({
method: "GET",
url: "/api/refreshPassport?session=" + testSession.getSessionId(),
Expand Down

0 comments on commit 3c446db

Please sign in to comment.