diff --git a/src/__test__/list-playlists.test.ts b/src/__test__/list-playlists.test.ts index 0fd4a550..f0eb246c 100644 --- a/src/__test__/list-playlists.test.ts +++ b/src/__test__/list-playlists.test.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -import listPlaylists, { formatTracks } from "../list-playlists"; +import listPlaylists, { formatName, formatTracks } from "../list-playlists"; import { getInput } from "@actions/core"; import SpotifyWebApi from "spotify-web-api-node"; @@ -233,3 +233,11 @@ describe("formatTracks", () => { `); }); }); + +describe("formatName", () => { + it("formats the name correctly", () => { + expect(formatName("2021 Fall")).toBe("2021-fall"); + expect(formatName("2020/2021 Winter")).toBe("2020-2021-winter"); + expect(formatName("2020 / 2021 Winter")).toBe("2020-2021-winter"); + }); +}); diff --git a/src/index.ts b/src/index.ts index 30ae02d8..3886cd3f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import updateMain from "./write-file"; -import { setFailed, exportVariable, getInput, info } from "@actions/core"; +import { setFailed, exportVariable, getInput } from "@actions/core"; import listPlaylists from "./list-playlists"; import * as github from "@actions/github"; @@ -23,14 +23,9 @@ export async function action() { try { const filename = getInput("filename"); const payload = github.context.payload.inputs; - const playlistName = payload?.["playlist-name"] || getInput("playlist-name"); - info(`payload: ${payload?.["playlist-name"]}`); - info(`action input: ${getInput("playlist-name")}`); - info(`playlistName: ${playlistName}`); - if (!playlistName) { throw new Error("Playlist name is required"); } diff --git a/src/list-playlists.ts b/src/list-playlists.ts index 16d7b430..66c64818 100644 --- a/src/list-playlists.ts +++ b/src/list-playlists.ts @@ -102,9 +102,10 @@ export function formatTracks({ }; } -function formatName(name: string): string { +export function formatName(name: string): string { return name .replace(/\s/g, "-") + .replace(/[/]/g, "-") .replace(/[^a-zA-Z0-9-]/g, "") .replace(/-+/g, "-") .toLowerCase();