1
- import * as assert from 'assert'
2
1
import * as core from '@actions/core'
3
2
import * as fsHelper from '../lib/fs-helper'
4
3
import * as github from '@actions/github'
5
4
import * as inputHelper from '../lib/input-helper'
6
5
import * as path from 'path'
6
+ import * as workflowContextHelper from '../lib/workflow-context-helper'
7
7
import { IGitSourceSettings } from '../lib/git-source-settings'
8
8
9
9
const originalGitHubWorkspace = process . env [ 'GITHUB_WORKSPACE' ]
@@ -43,6 +43,11 @@ describe('input-helper tests', () => {
43
43
. spyOn ( fsHelper , 'directoryExistsSync' )
44
44
. mockImplementation ( ( path : string ) => path == gitHubWorkspace )
45
45
46
+ // Mock ./workflowContextHelper getOrganizationId()
47
+ jest
48
+ . spyOn ( workflowContextHelper , 'getOrganizationId' )
49
+ . mockImplementation ( ( ) => Promise . resolve ( 123456 ) )
50
+
46
51
// GitHub workspace
47
52
process . env [ 'GITHUB_WORKSPACE' ] = gitHubWorkspace
48
53
} )
@@ -67,8 +72,8 @@ describe('input-helper tests', () => {
67
72
jest . restoreAllMocks ( )
68
73
} )
69
74
70
- it ( 'sets defaults' , ( ) => {
71
- const settings : IGitSourceSettings = inputHelper . getInputs ( )
75
+ it ( 'sets defaults' , async ( ) => {
76
+ const settings : IGitSourceSettings = await inputHelper . getInputs ( )
72
77
expect ( settings ) . toBeTruthy ( )
73
78
expect ( settings . authToken ) . toBeFalsy ( )
74
79
expect ( settings . clean ) . toBe ( true )
@@ -82,11 +87,11 @@ describe('input-helper tests', () => {
82
87
expect ( settings . repositoryPath ) . toBe ( gitHubWorkspace )
83
88
} )
84
89
85
- it ( 'qualifies ref' , ( ) => {
90
+ it ( 'qualifies ref' , async ( ) => {
86
91
let originalRef = github . context . ref
87
92
try {
88
93
github . context . ref = 'some-unqualified-ref'
89
- const settings : IGitSourceSettings = inputHelper . getInputs ( )
94
+ const settings : IGitSourceSettings = await inputHelper . getInputs ( )
90
95
expect ( settings ) . toBeTruthy ( )
91
96
expect ( settings . commit ) . toBe ( '1234567890123456789012345678901234567890' )
92
97
expect ( settings . ref ) . toBe ( 'refs/heads/some-unqualified-ref' )
@@ -95,32 +100,42 @@ describe('input-helper tests', () => {
95
100
}
96
101
} )
97
102
98
- it ( 'requires qualified repo' , ( ) => {
103
+ it ( 'requires qualified repo' , async ( ) => {
99
104
inputs . repository = 'some-unqualified-repo'
100
- assert . throws ( ( ) => {
101
- inputHelper . getInputs ( )
102
- } , / I n v a l i d r e p o s i t o r y ' s o m e - u n q u a l i f i e d - r e p o ' / )
105
+ try {
106
+ await inputHelper . getInputs ( )
107
+ throw 'should not reach here'
108
+ } catch ( err ) {
109
+ expect ( `(${ ( err as any ) . message } ` ) . toMatch (
110
+ "Invalid repository 'some-unqualified-repo'"
111
+ )
112
+ }
103
113
} )
104
114
105
- it ( 'roots path' , ( ) => {
115
+ it ( 'roots path' , async ( ) => {
106
116
inputs . path = 'some-directory/some-subdirectory'
107
- const settings : IGitSourceSettings = inputHelper . getInputs ( )
117
+ const settings : IGitSourceSettings = await inputHelper . getInputs ( )
108
118
expect ( settings . repositoryPath ) . toBe (
109
119
path . join ( gitHubWorkspace , 'some-directory' , 'some-subdirectory' )
110
120
)
111
121
} )
112
122
113
- it ( 'sets ref to empty when explicit sha' , ( ) => {
123
+ it ( 'sets ref to empty when explicit sha' , async ( ) => {
114
124
inputs . ref = '1111111111222222222233333333334444444444'
115
- const settings : IGitSourceSettings = inputHelper . getInputs ( )
125
+ const settings : IGitSourceSettings = await inputHelper . getInputs ( )
116
126
expect ( settings . ref ) . toBeFalsy ( )
117
127
expect ( settings . commit ) . toBe ( '1111111111222222222233333333334444444444' )
118
128
} )
119
129
120
- it ( 'sets sha to empty when explicit ref' , ( ) => {
130
+ it ( 'sets sha to empty when explicit ref' , async ( ) => {
121
131
inputs . ref = 'refs/heads/some-other-ref'
122
- const settings : IGitSourceSettings = inputHelper . getInputs ( )
132
+ const settings : IGitSourceSettings = await inputHelper . getInputs ( )
123
133
expect ( settings . ref ) . toBe ( 'refs/heads/some-other-ref' )
124
134
expect ( settings . commit ) . toBeFalsy ( )
125
135
} )
136
+
137
+ it ( 'sets workflow organization ID' , async ( ) => {
138
+ const settings : IGitSourceSettings = await inputHelper . getInputs ( )
139
+ expect ( settings . workflowOrganizationId ) . toBe ( 123456 )
140
+ } )
126
141
} )
0 commit comments