Skip to content

Commit

Permalink
feat(tests): updated publish.test.js to use updated requests and resp…
Browse files Browse the repository at this point in the history
…onses generated by publish.js

#753
  • Loading branch information
aldenbe committed Jul 26, 2024
1 parent d4e0576 commit 3bd8cce
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions test/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import nock from "nock";
import tempy from "tempy";
import { stub } from "sinon";
import publish from "../lib/publish.js";
import { authenticate } from "./helpers/mock-gitlab.js";
import { authenticate, getUploadResponse } from "./helpers/mock-gitlab.js";

/* eslint camelcase: ["error", {properties: "never"}] */

Expand Down Expand Up @@ -56,7 +56,7 @@ test.serial("Publish a release with templated path", async (t) => {
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
const generic = { path: "${env.FIXTURE}.txt", filepath: "/upload.txt" };
const assets = [generic];
const uploaded = { url: "/uploads/upload.txt", alt: "upload.txt" };
const uploaded = getUploadResponse(generic.filepath, encodedRepoId);
const gitlab = authenticate(env)
.post(`/projects/${encodedRepoId}/releases`, {
tag_name: nextRelease.gitTag,
Expand All @@ -65,7 +65,7 @@ test.serial("Publish a release with templated path", async (t) => {
links: [
{
name: "upload.txt",
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
url: `https://gitlab.com${uploaded.full_path}`,
filepath: "/upload.txt",
},
],
Expand All @@ -79,7 +79,7 @@ test.serial("Publish a release with templated path", async (t) => {
const result = await publish({ assets }, { env, cwd, options, nextRelease, logger: t.context.logger });

t.is(result.url, `https://gitlab.com/${owner}/${repo}/-/releases/${encodedGitTag}`);
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", uploaded.url]);
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", `https://gitlab.com${uploaded.full_path}`]);
t.deepEqual(t.context.log.args[1], ["Published GitLab release: %s", nextRelease.gitTag]);
t.true(gitlab.isDone());
});
Expand All @@ -93,7 +93,7 @@ test.serial("Publish a release with assets", async (t) => {
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
const uploaded = { url: "/uploads/file.css", alt: "file.css" };
const uploaded = getUploadResponse("file.css", encodedRepoId);
const assets = [["**", "!**/*.txt", "!.dotfile"]];
const gitlab = authenticate(env)
.post(`/projects/${encodedRepoId}/releases`, {
Expand All @@ -103,7 +103,7 @@ test.serial("Publish a release with assets", async (t) => {
links: [
{
name: uploaded.alt,
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
url: `https://gitlab.com${uploaded.full_path}`,
},
],
},
Expand All @@ -116,7 +116,7 @@ test.serial("Publish a release with assets", async (t) => {
const result = await publish({ assets }, { env, cwd, options, nextRelease, logger: t.context.logger });

t.is(result.url, `https://gitlab.com/${owner}/${repo}/-/releases/${encodedGitTag}`);
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", uploaded.url]);
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", `https://gitlab.com${uploaded.full_path}`]);
t.deepEqual(t.context.log.args[1], ["Published GitLab release: %s", nextRelease.gitTag]);
t.true(gitlabUpload.isDone());
t.true(gitlab.isDone());
Expand Down Expand Up @@ -315,7 +315,7 @@ test.serial("Publish a release with asset type and permalink", async (t) => {
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
const uploaded = { url: "/uploads/file.css", alt: "file.css", link_type: "package", filepath: "/dist/file.css" };
const uploaded = getUploadResponse("file.css", encodedRepoId)
const assets = [
{
path: ["**", "!**/*.txt", "!.dotfile"],
Expand All @@ -331,9 +331,9 @@ test.serial("Publish a release with asset type and permalink", async (t) => {
links: [
{
name: uploaded.alt,
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
link_type: uploaded.link_type,
filepath: uploaded.filepath,
url: `https://gitlab.com${uploaded.full_path}`,
link_type: "package",
filepath: "/dist/file.css",
},
],
},
Expand All @@ -346,7 +346,7 @@ test.serial("Publish a release with asset type and permalink", async (t) => {
const result = await publish({ assets }, { env, cwd, options, nextRelease, logger: t.context.logger });

t.is(result.url, `https://gitlab.com/${owner}/${repo}/-/releases/${encodedGitTag}`);
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", uploaded.url]);
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", `https://gitlab.com${uploaded.full_path}`]);
t.deepEqual(t.context.log.args[1], ["Published GitLab release: %s", nextRelease.gitTag]);
t.true(gitlabUpload.isDone());
t.true(gitlab.isDone());
Expand All @@ -361,7 +361,7 @@ test.serial("Publish a release with an asset with a template label", async (t) =
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
const uploaded = { url: "/uploads/file.css", alt: "file.css" };
const uploaded = getUploadResponse("file.css", encodedRepoId);
const assets = [
{
label: `file-v\${nextRelease.version}.css`,
Expand All @@ -378,7 +378,7 @@ test.serial("Publish a release with an asset with a template label", async (t) =
links: [
{
name: "file-v1.0.0.css",
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
url: `https://gitlab.com${uploaded.full_path}`,
link_type: "other",
filepath: "/dist/file.css",
},
Expand All @@ -393,7 +393,7 @@ test.serial("Publish a release with an asset with a template label", async (t) =
const result = await publish({ assets }, { env, cwd, options, nextRelease, logger: t.context.logger });

t.is(result.url, `https://gitlab.com/${owner}/${repo}/-/releases/${encodedGitTag}`);
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", uploaded.url]);
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", `https://gitlab.com${uploaded.full_path}`]);
t.deepEqual(t.context.log.args[1], ["Published GitLab release: %s", nextRelease.gitTag]);
t.true(gitlabUpload.isDone());
t.true(gitlab.isDone());
Expand All @@ -410,7 +410,7 @@ test.serial("Publish a release (with an link) with variables", async (t) => {
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
const uploaded = { url: "/uploads/file.css", alt: "file.css" };
const uploaded = getUploadResponse("file.css", encodedRepoId);
const assets = [
{
label: `README-v\${nextRelease.version}.md`,
Expand All @@ -437,7 +437,7 @@ test.serial("Publish a release (with an link) with variables", async (t) => {
},
{
name: "file.css",
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
url: `https://gitlab.com${uploaded.full_path}`,
link_type: "other",
filepath: "/dist/file.css",
},
Expand All @@ -452,7 +452,7 @@ test.serial("Publish a release (with an link) with variables", async (t) => {
const result = await publish({ assets }, { env, cwd, options, nextRelease, logger: t.context.logger });

t.is(result.url, `https://gitlab.com/${owner}/${repo}/-/releases/${encodedGitTag}`);
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", uploaded.url]);
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", `https://gitlab.com${uploaded.full_path}`]);
t.deepEqual(t.context.log.args[1], ["Published GitLab release: %s", nextRelease.gitTag]);
t.true(gitlabUpload.isDone());
t.true(gitlab.isDone());
Expand Down Expand Up @@ -524,7 +524,7 @@ test.serial("Publish a release with one asset and custom label", async (t) => {
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
const encodedGitTag = encodeURIComponent(nextRelease.gitTag);
const uploaded = { url: "/uploads/upload.txt" };
const uploaded = getUploadResponse("upload.txt", encodedRepoId)
const assetLabel = "Custom Label";
const assets = [{ path: "upload.txt", label: assetLabel }];
const gitlab = authenticate(env)
Expand All @@ -535,7 +535,7 @@ test.serial("Publish a release with one asset and custom label", async (t) => {
links: [
{
name: assetLabel,
url: `https://gitlab.com/${owner}/${repo}${uploaded.url}`,
url: `https://gitlab.com${uploaded.full_path}`,
},
],
},
Expand All @@ -548,7 +548,7 @@ test.serial("Publish a release with one asset and custom label", async (t) => {
const result = await publish({ assets }, { env, cwd, options, nextRelease, logger: t.context.logger });

t.is(result.url, `https://gitlab.com/${owner}/${repo}/-/releases/${encodedGitTag}`);
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", uploaded.url]);
t.deepEqual(t.context.log.args[0], ["Uploaded file: %s", `https://gitlab.com${uploaded.full_path}`]);
t.deepEqual(t.context.log.args[1], ["Published GitLab release: %s", nextRelease.gitTag]);
t.true(gitlabUpload.isDone());
t.true(gitlab.isDone());
Expand Down

0 comments on commit 3bd8cce

Please sign in to comment.