generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding client tests * Auto-package action Co-authored-by: dangoslen <dangoslen@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
62 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 @@ | ||
jest.mock('node-fetch'); | ||
|
||
const core = require('@actions/core') | ||
const fetch = require('node-fetch') | ||
const { Response } = jest.requireActual('node-fetch'); | ||
const client = require('../src/client') | ||
|
||
describe('the client', () => { | ||
|
||
afterAll(() => { | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
prepareResponse = (body) => { | ||
return Promise.resolve(new Response(body, { Headers: { 'Content-Type': 'application/json' } })) | ||
} | ||
|
||
it('should find the change file', async () => { | ||
const files = [ | ||
{ | ||
"filename": "CHANGELOG.md", | ||
"status": "modified", | ||
"raw_url": "./path/to/CHANGELOG.md" | ||
} | ||
] | ||
|
||
fetch.mockReturnValueOnce(prepareResponse(JSON.stringify(files))) | ||
|
||
const changelogFile = await client.findChangelog('token', 'repo', 1, 1, 'CHANGELOG.md') | ||
expect(fetch).toHaveBeenCalled() | ||
expect(changelogFile).toStrictEqual({ | ||
"filename": "CHANGELOG.md", | ||
"status": "modified", | ||
"raw_url": "./path/to/CHANGELOG.md" | ||
}) | ||
}) | ||
|
||
it('should not find the change file', async () => { | ||
const firstPage = [ | ||
{ | ||
"filename": "random.md", | ||
"status": "modified", | ||
"raw_url": "./path/to/random.md" | ||
} | ||
] | ||
|
||
const secondPage = [] | ||
|
||
fetch | ||
.mockReturnValueOnce(prepareResponse(JSON.stringify(firstPage))) | ||
.mockReturnValueOnce(prepareResponse(JSON.stringify(secondPage))) | ||
|
||
const changelogFile = await client.findChangelog('token', 'repo', 1, 1, 'CHANGELOG.md') | ||
expect(fetch).toHaveBeenCalledTimes(2) | ||
expect(changelogFile).toBeUndefined() | ||
}) | ||
}) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.