1- import * as assert from 'assert'
21import * as core from '@actions/core'
32import * as fsHelper from '../lib/fs-helper'
43import * as github from '@actions/github'
54import * as inputHelper from '../lib/input-helper'
65import * as path from 'path'
6+ import * as workflowContextHelper from '../lib/workflow-context-helper'
77import { IGitSourceSettings } from '../lib/git-source-settings'
88
99const originalGitHubWorkspace = process . env [ 'GITHUB_WORKSPACE' ]
@@ -43,6 +43,11 @@ describe('input-helper tests', () => {
4343 . spyOn ( fsHelper , 'directoryExistsSync' )
4444 . mockImplementation ( ( path : string ) => path == gitHubWorkspace )
4545
46+ // Mock ./workflowContextHelper getOrganizationId()
47+ jest
48+ . spyOn ( workflowContextHelper , 'getOrganizationId' )
49+ . mockImplementation ( ( ) => Promise . resolve ( 123456 ) )
50+
4651 // GitHub workspace
4752 process . env [ 'GITHUB_WORKSPACE' ] = gitHubWorkspace
4853 } )
@@ -67,8 +72,8 @@ describe('input-helper tests', () => {
6772 jest . restoreAllMocks ( )
6873 } )
6974
70- it ( 'sets defaults' , ( ) => {
71- const settings : IGitSourceSettings = inputHelper . getInputs ( )
75+ it ( 'sets defaults' , async ( ) => {
76+ const settings : IGitSourceSettings = await inputHelper . getInputs ( )
7277 expect ( settings ) . toBeTruthy ( )
7378 expect ( settings . authToken ) . toBeFalsy ( )
7479 expect ( settings . clean ) . toBe ( true )
@@ -82,11 +87,11 @@ describe('input-helper tests', () => {
8287 expect ( settings . repositoryPath ) . toBe ( gitHubWorkspace )
8388 } )
8489
85- it ( 'qualifies ref' , ( ) => {
90+ it ( 'qualifies ref' , async ( ) => {
8691 let originalRef = github . context . ref
8792 try {
8893 github . context . ref = 'some-unqualified-ref'
89- const settings : IGitSourceSettings = inputHelper . getInputs ( )
94+ const settings : IGitSourceSettings = await inputHelper . getInputs ( )
9095 expect ( settings ) . toBeTruthy ( )
9196 expect ( settings . commit ) . toBe ( '1234567890123456789012345678901234567890' )
9297 expect ( settings . ref ) . toBe ( 'refs/heads/some-unqualified-ref' )
@@ -95,32 +100,42 @@ describe('input-helper tests', () => {
95100 }
96101 } )
97102
98- it ( 'requires qualified repo' , ( ) => {
103+ it ( 'requires qualified repo' , async ( ) => {
99104 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+ }
103113 } )
104114
105- it ( 'roots path' , ( ) => {
115+ it ( 'roots path' , async ( ) => {
106116 inputs . path = 'some-directory/some-subdirectory'
107- const settings : IGitSourceSettings = inputHelper . getInputs ( )
117+ const settings : IGitSourceSettings = await inputHelper . getInputs ( )
108118 expect ( settings . repositoryPath ) . toBe (
109119 path . join ( gitHubWorkspace , 'some-directory' , 'some-subdirectory' )
110120 )
111121 } )
112122
113- it ( 'sets ref to empty when explicit sha' , ( ) => {
123+ it ( 'sets ref to empty when explicit sha' , async ( ) => {
114124 inputs . ref = '1111111111222222222233333333334444444444'
115- const settings : IGitSourceSettings = inputHelper . getInputs ( )
125+ const settings : IGitSourceSettings = await inputHelper . getInputs ( )
116126 expect ( settings . ref ) . toBeFalsy ( )
117127 expect ( settings . commit ) . toBe ( '1111111111222222222233333333334444444444' )
118128 } )
119129
120- it ( 'sets sha to empty when explicit ref' , ( ) => {
130+ it ( 'sets sha to empty when explicit ref' , async ( ) => {
121131 inputs . ref = 'refs/heads/some-other-ref'
122- const settings : IGitSourceSettings = inputHelper . getInputs ( )
132+ const settings : IGitSourceSettings = await inputHelper . getInputs ( )
123133 expect ( settings . ref ) . toBe ( 'refs/heads/some-other-ref' )
124134 expect ( settings . commit ) . toBeFalsy ( )
125135 } )
136+
137+ it ( 'sets workflow organization ID' , async ( ) => {
138+ const settings : IGitSourceSettings = await inputHelper . getInputs ( )
139+ expect ( settings . workflowOrganizationId ) . toBe ( 123456 )
140+ } )
126141} )
0 commit comments