@@ -4,7 +4,7 @@ import nock from 'nock';
4
4
import { mockAccounts } from '../__mocks__/mock-state' ;
5
5
import { mockedSingleNotification } from '../__mocks__/mockedData' ;
6
6
import {
7
- getCheckSuiteState ,
7
+ getCheckSuiteAttributes ,
8
8
getDiscussionState ,
9
9
getIssueState ,
10
10
getPullRequestState ,
@@ -26,9 +26,12 @@ describe('utils/state.ts', () => {
26
26
} ,
27
27
} ;
28
28
29
- const result = getCheckSuiteState ( mockNotification ) ;
29
+ const result = getCheckSuiteAttributes ( mockNotification ) ;
30
30
31
- expect ( result ) . toBe ( 'cancelled' ) ;
31
+ expect ( result . workflowName ) . toBe ( 'Demo' ) ;
32
+ expect ( result . attemptNumber ) . toBeNull ( ) ;
33
+ expect ( result . status ) . toBe ( 'cancelled' ) ;
34
+ expect ( result . branchName ) . toBe ( 'main' ) ;
32
35
} ) ;
33
36
34
37
it ( 'failed check suite state' , async ( ) => {
@@ -40,9 +43,29 @@ describe('utils/state.ts', () => {
40
43
} ,
41
44
} ;
42
45
43
- const result = getCheckSuiteState ( mockNotification ) ;
46
+ const result = getCheckSuiteAttributes ( mockNotification ) ;
44
47
45
- expect ( result ) . toBe ( 'failure' ) ;
48
+ expect ( result . workflowName ) . toBe ( 'Demo' ) ;
49
+ expect ( result . attemptNumber ) . toBeNull ( ) ;
50
+ expect ( result . status ) . toBe ( 'failure' ) ;
51
+ expect ( result . branchName ) . toBe ( 'main' ) ;
52
+ } ) ;
53
+
54
+ it ( 'multiple attempts failed check suite state' , async ( ) => {
55
+ const mockNotification = {
56
+ ...mockedSingleNotification ,
57
+ subject : {
58
+ ...mockedSingleNotification . subject ,
59
+ title : 'Demo workflow run, Attempt #3 failed for main branch' ,
60
+ } ,
61
+ } ;
62
+
63
+ const result = getCheckSuiteAttributes ( mockNotification ) ;
64
+
65
+ expect ( result . workflowName ) . toBe ( 'Demo' ) ;
66
+ expect ( result . attemptNumber ) . toBe ( 3 ) ;
67
+ expect ( result . status ) . toBe ( 'failure' ) ;
68
+ expect ( result . branchName ) . toBe ( 'main' ) ;
46
69
} ) ;
47
70
48
71
it ( 'skipped check suite state' , async ( ) => {
@@ -54,9 +77,12 @@ describe('utils/state.ts', () => {
54
77
} ,
55
78
} ;
56
79
57
- const result = getCheckSuiteState ( mockNotification ) ;
80
+ const result = getCheckSuiteAttributes ( mockNotification ) ;
58
81
59
- expect ( result ) . toBe ( 'skipped' ) ;
82
+ expect ( result . workflowName ) . toBe ( 'Demo' ) ;
83
+ expect ( result . attemptNumber ) . toBeNull ( ) ;
84
+ expect ( result . status ) . toBe ( 'skipped' ) ;
85
+ expect ( result . branchName ) . toBe ( 'main' ) ;
60
86
} ) ;
61
87
62
88
it ( 'successful check suite state' , async ( ) => {
@@ -68,21 +94,41 @@ describe('utils/state.ts', () => {
68
94
} ,
69
95
} ;
70
96
71
- const result = getCheckSuiteState ( mockNotification ) ;
97
+ const result = getCheckSuiteAttributes ( mockNotification ) ;
72
98
73
- expect ( result ) . toBe ( 'success' ) ;
99
+ expect ( result . workflowName ) . toBe ( 'Demo' ) ;
100
+ expect ( result . attemptNumber ) . toBeNull ( ) ;
101
+ expect ( result . status ) . toBe ( 'success' ) ;
102
+ expect ( result . branchName ) . toBe ( 'main' ) ;
74
103
} ) ;
75
104
76
105
it ( 'unknown check suite state' , async ( ) => {
77
106
const mockNotification = {
78
107
...mockedSingleNotification ,
79
108
subject : {
80
109
...mockedSingleNotification . subject ,
81
- title : 'Demo workflow run for main branch' ,
110
+ title : 'Demo workflow run unknown-status for main branch' ,
111
+ } ,
112
+ } ;
113
+
114
+ const result = getCheckSuiteAttributes ( mockNotification ) ;
115
+
116
+ expect ( result . workflowName ) . toBe ( 'Demo' ) ;
117
+ expect ( result . attemptNumber ) . toBeNull ( ) ;
118
+ expect ( result . status ) . toBeNull ( ) ;
119
+ expect ( result . branchName ) . toBe ( 'main' ) ;
120
+ } ) ;
121
+
122
+ it ( 'unhandled check suite title' , async ( ) => {
123
+ const mockNotification = {
124
+ ...mockedSingleNotification ,
125
+ subject : {
126
+ ...mockedSingleNotification . subject ,
127
+ title : 'A title that is not in the structure we expect' ,
82
128
} ,
83
129
} ;
84
130
85
- const result = getCheckSuiteState ( mockNotification ) ;
131
+ const result = getCheckSuiteAttributes ( mockNotification ) ;
86
132
87
133
expect ( result ) . toBeNull ( ) ;
88
134
} ) ;
0 commit comments