Skip to content

Commit

Permalink
(mathieudutour#145): specified desired behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-hartmond-mw committed Apr 21, 2023
1 parent 86301c8 commit 663cac3
Showing 1 changed file with 137 additions and 0 deletions.
137 changes: 137 additions & 0 deletions tests/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 663cac3

Please sign in to comment.