1
1
/* eslint-disable no-magic-numbers */
2
2
import nock from 'nock' ;
3
3
import path from 'path' ;
4
- import { Octokit } from '@octokit/rest' ;
5
4
import { Utils } from '../src' ;
6
5
import {
7
6
disableNetConnect ,
8
7
testEnv ,
9
8
getContext ,
10
9
getApiFixture ,
11
- createResponse ,
12
10
spyOnStdout ,
13
11
stdoutCalledWith ,
14
12
} from '@technote-space/github-action-test-helper' ;
13
+ import { GitCreateCommitResponseData } from '@octokit/types' ;
15
14
import { ApiHelper , Logger } from '../src' ;
16
15
17
16
const rootDir = path . resolve ( __dirname , 'fixtures' ) ;
@@ -33,7 +32,7 @@ const context = getContext({
33
32
const octokit = Utils . getOctokit ( 'test-token' ) ;
34
33
const logger = new Logger ( ) ;
35
34
36
- const createCommitResponse = createResponse < Octokit . GitCreateCommitResponse > ( {
35
+ const createCommitResponse : GitCreateCommitResponseData = {
37
36
author : {
38
37
date : '' ,
39
38
email : '' ,
@@ -54,13 +53,13 @@ const createCommitResponse = createResponse<Octokit.GitCreateCommitResponse>({
54
53
} ,
55
54
url : '' ,
56
55
verification : {
57
- payload : null ,
56
+ payload : '' ,
58
57
reason : '' ,
59
- signature : null ,
58
+ signature : '' ,
60
59
verified : true ,
61
60
} ,
62
- } ) ;
63
- const escape = value => encodeURIComponent ( value ) . replace ( new RegExp ( '%2F' , 'g' ) , '%252F' ) ;
61
+ } ;
62
+ const escape = value => encodeURIComponent ( value ) . replace ( new RegExp ( '%2F' , 'g' ) , '%252F' ) ;
64
63
65
64
describe ( 'ApiHelper' , ( ) => {
66
65
disableNetConnect ( nock ) ;
@@ -136,11 +135,9 @@ describe('ApiHelper', () => {
136
135
expect ( fn1 ) . toBeCalledTimes ( 1 ) ;
137
136
expect ( fn2 ) . toBeCalledTimes ( 1 ) ;
138
137
expect ( fn3 ) . toBeCalledTimes ( 1 ) ;
139
- expect ( tree ) . toHaveProperty ( 'status ' ) ;
138
+ expect ( tree ) . toHaveProperty ( 'sha ' ) ;
140
139
expect ( tree ) . toHaveProperty ( 'url' ) ;
141
- expect ( tree ) . toHaveProperty ( 'headers' ) ;
142
- expect ( tree ) . toHaveProperty ( 'data' ) ;
143
- expect ( tree . status ) . toBe ( 201 ) ;
140
+ expect ( tree ) . toHaveProperty ( 'tree' ) ;
144
141
} ) ;
145
142
} ) ;
146
143
@@ -161,19 +158,18 @@ describe('ApiHelper', () => {
161
158
return getApiFixture ( rootDir , 'repos.git.commits' ) ;
162
159
} ) ;
163
160
164
- const commit = await helper . createCommit ( 'test commit message' , createResponse < Octokit . GitCreateTreeResponse > ( {
161
+ const commit = await helper . createCommit ( 'test commit message' , {
165
162
sha : 'tree-sha' ,
166
163
tree : [ ] ,
167
164
url : '' ,
168
- } ) ) ;
165
+ } ) ;
169
166
170
167
expect ( fn1 ) . toBeCalledTimes ( 1 ) ;
171
168
expect ( fn2 ) . toBeCalledTimes ( 1 ) ;
172
- expect ( commit ) . toHaveProperty ( 'status' ) ;
169
+ expect ( commit ) . toHaveProperty ( 'sha' ) ;
170
+ expect ( commit ) . toHaveProperty ( 'author' ) ;
173
171
expect ( commit ) . toHaveProperty ( 'url' ) ;
174
- expect ( commit ) . toHaveProperty ( 'headers' ) ;
175
- expect ( commit ) . toHaveProperty ( 'data' ) ;
176
- expect ( commit . status ) . toBe ( 201 ) ;
172
+ expect ( commit ) . toHaveProperty ( 'tree' ) ;
177
173
} ) ;
178
174
179
175
it ( 'should create PR commit' , async ( ) => {
@@ -198,14 +194,17 @@ describe('ApiHelper', () => {
198
194
} ,
199
195
} ,
200
196
} ) , logger ) ;
201
- const commit = await helper . createCommit ( 'test commit message' , createResponse < Octokit . GitCreateTreeResponse > ( {
197
+ const commit = await helper . createCommit ( 'test commit message' , {
202
198
sha : 'tree-sha' ,
203
199
tree : [ ] ,
204
200
url : '' ,
205
- } ) ) ;
201
+ } ) ;
206
202
207
203
expect ( fn ) . toBeCalledTimes ( 1 ) ;
208
- expect ( commit . status ) . toBe ( 201 ) ;
204
+ expect ( commit ) . toHaveProperty ( 'sha' ) ;
205
+ expect ( commit ) . toHaveProperty ( 'author' ) ;
206
+ expect ( commit ) . toHaveProperty ( 'url' ) ;
207
+ expect ( commit ) . toHaveProperty ( 'tree' ) ;
209
208
} ) ;
210
209
} ) ;
211
210
0 commit comments