@@ -4,7 +4,7 @@ import nock from 'nock';
44import { mockAccounts } from '../__mocks__/mock-state' ;
55import { mockedSingleNotification } from '../__mocks__/mockedData' ;
66import {
7- getCheckSuiteState ,
7+ getCheckSuiteAttributes ,
88 getDiscussionState ,
99 getIssueState ,
1010 getPullRequestState ,
@@ -26,9 +26,12 @@ describe('utils/state.ts', () => {
2626 } ,
2727 } ;
2828
29- const result = getCheckSuiteState ( mockNotification ) ;
29+ const result = getCheckSuiteAttributes ( mockNotification ) ;
3030
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' ) ;
3235 } ) ;
3336
3437 it ( 'failed check suite state' , async ( ) => {
@@ -40,9 +43,29 @@ describe('utils/state.ts', () => {
4043 } ,
4144 } ;
4245
43- const result = getCheckSuiteState ( mockNotification ) ;
46+ const result = getCheckSuiteAttributes ( mockNotification ) ;
4447
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' ) ;
4669 } ) ;
4770
4871 it ( 'skipped check suite state' , async ( ) => {
@@ -54,9 +77,12 @@ describe('utils/state.ts', () => {
5477 } ,
5578 } ;
5679
57- const result = getCheckSuiteState ( mockNotification ) ;
80+ const result = getCheckSuiteAttributes ( mockNotification ) ;
5881
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' ) ;
6086 } ) ;
6187
6288 it ( 'successful check suite state' , async ( ) => {
@@ -68,21 +94,41 @@ describe('utils/state.ts', () => {
6894 } ,
6995 } ;
7096
71- const result = getCheckSuiteState ( mockNotification ) ;
97+ const result = getCheckSuiteAttributes ( mockNotification ) ;
7298
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' ) ;
74103 } ) ;
75104
76105 it ( 'unknown check suite state' , async ( ) => {
77106 const mockNotification = {
78107 ...mockedSingleNotification ,
79108 subject : {
80109 ...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' ,
82128 } ,
83129 } ;
84130
85- const result = getCheckSuiteState ( mockNotification ) ;
131+ const result = getCheckSuiteAttributes ( mockNotification ) ;
86132
87133 expect ( result ) . toBeNull ( ) ;
88134 } ) ;
0 commit comments