1
1
import * as github from '@actions/github'
2
- import type { RestEndpointMethods } from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/method-types'
3
2
import type { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/parameters-and-response-types'
4
3
import {
5
4
listArtifactsInternal ,
@@ -10,13 +9,13 @@ import {ArtifactServiceClientJSON, Timestamp} from '../src/generated'
10
9
import * as util from '../src/internal/shared/util'
11
10
import { noopLogs } from './common'
12
11
import { Artifact } from '../src/internal/shared/interfaces'
12
+ import { RequestInterface } from '@octokit/types'
13
13
14
- type MockedListWorkflowRunArtifacts = jest . MockedFunction <
15
- RestEndpointMethods [ 'actions' ] [ 'listWorkflowRunArtifacts' ]
16
- >
14
+ type MockedRequest = jest . MockedFunction < RequestInterface < object > >
17
15
18
16
jest . mock ( '@actions/github' , ( ) => ( {
19
17
getOctokit : jest . fn ( ) . mockReturnValue ( {
18
+ request : jest . fn ( ) ,
20
19
rest : {
21
20
actions : {
22
21
listWorkflowRunArtifacts : jest . fn ( )
@@ -81,10 +80,10 @@ describe('list-artifact', () => {
81
80
82
81
describe ( 'public' , ( ) => {
83
82
it ( 'should return a list of artifacts' , async ( ) => {
84
- const mockListArtifacts = github . getOctokit ( fixtures . token ) . rest . actions
85
- . listWorkflowRunArtifacts as MockedListWorkflowRunArtifacts
83
+ const mockRequest = github . getOctokit ( fixtures . token )
84
+ . request as MockedRequest
86
85
87
- mockListArtifacts . mockResolvedValueOnce ( {
86
+ mockRequest . mockResolvedValueOnce ( {
88
87
status : 200 ,
89
88
headers : { } ,
90
89
url : '' ,
@@ -105,10 +104,10 @@ describe('list-artifact', () => {
105
104
} )
106
105
107
106
it ( 'should return the latest artifact when latest is specified' , async ( ) => {
108
- const mockListArtifacts = github . getOctokit ( fixtures . token ) . rest . actions
109
- . listWorkflowRunArtifacts as MockedListWorkflowRunArtifacts
107
+ const mockRequest = github . getOctokit ( fixtures . token )
108
+ . request as MockedRequest
110
109
111
- mockListArtifacts . mockResolvedValueOnce ( {
110
+ mockRequest . mockResolvedValueOnce ( {
112
111
status : 200 ,
113
112
headers : { } ,
114
113
url : '' ,
@@ -129,10 +128,10 @@ describe('list-artifact', () => {
129
128
} )
130
129
131
130
it ( 'can return empty artifacts' , async ( ) => {
132
- const mockListArtifacts = github . getOctokit ( fixtures . token ) . rest . actions
133
- . listWorkflowRunArtifacts as MockedListWorkflowRunArtifacts
131
+ const mockRequest = github . getOctokit ( fixtures . token )
132
+ . request as MockedRequest
134
133
135
- mockListArtifacts . mockResolvedValueOnce ( {
134
+ mockRequest . mockResolvedValueOnce ( {
136
135
status : 200 ,
137
136
headers : { } ,
138
137
url : '' ,
@@ -156,10 +155,10 @@ describe('list-artifact', () => {
156
155
} )
157
156
158
157
it ( 'should fail if non-200 response' , async ( ) => {
159
- const mockListArtifacts = github . getOctokit ( fixtures . token ) . rest . actions
160
- . listWorkflowRunArtifacts as MockedListWorkflowRunArtifacts
158
+ const mockRequest = github . getOctokit ( fixtures . token )
159
+ . request as MockedRequest
161
160
162
- mockListArtifacts . mockRejectedValue ( new Error ( 'boom' ) )
161
+ mockRequest . mockRejectedValueOnce ( new Error ( 'boom' ) )
163
162
164
163
await expect (
165
164
listArtifactsPublic (
0 commit comments