feat(tests): add test for handling release payload with null body and update formatDescription to handle undefined input. resolves #53

This commit is contained in:
SethCohen
2026-04-03 12:54:06 -04:00
parent e15eb81a91
commit 60ef92f147
3 changed files with 35 additions and 3 deletions
+1
View File
@@ -8,3 +8,4 @@ repository.json
user.json user.json
tests/sample-test-release-v2.json tests/sample-test-release-v2.json
tests/sample-test-release-v3.json tests/sample-test-release-v3.json
tests/sample-test-release-null-body.json
+3 -3
View File
@@ -110,7 +110,7 @@ const convertLinksToMarkdown = (text) => {
* @returns {string} The formatted description. * @returns {string} The formatted description.
*/ */
const formatDescription = (description) => { const formatDescription = (description) => {
let edit = removeCarriageReturn(description); let edit = removeCarriageReturn(description ?? '');
edit = removeHTMLComments(edit); edit = removeHTMLComments(edit);
edit = reduceNewlines(edit); edit = reduceNewlines(edit);
@@ -303,8 +303,8 @@ const run = async () => {
const { body, html_url, name } = getContext(); const { body, html_url, name } = getContext();
if (!body || !name) { if (!name) {
return core.setFailed('No GitHub release payload found. When using workflow_dispatch, pass release_name and release_body inputs to the action.'); return core.setFailed('No GitHub release payload found. When using workflow_dispatch, pass release_name to the action.');
} }
const description = formatDescription(body); const description = formatDescription(body);
+31
View File
@@ -34,6 +34,14 @@ const githubMock = {
} }
}; };
beforeEach(() => {
fetchMock.mockClear();
coreMock.setFailed.mockClear();
coreMock.info.mockClear();
coreMock.warning.mockClear();
githubMock.context.payload = {};
});
jest.unstable_mockModule('@actions/core', () => ({ jest.unstable_mockModule('@actions/core', () => ({
default: coreMock default: coreMock
})); }));
@@ -72,4 +80,27 @@ describe('manual dispatch integration', () => {
expect(coreMock.setFailed).not.toHaveBeenCalled(); expect(coreMock.setFailed).not.toHaveBeenCalled();
expect(coreMock.info).toHaveBeenCalledWith('{"id":"discord-message-id"}'); expect(coreMock.info).toHaveBeenCalledWith('{"id":"discord-message-id"}');
}); });
test('run() tolerates a release payload with a null body', async () => {
githubMock.context.payload.release = {
name: 'v1.2.4',
body: null,
html_url: 'https://github.com/owner/repo/releases/tag/v1.2.4'
};
const { run } = await import('../index.js');
await run();
expect(fetchMock).toHaveBeenCalledTimes(1);
const request = JSON.parse(fetchMock.mock.calls[0][1].body);
expect(request.embeds[0]).toMatchObject({
title: 'v1.2.4',
url: 'https://github.com/owner/repo/releases/tag/v1.2.4',
description: ''
});
expect(coreMock.setFailed).not.toHaveBeenCalled();
});
}); });