@@ -17,6 +17,14 @@ Cookie.prototype.loadConfigFile = jest.fn(async function () {
17
17
Cookie . prototype . saveConfigFile = jest . fn ( async function ( ) {
18
18
} ) ;
19
19
20
+ // 標準入力を求めることなくログインを行う
21
+ const mockLogin = async ( atcoder : AtCoder ) => {
22
+ // ユーザー名とパスワードを標準入力で受け付けるかわりに、JSONファイルから取得した情報を流し込む
23
+ // @ts -ignore
24
+ inquirer . prompt . mockResolvedValueOnce ( { username, password} ) ;
25
+ return await atcoder . login ( ) ;
26
+ } ;
27
+
20
28
/*
21
29
このテストが失敗する場合、まず以下の点を確認してください
22
30
- __tests__/auth.json が存在し、正しいユーザー名とパスワードが記述されていること
@@ -28,49 +36,44 @@ test("AtCoder Login", async () => {
28
36
const atcoder = new AtCoder ( ) ;
29
37
expect ( await atcoder . checkSession ( ) ) . toBe ( false ) ;
30
38
31
- // ユーザー名とパスワードを標準入力で受け付けるかわりにファイルから流し込むようモックする
32
- // @ts -ignore
33
- inquirer . prompt . mockResolvedValueOnce ( { username, password} ) ;
34
-
35
- expect ( await atcoder . login ( ) ) . toBe ( true ) ;
39
+ expect ( await mockLogin ( atcoder ) ) . toBe ( true ) ;
36
40
expect ( await atcoder . checkSession ( true ) ) . toBe ( true ) ;
37
41
} ) ;
38
42
39
43
describe ( "AtCoder" , async ( ) => {
40
- let atcoder : AtCoder ;
41
- beforeEach ( async ( ) => {
42
- atcoder = new AtCoder ( ) ;
43
- // @ts -ignore
44
- inquirer . prompt . mockResolvedValueOnce ( { username, password} ) ;
45
- await atcoder . login ( ) ;
46
- } ) ;
47
- const contests = [ "abc101" , "arc101" ] ;
48
- describe ( "contest" , async ( ) => {
49
- test . each ( contests ) ( "%s" , async ( contest_id ) => {
50
- expect ( await atcoder . contest ( contest_id ) ) . toMatchSnapshot ( ) ;
51
- } ) ;
52
- test ( "invalid contest id" , async ( ) => {
53
- await expect ( atcoder . contest ( "abc0xx" ) ) . rejects . toThrow ( ) ;
54
- } ) ;
55
- } ) ;
56
- describe ( "tasks" , async ( ) => {
57
- test . each ( contests ) ( "%s" , async ( contest_id ) => {
58
- expect ( await atcoder . tasks ( contest_id ) ) . toMatchSnapshot ( ) ;
59
- } ) ;
60
- test ( "invalid contest id" , async ( ) => {
61
- await expect ( atcoder . tasks ( "abc0xx" ) ) . rejects . toThrow ( ) ;
62
- } ) ;
44
+ const atcoder = new AtCoder ( ) ;
45
+ beforeAll ( async ( ) => {
46
+ await mockLogin ( atcoder ) ;
63
47
} ) ;
64
- const tasks = [ [ "abc101" , "abc101_a" ] , [ "abc101" , "abc101_b" ] , [ "arc101" , "arc101_a" ] ] ;
65
- describe ( "task" , async ( ) => {
66
- test . each ( tasks ) ( "%s %s" , async ( contest_id , task_id ) => {
67
- expect ( await atcoder . task ( contest_id , task_id ) ) . toMatchSnapshot ( ) ;
48
+ describe ( "get contest and task information" , async ( ) => {
49
+ const contests = [ "abc101" , "arc101" ] ;
50
+ describe ( "contest" , async ( ) => {
51
+ test . each ( contests ) ( "%s" , async ( contest_id ) => {
52
+ expect ( await atcoder . contest ( contest_id ) ) . toMatchSnapshot ( ) ;
53
+ } ) ;
54
+ test ( "invalid contest id" , async ( ) => {
55
+ await expect ( atcoder . contest ( "abc0xx" ) ) . rejects . toThrow ( ) ;
56
+ } ) ;
68
57
} ) ;
69
- test ( "invalid contest id" , async ( ) => {
70
- await expect ( atcoder . task ( "abc0xx" , "abc0xx_z" ) ) . rejects . toThrow ( ) ;
58
+ describe ( "tasks" , async ( ) => {
59
+ test . each ( contests ) ( "%s" , async ( contest_id ) => {
60
+ expect ( await atcoder . tasks ( contest_id ) ) . toMatchSnapshot ( ) ;
61
+ } ) ;
62
+ test ( "invalid contest id" , async ( ) => {
63
+ await expect ( atcoder . tasks ( "abc0xx" ) ) . rejects . toThrow ( ) ;
64
+ } ) ;
71
65
} ) ;
72
- test ( "invalid task id" , async ( ) => {
73
- await expect ( atcoder . task ( "abc101" , "abc102_a" ) ) . rejects . toThrow ( ) ;
66
+ const tasks = [ [ "abc101" , "abc101_a" ] , [ "abc101" , "abc101_b" ] , [ "arc101" , "arc101_a" ] ] ;
67
+ describe ( "task" , async ( ) => {
68
+ test . each ( tasks ) ( "%s %s" , async ( contest_id , task_id ) => {
69
+ expect ( await atcoder . task ( contest_id , task_id ) ) . toMatchSnapshot ( ) ;
70
+ } ) ;
71
+ test ( "invalid contest id" , async ( ) => {
72
+ await expect ( atcoder . task ( "abc0xx" , "abc0xx_z" ) ) . rejects . toThrow ( ) ;
73
+ } ) ;
74
+ test ( "invalid task id" , async ( ) => {
75
+ await expect ( atcoder . task ( "abc101" , "abc102_a" ) ) . rejects . toThrow ( ) ;
76
+ } ) ;
74
77
} ) ;
75
78
} ) ;
76
79
} ) ;
0 commit comments