-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for custom request options
- Loading branch information
Mila Votradovec
committed
Mar 16, 2021
1 parent
7919781
commit e46f2e3
Showing
4 changed files
with
166 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface RequestOptions { | ||
headers: { [key: string]: string }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { Log } from 'sarif'; | |
import * as sarifSchema from './sarif-schema-2.1.0.json'; | ||
import { ErrorCodes } from '../src/constants'; | ||
import { IGitBundle } from '../src/interfaces/analysis-result.interface'; | ||
import axios from '../src/axios'; | ||
|
||
const oAuthToken = process.env.SNYK_OAUTH_KEY || ''; | ||
const sessionTokenNoRepoAccess = process.env.SNYK_API_KEY_NO_ACCESS || ''; | ||
|
@@ -191,6 +192,39 @@ describe('Functional test of analysis', () => { | |
}); | ||
}); | ||
|
||
describe('Custom request options', () => { | ||
beforeAll(() => { | ||
jest.mock('axios'); | ||
axios.request = jest.fn().mockRejectedValue({}); | ||
}); | ||
|
||
it( | ||
'passes custom options correctly', | ||
async () => { | ||
try { | ||
await analyzeGit( | ||
{ | ||
baseURL, | ||
sessionToken, | ||
includeLint: false, | ||
severity: 1, | ||
gitUri: '[email protected]:DeepCodeAI/cli.git', | ||
}, | ||
{ headers: { 'X-test-header': 'Snyk' } }, | ||
); | ||
} catch (e) { | ||
// expected to fail, we are interested in correct propagation of headers only | ||
} | ||
expect((axios.request as jest.Mock).mock.calls[0][0]).toMatchObject({headers: { 'X-test-header': 'Snyk' }}); | ||
}, | ||
TEST_TIMEOUT, | ||
); | ||
|
||
afterAll(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
}); | ||
|
||
function getNumOfIssues(bundle: IGitBundle): number { | ||
let numberOfIssues = 0; | ||
|
||
|