11/**
22 * Unit tests for fetchSupportedScanFileNames.
33 *
4- * Purpose:
5- * Tests fetching supported manifest file names for scanning. Validates which files Socket can analyze.
6- *
7- * Test Coverage:
8- * - Successful API operation
9- * - SDK setup failure handling
10- * - API call error scenarios
11- * - Custom SDK options (API tokens, base URLs)
12- * - Supported file types
13- * - Ecosystem detection
14- * - Null prototype usage for security
15- *
16- * Testing Approach:
17- * Uses SDK test helpers to mock Socket API interactions. Validates comprehensive
18- * error handling and API integration.
19- *
20- * Related Files:
21- * - src/commands/SupportedScanFileNames.mts (implementation)
4+ * Tests fetching supported manifest file names for scanning.
5+ * Validates which files Socket can analyze via the SDK v4 getSupportedFiles API.
226 */
237
248import { describe , expect , it , vi } from 'vitest'
@@ -51,13 +35,13 @@ describe('fetchSupportedScanFileNames', () => {
5135 }
5236
5337 const { mockHandleApi, mockSdk } = await setupSdkMockSuccess (
54- 'getSupportedScanFiles ' ,
38+ 'getSupportedFiles ' ,
5539 mockData ,
5640 )
5741
58- const result = await fetchSupportedScanFileNames ( )
42+ const result = await fetchSupportedScanFileNames ( { orgSlug : 'test-org' } )
5943
60- expect ( mockSdk . getSupportedScanFiles ) . toHaveBeenCalledWith ( )
44+ expect ( mockSdk . getSupportedFiles ) . toHaveBeenCalledWith ( 'test-org' )
6145 expect ( mockHandleApi ) . toHaveBeenCalledWith ( expect . any ( Promise ) , {
6246 description : 'supported scan file types' ,
6347 } )
@@ -74,7 +58,7 @@ describe('fetchSupportedScanFileNames', () => {
7458 cause : 'Invalid configuration' ,
7559 } )
7660
77- const result = await fetchSupportedScanFileNames ( )
61+ const result = await fetchSupportedScanFileNames ( { orgSlug : 'test-org' } )
7862
7963 expect ( result . ok ) . toBe ( false )
8064 expect ( result . message ) . toBe ( 'Failed to setup SDK' )
@@ -85,9 +69,9 @@ describe('fetchSupportedScanFileNames', () => {
8569 const { fetchSupportedScanFileNames } =
8670 await import ( '../../../../../src/commands/scan/fetch-supported-scan-file-names.mts' )
8771
88- await setupSdkMockError ( 'getSupportedScanFiles ' , 'API error' , 500 )
72+ await setupSdkMockError ( 'getSupportedFiles ' , 'API error' , 500 )
8973
90- const result = await fetchSupportedScanFileNames ( )
74+ const result = await fetchSupportedScanFileNames ( { orgSlug : 'test-org' } )
9175
9276 expect ( result . ok ) . toBe ( false )
9377 expect ( result . code ) . toBe ( 500 )
@@ -98,29 +82,31 @@ describe('fetchSupportedScanFileNames', () => {
9882 await import ( '../../../../../src/commands/scan/fetch-supported-scan-file-names.mts' )
9983
10084 const { mockSdk, mockSetupSdk } = await setupSdkMockSuccess (
101- 'getSupportedScanFiles ' ,
85+ 'getSupportedFiles ' ,
10286 { } ,
10387 )
10488
105- const options = {
89+ await fetchSupportedScanFileNames ( {
90+ orgSlug : 'my-org' ,
10691 sdkOpts : {
10792 apiToken : 'custom-token' ,
10893 baseUrl : 'https://api.example.com' ,
10994 } ,
110- }
111-
112- await fetchSupportedScanFileNames ( options )
95+ } )
11396
114- expect ( mockSetupSdk ) . toHaveBeenCalledWith ( options . sdkOpts )
115- expect ( mockSdk . getSupportedScanFiles ) . toHaveBeenCalledWith ( )
97+ expect ( mockSetupSdk ) . toHaveBeenCalledWith ( {
98+ apiToken : 'custom-token' ,
99+ baseUrl : 'https://api.example.com' ,
100+ } )
101+ expect ( mockSdk . getSupportedFiles ) . toHaveBeenCalledWith ( 'my-org' )
116102 } )
117103
118104 it ( 'passes custom spinner' , async ( ) => {
119105 const { fetchSupportedScanFileNames } =
120106 await import ( '../../../../../src/commands/scan/fetch-supported-scan-file-names.mts' )
121107
122108 const { mockHandleApi } = await setupSdkMockSuccess (
123- 'getSupportedScanFiles ' ,
109+ 'getSupportedFiles ' ,
124110 { } ,
125111 )
126112
@@ -131,11 +117,7 @@ describe('fetchSupportedScanFileNames', () => {
131117 fail : vi . fn ( ) ,
132118 }
133119
134- const options = {
135- spinner : mockSpinner ,
136- }
137-
138- await fetchSupportedScanFileNames ( options )
120+ await fetchSupportedScanFileNames ( { orgSlug : 'test-org' , spinner : mockSpinner } )
139121
140122 expect ( mockHandleApi ) . toHaveBeenCalledWith ( expect . any ( Promise ) , {
141123 description : 'supported scan file types' ,
@@ -147,76 +129,28 @@ describe('fetchSupportedScanFileNames', () => {
147129 const { fetchSupportedScanFileNames } =
148130 await import ( '../../../../../src/commands/scan/fetch-supported-scan-file-names.mts' )
149131
150- await setupSdkMockSuccess ( 'getSupportedScanFiles ' , {
132+ await setupSdkMockSuccess ( 'getSupportedFiles ' , {
151133 supportedFiles : [ ] ,
152134 ecosystems : [ ] ,
153135 } )
154136
155- const result = await fetchSupportedScanFileNames ( )
137+ const result = await fetchSupportedScanFileNames ( { orgSlug : 'test-org' } )
156138
157139 expect ( result . ok ) . toBe ( true )
158140 expect ( result . data ?. supportedFiles ) . toEqual ( [ ] )
159141 expect ( result . data ?. ecosystems ) . toEqual ( [ ] )
160142 } )
161143
162- it ( 'handles comprehensive file types' , async ( ) => {
163- const { fetchSupportedScanFileNames } =
164- await import ( '../../../../../src/commands/scan/fetch-supported-scan-file-names.mts' )
165-
166- const comprehensiveFiles = [
167- // JavaScript/Node.js
168- 'package.json' ,
169- 'package-lock.json' ,
170- 'yarn.lock' ,
171- 'pnpm-lock.yaml' ,
172- // PHP
173- 'composer.json' ,
174- 'composer.lock' ,
175- // Ruby
176- 'Gemfile' ,
177- 'Gemfile.lock' ,
178- // Python
179- 'requirements.txt' ,
180- 'Pipfile' ,
181- 'Pipfile.lock' ,
182- 'poetry.lock' ,
183- 'pyproject.toml' ,
184- // Go
185- 'go.mod' ,
186- 'go.sum' ,
187- // Java
188- 'pom.xml' ,
189- 'build.gradle' ,
190- // .NET
191- 'packages.config' ,
192- '*.csproj' ,
193- // Rust
194- 'Cargo.toml' ,
195- 'Cargo.lock' ,
196- ]
197-
198- await setupSdkMockSuccess ( 'getSupportedScanFiles' , {
199- supportedFiles : comprehensiveFiles ,
200- } )
201-
202- const result = await fetchSupportedScanFileNames ( )
203-
204- expect ( result . ok ) . toBe ( true )
205- expect ( result . data ?. supportedFiles ) . toContain ( 'package.json' )
206- expect ( result . data ?. supportedFiles ) . toContain ( 'Cargo.toml' )
207- expect ( result . data ?. supportedFiles ) . toContain ( 'pom.xml' )
208- } )
209-
210- it ( 'works without options parameter' , async ( ) => {
144+ it ( 'works with orgSlug provided' , async ( ) => {
211145 const { fetchSupportedScanFileNames } =
212146 await import ( '../../../../../src/commands/scan/fetch-supported-scan-file-names.mts' )
213147
214148 const { mockHandleApi, mockSetupSdk } = await setupSdkMockSuccess (
215- 'getSupportedScanFiles ' ,
149+ 'getSupportedFiles ' ,
216150 { supportedFiles : [ 'package.json' ] } ,
217151 )
218152
219- const result = await fetchSupportedScanFileNames ( )
153+ const result = await fetchSupportedScanFileNames ( { orgSlug : 'test-org' } )
220154
221155 expect ( mockSetupSdk ) . toHaveBeenCalledWith ( undefined )
222156 expect ( mockHandleApi ) . toHaveBeenCalledWith ( expect . any ( Promise ) , {
@@ -230,12 +164,10 @@ describe('fetchSupportedScanFileNames', () => {
230164 const { fetchSupportedScanFileNames } =
231165 await import ( '../../../../../src/commands/scan/fetch-supported-scan-file-names.mts' )
232166
233- const { mockSdk } = await setupSdkMockSuccess ( 'getSupportedScanFiles ' , { } )
167+ const { mockSdk } = await setupSdkMockSuccess ( 'getSupportedFiles ' , { } )
234168
235- // This tests that the function properly uses __proto__: null.
236- await fetchSupportedScanFileNames ( )
169+ await fetchSupportedScanFileNames ( { orgSlug : 'test-org' } )
237170
238- // The function should work without prototype pollution issues.
239- expect ( mockSdk . getSupportedScanFiles ) . toHaveBeenCalled ( )
171+ expect ( mockSdk . getSupportedFiles ) . toHaveBeenCalled ( )
240172 } )
241173} )
0 commit comments