Skip to content

Commit

Permalink
test: update tests to support draft releases
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrcunha authored and gr2m committed Mar 25, 2019
1 parent c9c5ebf commit 06f1d91
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
18 changes: 14 additions & 4 deletions test/integration.test.js
Expand Up @@ -152,8 +152,13 @@ test.serial('Publish a release with an array of assets', async t => {
target_commitish: options.branch,
name: nextRelease.gitTag,
body: nextRelease.notes,
draft: true,
})
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl});
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl, id: releaseId})
.patch(`/repos/${owner}/${repo}/releases/${releaseId}`, {
draft: false,
})
.reply(200, {html_url: releaseUrl});
const githubUpload1 = upload(env, {
uploadUrl: 'https://github.com',
contentLength: (await stat(path.resolve(cwd, 'upload.txt'))).size,
Expand All @@ -171,9 +176,9 @@ test.serial('Publish a release with an array of assets', async t => {

t.is(result.url, releaseUrl);
t.deepEqual(t.context.log.args[0], ['Verify GitHub authentication']);
t.deepEqual(t.context.log.args[1], ['Published GitHub release: %s', releaseUrl]);
t.true(t.context.log.calledWith('Published file %s', otherAssetUrl));
t.true(t.context.log.calledWith('Published file %s', assetUrl));
t.true(t.context.log.calledWith('Published GitHub release: %s', releaseUrl));
t.true(github.isDone());
t.true(githubUpload1.isDone());
t.true(githubUpload2.isDone());
Expand Down Expand Up @@ -285,8 +290,13 @@ test.serial('Verify, release and notify success', async t => {
target_commitish: options.branch,
name: nextRelease.gitTag,
body: nextRelease.notes,
draft: true,
})
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl, id: releaseId})
.patch(`/repos/${owner}/${repo}/releases/${releaseId}`, {
draft: false,
})
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl})
.reply(200, {html_url: releaseUrl})
.get(`/repos/${owner}/${repo}`)
.reply(200, {full_name: `${owner}/${repo}`})
.get(
Expand Down Expand Up @@ -328,9 +338,9 @@ test.serial('Verify, release and notify success', async t => {
);

t.deepEqual(t.context.log.args[0], ['Verify GitHub authentication']);
t.deepEqual(t.context.log.args[1], ['Published GitHub release: %s', releaseUrl]);
t.true(t.context.log.calledWith('Published file %s', otherAssetUrl));
t.true(t.context.log.calledWith('Published file %s', assetUrl));
t.true(t.context.log.calledWith('Published GitHub release: %s', releaseUrl));
t.true(github.isDone());
t.true(githubUpload1.isDone());
t.true(githubUpload2.isDone());
Expand Down
27 changes: 21 additions & 6 deletions test/publish.test.js
Expand Up @@ -47,7 +47,7 @@ test.serial('Publish a release', async t => {
name: nextRelease.gitTag,
body: nextRelease.notes,
})
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl});
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl, id: releaseId});

const result = await publish(pluginConfig, {cwd, env, options, nextRelease, logger: t.context.logger});

Expand Down Expand Up @@ -83,7 +83,7 @@ test.serial('Publish a release, retrying 4 times', async t => {
name: nextRelease.gitTag,
body: nextRelease.notes,
})
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl});
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl, id: releaseId});

const result = await publish(pluginConfig, {cwd, env, options, nextRelease, logger: t.context.logger});

Expand Down Expand Up @@ -113,6 +113,11 @@ test.serial('Publish a release with one asset', async t => {
target_commitish: options.branch,
name: nextRelease.gitTag,
body: nextRelease.notes,
draft: true,
})
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl, id: releaseId})
.patch(`/repos/${owner}/${repo}/releases/${releaseId}`, {
draft: false,
})
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl});

Expand All @@ -126,7 +131,7 @@ test.serial('Publish a release with one asset', async t => {
const result = await publish(pluginConfig, {cwd, env, options, nextRelease, logger: t.context.logger});

t.is(result.url, releaseUrl);
t.deepEqual(t.context.log.args[0], ['Published GitHub release: %s', releaseUrl]);
t.true(t.context.log.calledWith('Published GitHub release: %s', releaseUrl));
t.true(t.context.log.calledWith('Published file %s', assetUrl));
t.true(github.isDone());
t.true(githubUpload.isDone());
Expand All @@ -153,6 +158,11 @@ test.serial('Publish a release with one asset and custom github url', async t =>
target_commitish: options.branch,
name: nextRelease.gitTag,
body: nextRelease.notes,
draft: true,
})
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl, id: releaseId})
.patch(`/repos/${owner}/${repo}/releases/${releaseId}`, {
draft: false,
})
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl});

Expand All @@ -166,7 +176,7 @@ test.serial('Publish a release with one asset and custom github url', async t =>
const result = await publish(pluginConfig, {cwd, env, options, nextRelease, logger: t.context.logger});

t.is(result.url, releaseUrl);
t.deepEqual(t.context.log.args[0], ['Published GitHub release: %s', releaseUrl]);
t.true(t.context.log.calledWith('Published GitHub release: %s', releaseUrl));
t.true(t.context.log.calledWith('Published file %s', assetUrl));
t.true(github.isDone());
t.true(githubUpload.isDone());
Expand All @@ -191,13 +201,18 @@ test.serial('Publish a release with an array of missing assets', async t => {
target_commitish: options.branch,
name: nextRelease.gitTag,
body: nextRelease.notes,
draft: true,
})
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl});
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl, id: releaseId})
.patch(`/repos/${owner}/${repo}/releases/${releaseId}`, {
draft: false,
})
.reply(200, {html_url: releaseUrl});

const result = await publish(pluginConfig, {cwd, env, options, nextRelease, logger: t.context.logger});

t.is(result.url, releaseUrl);
t.deepEqual(t.context.log.args[0], ['Published GitHub release: %s', releaseUrl]);
t.true(t.context.log.calledWith('Published GitHub release: %s', releaseUrl));
t.true(t.context.error.calledWith('The asset %s cannot be read, and will be ignored.', 'missing.txt'));
t.true(t.context.error.calledWith('The asset %s is not a file, and will be ignored.', emptyDirectory));
t.true(github.isDone());
Expand Down

0 comments on commit 06f1d91

Please sign in to comment.