11jest . mock ( "danger" , ( ) => jest . fn ( ) )
2+ jest . mock ( "Asana" , ( ) => jest . fn ( ) )
23import danger from 'danger'
4+ import Asana from 'asana'
35const dm = danger as any ;
6+ const a = Asana as any ;
47
58import { internalLink } from '../org/allPRs'
69
@@ -11,17 +14,40 @@ beforeEach(() => {
1114 dm . danger = {
1215 github : {
1316 pr : {
14- body : 'task/issue url: https://app.asana.com/someurl /0001'
17+ body : 'task/issue url: https://app.asana.com/0 /0001/0002/f '
1518 }
1619 } ,
1720 }
21+
22+ a . ApiClient = {
23+ instance : {
24+ authentications : {
25+ token : {
26+ accessToken : '1234'
27+ }
28+ }
29+ }
30+ }
31+
32+ a . TasksApi = jest . fn ( ) . mockImplementation ( ( ) => {
33+ return {
34+ getTask : jest . fn ( ) . mockReturnValue ( {
35+ data : {
36+ projects : [
37+ { gid : '1234' } ,
38+ { gid : '0001' } ,
39+ ]
40+ }
41+ } )
42+ }
43+ } )
1844} )
1945
2046describe ( "Internal Asana link test" , ( ) => {
2147 it ( "does not fail when the description contains a link to Asana" , async ( ) => {
2248 await internalLink ( )
2349
24- expect ( dm . warn ) . not . toHaveBeenCalled ( )
50+ expect ( dm . fail ) . not . toHaveBeenCalled ( )
2551 } )
2652
2753 it ( "fails when the description doesn't contain a link to Asana" , async ( ) => {
@@ -31,4 +57,40 @@ describe("Internal Asana link test", () => {
3157
3258 expect ( dm . fail ) . toHaveBeenCalledWith ( "Please, don't forget to add a link to the internal task" )
3359 } )
60+
61+ it ( "fails when the description contains a malformed link to Asana" , async ( ) => {
62+ dm . danger . github . pr . body = 'task/issue url: https://app.asana.com/000010002/f'
63+
64+ await internalLink ( ) ;
65+
66+ expect ( dm . fail ) . toHaveBeenCalledWith ( "Please, don't forget to add a link to the internal task" )
67+ } )
68+
69+ it ( "fails when the description doesn't contain a line with task/issue URL" , async ( ) => {
70+ dm . danger . github . pr . body = 'sample random body'
71+
72+ await internalLink ( ) ;
73+
74+ expect ( dm . fail ) . toHaveBeenCalledWith ( "Please, don't forget to add a link to the internal task" )
75+ } )
76+
77+ it ( "does not fail when the description contains a link to Asana task in a correct project" , async ( ) => {
78+ process . env . ASANA_ACCESS_TOKEN = '1234'
79+ process . env . ASANA_PROJECT_ID = '0001'
80+ process . env . ASANA_PROJECT_NAME = 'macOS App Board'
81+
82+ await internalLink ( ) ;
83+
84+ expect ( dm . fail ) . not . toHaveBeenCalled ( )
85+ } )
86+
87+ it ( "fails when the description contains a link to Asana task not in a correct project" , async ( ) => {
88+ process . env . ASANA_ACCESS_TOKEN = '1234'
89+ process . env . ASANA_PROJECT_ID = '9999'
90+ process . env . ASANA_PROJECT_NAME = 'macOS App Board'
91+
92+ await internalLink ( ) ;
93+
94+ expect ( dm . fail ) . toHaveBeenCalledWith ( "Please ensure that the Asana task is added to macOS App Board project" )
95+ } )
3496} )
0 commit comments