From 663cac31b2d31a0a127ba44cd85bab029c491fef Mon Sep 17 00:00:00 2001 From: Martin Hartmond Date: Fri, 21 Apr 2023 16:05:26 +0200 Subject: [PATCH] (#145): specified desired behaviour --- tests/action.test.ts | 137 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/tests/action.test.ts b/tests/action.test.ts index 413e7bfae..832765198 100644 --- a/tests/action.test.ts +++ b/tests/action.test.ts @@ -527,6 +527,143 @@ describe('github-tag-action', () => { expect(mockSetFailed).not.toBeCalled(); }); + /** 1.3.0 commit =[minor, preminor]=> 1.4.0-pre.0 */ + it('does create prerelease tag respecting default_bump', async () => { + /* + * Given + */ + const commits = [{ message: 'this is a commit', hash: null }]; + jest + .spyOn(utils, 'getCommits') + .mockImplementation(async (sha) => commits); + + const validTags = [ + { + name: 'v1.2.3', + commit: { sha: '012345', url: '' }, + zipball_url: '', + tarball_url: 'string', + node_id: 'string', + }, + ]; + jest + .spyOn(utils, 'getValidTags') + .mockImplementation(async () => validTags); + + /* + * When + */ + setInput('default_bump', 'minor'); + setInput('default_prerelease_bump', 'prerelease'); + await action(); + + /* + * Then + */ + expect(mockCreateTag).toHaveBeenCalledWith( + 'v1.3.0-prerelease.0', + expect.any(Boolean), + expect.any(String) + ); + expect(mockSetFailed).not.toBeCalled(); + }); + + /** 1.3.0-pre.0 + commit =[minor, prerelease]=> 1.3.0-pre.1 */ + it('does update prerelease tag respecting default_bump', async () => { + /* + * Given + */ + const commits = [{ message: 'this is a commit', hash: null }]; + jest + .spyOn(utils, 'getCommits') + .mockImplementation(async (sha) => commits); + + const validTags = [ + { + name: 'v1.2.3', + commit: { sha: '012345', url: '' }, + zipball_url: '', + tarball_url: 'string', + node_id: 'string', + }, + { + name: 'v1.3.0-prerelease.0', + commit: { sha: '123456', url: '' }, + zipball_url: '', + tarball_url: 'string', + node_id: 'string', + }, + ]; + jest + .spyOn(utils, 'getValidTags') + .mockImplementation(async () => validTags); + + /* + * When + */ + setInput('default_bump', 'minor'); + setInput('default_prerelease_bump', 'prerelease'); + await action(); + + /* + * Then + */ + expect(mockCreateTag).toHaveBeenCalledWith( + 'v1.3.0-prerelease.1', + expect.any(Boolean), + expect.any(String) + ); + expect(mockSetFailed).not.toBeCalled(); + }); + + /** 1.3.0-pre.0 + commit =[minor, preminor]=> 1.4.0-pre.0 */ + it('does update prerelease tag with preminor', async () => { + /* + * Given + */ + const commits = [{ message: 'this is a commit', hash: null }]; + jest + .spyOn(utils, 'getCommits') + .mockImplementation(async (sha) => commits); + + const validTags = [ + { + name: 'v1.2.3', + commit: { sha: '012345', url: '' }, + zipball_url: '', + tarball_url: 'string', + node_id: 'string', + }, + { + name: 'v1.3.0-prerelease.0', + commit: { sha: '123456', url: '' }, + zipball_url: '', + tarball_url: 'string', + node_id: 'string', + }, + ]; + jest + .spyOn(utils, 'getValidTags') + .mockImplementation(async () => validTags); + + /* + * When + */ + setInput('default_bump', 'minor'); + setInput('default_prerelease_bump', 'preminor'); + await action(); + + /* + * Then + */ + expect(mockCreateTag).toHaveBeenCalledWith( + 'v1.4.0-prerelease.0', + expect.any(Boolean), + expect.any(String) + ); + expect(mockSetFailed).not.toBeCalled(); + }); + it('does create prepatch tag', async () => { /* * Given