@@ -39,14 +39,13 @@ describe("changeset-bot", () => {
39
39
} ) ,
40
40
} ) ;
41
41
42
-
43
42
app = changesetBot . default ( probot )
44
43
45
44
// just return a test token
46
45
app . app = ( ) => "test.ts" ;
47
46
} ) ;
48
47
49
- it ( "should add a comment when there is no comment" , async ( ) => {
48
+ beforeEach ( ( ) => {
50
49
nock ( "https://raw.githubusercontent.com" )
51
50
. get ( "/changesets/bot/test/package.json" )
52
51
. reply ( 200 , { } )
@@ -65,22 +64,19 @@ describe("changeset-bot", () => {
65
64
. post ( "/app/installations/2462428/access_tokens" )
66
65
. reply ( 200 , [ ] )
67
66
68
- nock ( "https://api.github.com" )
69
- . get ( "/repos/pyu/testing-things/issues/1/comments" )
70
- . reply ( 200 , [ ] ) ;
67
+ } )
71
68
69
+ it ( "should add a comment when there is no comment" , async ( ) => {
72
70
nock ( "https://api.github.com" )
73
71
. get ( "/repos/changesets/bot/pulls/2/files" )
74
72
. reply ( 200 , [
75
73
{ filename : ".changeset/something/changes.md" , status : "added" }
76
74
] ) ;
77
75
78
- nock ( "https://api.github.com" )
79
- . get ( "/repos/pyu/testing-things/pulls/1/commits" )
80
- . reply ( 200 , [ { sha : "ABCDE" } ] ) ;
81
-
76
+ // checks and creates a comment
82
77
nock ( "https://api.github.com" )
83
78
. post ( "/repos/changesets/bot/issues/2/comments" , body => {
79
+ expect ( body . body ) . toContain ( "Changeset detected" )
84
80
expect ( body . comment_id ) . toBeUndefined ( )
85
81
return true ;
86
82
} )
@@ -93,33 +89,31 @@ describe("changeset-bot", () => {
93
89
} ) ;
94
90
95
91
it ( "should update a comment when there is a comment" , async ( ) => {
96
- nock ( "https://api.github.com" )
97
- . get ( "/repos/pyu/testing-things/issues/1/comments" )
98
- . reply ( 200 , [
99
- {
100
- id : 7 ,
101
- user : {
102
- login : "changeset-bot[bot]"
103
- }
104
- }
105
- ] ) ;
92
+ const commentId = 123
106
93
107
94
nock ( "https://api.github.com" )
108
- . get ( "/repos/pyu/testing-things /pulls/1 /files" )
109
- . reply ( 200 , [
110
- { filename : ".changeset/something/changes.md" , status : "added" }
111
- ] ) ;
95
+ . get ( "/repos/changesets/bot /pulls/2 /files" )
96
+ . reply ( 200 , [
97
+ { filename : ".changeset/something/changes.md" , status : "added" }
98
+ ] ) ;
112
99
100
+ // get comments for an issue
113
101
nock ( "https://api.github.com" )
114
- . get ( "/repos/pyu/testing-things/pulls/1/commits" )
115
- . reply ( 200 , [ { sha : "ABCDE" } ] ) ;
102
+ . get ( "/repos/changesets/bot/issues/2/comments" )
103
+ . reply ( 200 , [ {
104
+ id : commentId ,
105
+ user : {
106
+ login : "changeset-bot[bot]"
107
+ }
108
+ } ] ) ;
116
109
110
+ // update comments for an issue
117
111
nock ( "https://api.github.com" )
118
- . patch ( " /repos/pyu/testing-things /issues/comments/7" , body => {
119
- expect ( body . number ) . toBe ( 1 ) ;
120
- return true ;
121
- } )
122
- . reply ( 200 ) ;
112
+ . patch ( ` /repos/changesets/bot /issues/comments/${ commentId } ` , body => {
113
+ expect ( body . body ) . toContain ( "Changeset detected" )
114
+ return true ;
115
+ } )
116
+ . reply ( 200 ) ;
123
117
124
118
await probot . receive ( {
125
119
name : "pull_request" ,
0 commit comments