Skip to content

Commit 4c20176

Browse files
committed
test: add coverage for createScanFromFilepaths method
- Add test for createScanFromFilepaths without issueRules - Add test for createScanFromFilepaths with issueRules option - Add error handling test for createScanFromFilepaths - Improves socket-sdk-class.ts coverage to 100% statements/lines
1 parent 329d407 commit 4c20176

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

test/socket-sdk-scanning.test.mts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,4 +481,59 @@ describe('SocketSdk - Scanning APIs', () => {
481481
expect(sbomData.components).toHaveLength(1)
482482
})
483483
})
484+
485+
describe('createScanFromFilepaths', () => {
486+
it('should create scan from filepaths without issueRules', async () => {
487+
nock('https://api.socket.dev').put('/v0/report/upload').reply(200, {
488+
id: 'report-123',
489+
status: 'complete',
490+
issues: [],
491+
})
492+
493+
const client = new SocketSdk('test-token')
494+
const res = await client.createScanFromFilepaths([packageJsonPath], {
495+
pathsRelativeTo: tempDir,
496+
})
497+
498+
expect(res.success).toBe(true)
499+
if (res.success) {
500+
expect(res.data.id).toBe('report-123')
501+
}
502+
})
503+
504+
it('should create scan from filepaths with issueRules', async () => {
505+
nock('https://api.socket.dev').put('/v0/report/upload').reply(200, {
506+
id: 'report-456',
507+
status: 'complete',
508+
issues: [],
509+
})
510+
511+
const client = new SocketSdk('test-token')
512+
const res = await client.createScanFromFilepaths([packageJsonPath], {
513+
issueRules: {
514+
'npm-install-scripts': false,
515+
'npm-outdated-dependency': true,
516+
},
517+
pathsRelativeTo: tempDir,
518+
})
519+
520+
expect(res.success).toBe(true)
521+
if (res.success) {
522+
expect(res.data.id).toBe('report-456')
523+
}
524+
})
525+
526+
it('should handle error in createScanFromFilepaths', async () => {
527+
nock('https://api.socket.dev')
528+
.put('/v0/report/upload')
529+
.reply(400, { error: { message: 'Invalid file format' } })
530+
531+
const client = new SocketSdk('test-token')
532+
const res = await client.createScanFromFilepaths([packageJsonPath], {
533+
pathsRelativeTo: tempDir,
534+
})
535+
536+
assertApiError(res, 400)
537+
})
538+
})
484539
})

0 commit comments

Comments
 (0)