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
+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', () => ({
default: coreMock
}));
@@ -72,4 +80,27 @@ describe('manual dispatch integration', () => {
expect(coreMock.setFailed).not.toHaveBeenCalled();
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();
});
});