Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/content/__tests__/listArtistSongs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { listArtistSongs } from "../listArtistSongs";

const mockFetch = vi.fn();
global.fetch = mockFetch;

process.env.GITHUB_TOKEN = "test-token";

function makeTreeResponse(paths: string[]) {
return {
ok: true,
json: () =>
Promise.resolve({
tree: paths.map(path => ({ path, type: "blob" })),
}),
};
}

describe("listArtistSongs", () => {
beforeEach(() => {
vi.clearAllMocks();
});

it("only returns mp3s from the songs/ subdirectory", async () => {
mockFetch.mockResolvedValueOnce(
makeTreeResponse([
"artists/gatsby-grace/songs/my-song/my-song.mp3",
"artists/gatsby-grace/content/social-pack/assets/clip_bridge_15s.mp3",
"artists/gatsby-grace/images/photo.jpg",
]),
);

const songs = await listArtistSongs("https://github.com/org/repo", "gatsby-grace");

expect(songs).toEqual(["artists/gatsby-grace/songs/my-song/my-song.mp3"]);
});

it("excludes mp3s from content/ directory", async () => {
// Main repo returns only content/ mp3s (no songs/)
mockFetch.mockResolvedValueOnce(
makeTreeResponse([
"artists/gatsby-grace/content/social-pack-bedroom-lip-sync/assets/clip_bridge_15s.mp3",
]),
);
// Org submodules fetch (.gitmodules) returns no submodules
mockFetch.mockResolvedValueOnce({ ok: false });

const songs = await listArtistSongs("https://github.com/org/repo", "gatsby-grace");

expect(songs).toEqual([]);
});
});
2 changes: 1 addition & 1 deletion src/content/listArtistSongs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function listMp3sInRepo(
tree: Array<{ path: string; type: string }>;
};

const artistPrefix = `artists/${artistSlug}/`;
const artistPrefix = `artists/${artistSlug}/songs/`;
return data.tree
.filter(
entry =>
Expand Down
Loading