-
Notifications
You must be signed in to change notification settings - Fork 172
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
1 parent
43a2bbc
commit 6b71476
Showing
2 changed files
with
45 additions
and
2 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
38 changes: 38 additions & 0 deletions
38
packages/agents/watcher/test/operations/validateAndSwitch.spec.ts
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,38 @@ | ||
import { BaseRequestContext, createRequestContext, expect, mkHash } from "@connext/nxtp-utils"; | ||
import { PauseResponse, ReportEventType } from "@connext/nxtp-adapters-watcher"; | ||
import { stub, SinonStub } from "sinon"; | ||
import * as validateAndSwitchFns from "../../src/operations/validateAndSwitch"; | ||
import { ctxMock } from "../globalTestHook"; | ||
|
||
const requestContext = createRequestContext("test"); | ||
|
||
describe("Operations:validateAndSwitch", () => { | ||
describe("validateAndSwitch", () => { | ||
let validateAndSwitchStub: SinonStub< | ||
[requestContext: BaseRequestContext, reason: string], | ||
Promise<PauseResponse[]> | ||
>; | ||
beforeEach(() => { | ||
validateAndSwitchStub = stub(validateAndSwitchFns, "switchAndAlert").resolves(); | ||
}); | ||
|
||
it("should not call switchAndAlert if it doesnt need pause", async () => { | ||
(ctxMock.adapters.monitor.validateProposal as SinonStub).resolves({ needsSwitch: false }); | ||
await validateAndSwitchFns.validateAndSwitch(); | ||
expect(validateAndSwitchStub.callCount).to.be.eq(0); | ||
}); | ||
|
||
it("should call switchAndAlert if needs pause", async () => { | ||
(ctxMock.adapters.monitor.validateProposal as SinonStub).resolves({ needsSwitch: true }); | ||
await validateAndSwitchFns.validateAndSwitch(); | ||
expect(validateAndSwitchStub).to.have.been.calledOnce; | ||
}); | ||
}); | ||
|
||
describe("switchAndAlert", () => { | ||
it("should switch and alert", async () => { | ||
await validateAndSwitchFns.switchAndAlert(requestContext, "reason"); | ||
expect(ctxMock.adapters.watcher.alert).to.be.calledOnce; | ||
}); | ||
}); | ||
}); |