|
1 |
| -import { login } from "../../src/commands"; |
| 1 | +import { login, logout, session } from "../../src/commands"; |
2 | 2 | import { AtCoder } from "../../src/atcoder";
|
3 | 3 | import { getAtCoder } from "../../src/di";
|
4 | 4 | jest.mock("../../src/di");
|
@@ -34,4 +34,35 @@ describe("login()", () => {
|
34 | 34 | spy_console_log.mockRestore();
|
35 | 35 | })
|
36 | 36 | });
|
| 37 | + describe("logout()", () => { |
| 38 | + test("logout", async () => { |
| 39 | + let log = ""; |
| 40 | + const spy_console_log = jest.spyOn(console, "log").mockImplementation(s => log += `${s}\n`); |
| 41 | + atcoder.logout = jest.fn(); |
| 42 | + |
| 43 | + await logout(); |
| 44 | + expect(log).toMatchSnapshot(); |
| 45 | + spy_console_log.mockRestore(); |
| 46 | + }) |
| 47 | + }); |
| 48 | + describe("session()", () => { |
| 49 | + test("logged-in", async () => { |
| 50 | + let log = ""; |
| 51 | + const spy_console_log = jest.spyOn(console, "log").mockImplementation(s => log += `${s}\n`); |
| 52 | + atcoder.checkSession = jest.fn(async () => true); |
| 53 | + |
| 54 | + await session(); |
| 55 | + expect(log).toMatchSnapshot(); |
| 56 | + spy_console_log.mockRestore(); |
| 57 | + }) |
| 58 | + test("not logged-in", async () => { |
| 59 | + let log = ""; |
| 60 | + const spy_console_log = jest.spyOn(console, "log").mockImplementation(s => log += `${s}\n`); |
| 61 | + atcoder.checkSession = jest.fn(async () => false); |
| 62 | + |
| 63 | + await session(); |
| 64 | + expect(log).toMatchSnapshot(); |
| 65 | + spy_console_log.mockRestore(); |
| 66 | + }) |
| 67 | + }); |
37 | 68 | });
|
0 commit comments