Skip to content

Commit b8e334a

Browse files
committed
add tests for commands.logout() and commands.session()
1 parent c89c587 commit b8e334a

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

tests/__tests__/__snapshots__/commands.ts.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,20 @@ exports[`login() login() login success 1`] = `
99
"OK
1010
"
1111
`;
12+
13+
exports[`login() logout() logout 1`] = `
14+
"login session aborted.
15+
"
16+
`;
17+
18+
exports[`login() session() logged-in 1`] = `
19+
"check login status...
20+
OK
21+
"
22+
`;
23+
24+
exports[`login() session() not logged-in 1`] = `
25+
"check login status...
26+
not login
27+
"
28+
`;

tests/__tests__/commands.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { login } from "../../src/commands";
1+
import { login, logout, session } from "../../src/commands";
22
import { AtCoder } from "../../src/atcoder";
33
import { getAtCoder } from "../../src/di";
44
jest.mock("../../src/di");
@@ -34,4 +34,35 @@ describe("login()", () => {
3434
spy_console_log.mockRestore();
3535
})
3636
});
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+
});
3768
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy