-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(byods): Spark 549034 jest setup (#3821)
- Loading branch information
1 parent
97d8936
commit 0c1a758
Showing
9 changed files
with
121 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import config from '@webex/jest-config-legacy'; | ||
|
||
const jestConfig = { | ||
rootDir: './', | ||
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], | ||
testEnvironment: 'node', | ||
testMatch: ['<rootDir>/**/*.test.ts'], | ||
transformIgnorePatterns: ['/node_modules/(?!node-fetch)|data-uri-to-buffer'], | ||
testPathIgnorePatterns: ['/node_modules/', '/dist/'], | ||
testResultsProcessor: 'jest-junit', | ||
// Clear mocks in between tests by default | ||
clearMocks: true, | ||
// TODO: Set this to true once we have the source code and their corresponding test files added | ||
collectCoverage: false, | ||
coverageThreshold: { | ||
global: { | ||
lines: 85, | ||
functions: 85, | ||
branches: 85, | ||
statements: 85, | ||
}, | ||
}, | ||
coverageDirectory: 'coverage', | ||
coverageReporters: ['clover', 'json', 'lcov'], | ||
reporters: [ | ||
'default', | ||
[ | ||
'jest-junit', | ||
{ | ||
outputDirectory: 'coverage/junit', | ||
outputName: 'coverage-junit.xml', | ||
classNameTemplate: '{classname}', | ||
titleTemplate: '{title}', | ||
}, | ||
], | ||
[ | ||
'jest-html-reporters', | ||
{ | ||
publicPath: './coverage', | ||
filename: 'jest-report.html', | ||
openReport: false, | ||
}, | ||
], | ||
], | ||
}; | ||
|
||
export default {...config, ...jestConfig}; |
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,10 @@ | ||
import 'jest'; | ||
|
||
declare global { | ||
namespace jest { | ||
/* eslint-disable-next-line no-unused-vars */ | ||
interface Matchers<R> { | ||
toBeCalledOnceWith(received?: any, ...expected: any[]): CustomMatcherResult; | ||
} | ||
} | ||
} |
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,12 @@ | ||
expect.extend({ | ||
toBeCalledOnceWith(received, ...expected) { | ||
try { | ||
expect(received).toBeCalledTimes(1); | ||
expect(received).toBeCalledWith(...expected); | ||
} catch (error) { | ||
return {message: () => error, pass: false}; | ||
} | ||
|
||
return {pass: true}; | ||
}, | ||
}); |
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,32 @@ | ||
import fetch, {Response} from 'node-fetch'; | ||
import BYODS from './BYODS'; | ||
|
||
jest.mock('node-fetch', () => jest.fn()); | ||
|
||
describe('BYoDS Tests', () => { | ||
const mockSDKConfig = { | ||
clientId: 'your-client-id', | ||
clientSecret: 'your-client-secret', | ||
accessToken: 'your-initial-access-token', | ||
refreshToken: 'your-refresh-token', | ||
expiresAt: new Date('2024-09-15T00:00:00Z'), | ||
}; | ||
|
||
const mockResponse = { | ||
json: jest.fn().mockResolvedValue({key: 'value'}), | ||
} as unknown as Response; | ||
|
||
(fetch as unknown as jest.MockedFunction<typeof fetch>).mockResolvedValue(mockResponse); | ||
|
||
it('fetch the datasources', async () => { | ||
const mockPayload = { | ||
headers: { | ||
Authorization: `Bearer ${mockSDKConfig.accessToken}`, | ||
}, | ||
}; | ||
const sdk = new BYODS(mockSDKConfig); | ||
const endpoint = 'https://developer-applications.ciscospark.com/v1/dataSources/'; | ||
await sdk.makeAuthenticatedRequest(endpoint); | ||
expect(fetch).toHaveBeenCalledWith(endpoint, mockPayload); | ||
}); | ||
}); |
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