generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
74 additions
and
1 deletion.
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,61 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { getWorkItemsBatch } from '../src/azdo' | ||
|
||
const adoResponse = fs.readFileSync( | ||
path.join(__dirname, 'test_cases/big', 'ado_response.json'), | ||
'utf8' | ||
) | ||
describe('Azure DevOps API tests', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
|
||
// mock fetch | ||
global.fetch = jest.fn(() => | ||
Check failure on line 14 in __tests__/azdo.test.ts GitHub Actions / Lint Codebase
|
||
Promise.resolve({ | ||
json: () => Promise.resolve(JSON.parse(adoResponse)), | ||
Check failure on line 16 in __tests__/azdo.test.ts GitHub Actions / Lint Codebase
|
||
status: 200 | ||
}) | ||
) as jest.Mock; | ||
}) | ||
|
||
it('calls azdo API to get workitems', async () => { | ||
const expectedAuth = Buffer.from(`:${'token'}`).toString('base64') | ||
const ids = [11, 1, 111, 5, 14, 143, 112]; | ||
|
||
const workItems = await getWorkItemsBatch('token', 'my-org', 'my-project', ids) | ||
|
||
expect(fetch).toHaveBeenCalledWith( | ||
`https://dev.azure.com/my-org/my-project/_apis/wit/workitemsbatch?api-version=7.1-preview.1`, | ||
expect.objectContaining({ | ||
"headers": expect.objectContaining({ | ||
"Authorization": `Basic ${expectedAuth}`, | ||
}), | ||
"body": expect.stringContaining(ids.join(',')), | ||
})); | ||
expect(workItems).toBeDefined() | ||
expect((workItems?.value.map((wi: any) => wi.id))).toEqual(expect.arrayContaining(ids)) | ||
}) | ||
|
||
it('returns undefined on error', async () => { | ||
global.fetch = jest.fn(() => | ||
Promise.resolve({ | ||
status: 500 | ||
}) | ||
) as jest.Mock; | ||
|
||
const workItems = await getWorkItemsBatch('token', 'my-org', 'my-project', [1, 2, 3]) | ||
|
||
expect(workItems).toBeUndefined() | ||
}) | ||
|
||
it('returns undefined on catch error', async () => { | ||
global.fetch = jest.fn(() => | ||
Promise.reject(new Error('error')) | ||
) as jest.Mock; | ||
|
||
const workItems = await getWorkItemsBatch('token', 'my-org', 'my-project', [1, 2, 3]) | ||
|
||
expect(workItems).toBeUndefined() | ||
}) | ||
}) |
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