Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparing 0.7.1 #48

Merged
merged 2 commits into from
Jun 16, 2024
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
4 changes: 3 additions & 1 deletion .github/workflows/enforce-dev-to-main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Ensure only `dev` can merge into `main`
on:
pull_request_target:
pull_request:
branches:
- main
types:
- opened
- reopened
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-jest-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ jobs:
with:
node-version: 18.x
- run: npm install
- run: npm test
- run: npm test -- --verbose
- if: ${{ failure() }}
run: exit 1
46 changes: 24 additions & 22 deletions src/utils/array.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import { getBiggestImageUrl } from "@utils/array";

//#region getBiggestImageUrl
describe("getBiggestImageUrl", () => {
it("should return url of image with highest width", () => {
const images: SpotifyImage[] = [
{ url: "small.jpg", width: 100, height: 100 },
{ url: "large.jpg", width: 300, height: 300 },
{ url: "medium.jpg", width: 200, height: 200 },
];
expect(getBiggestImageUrl(images)).toBe("large.jpg");
});
describe("Array Helpers", () => {
//#region getBiggestImageUrl
describe("getBiggestImageUrl", () => {
it("should return url of image with highest width", () => {
const images: SpotifyImage[] = [
{ url: "small.jpg", width: 100, height: 100 },
{ url: "large.jpg", width: 300, height: 300 },
{ url: "medium.jpg", width: 200, height: 200 },
];
expect(getBiggestImageUrl(images)).toBe("large.jpg");
});

it("should return first url if multiple images with same width", () => {
const images: SpotifyImage[] = [
{ url: "large-image-1.jpg", width: 300, height: 300 },
{ url: "small.jpg", width: 100, height: 100 },
{ url: "large-image-2.jpg", width: 300, height: 300 },
];
expect(getBiggestImageUrl(images)).toBe("large-image-1.jpg");
});
it("should return first url if multiple images with same width", () => {
const images: SpotifyImage[] = [
{ url: "large-image-1.jpg", width: 300, height: 300 },
{ url: "small.jpg", width: 100, height: 100 },
{ url: "large-image-2.jpg", width: 300, height: 300 },
];
expect(getBiggestImageUrl(images)).toBe("large-image-1.jpg");
});

it("should return empty string if no images", () => {
const images: SpotifyImage[] = [];
it("should return empty string if no images", () => {
const images: SpotifyImage[] = [];

expect(getBiggestImageUrl(images)).toBe("");
expect(getBiggestImageUrl(images)).toBe("");
});
});
//#endregion
});
//#endregion
3 changes: 1 addition & 2 deletions src/utils/spotify/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SpotifyService } from "@utils/spotify";
import { SpotifyApiService } from "@utils/spotify/api";
import { jest } from "@jest/globals";
import { integrationManager, logger } from "@utils/firebot";

type DummyDataType = {
foo: string;
Expand All @@ -18,7 +17,7 @@ jest.mock("@utils/firebot", () => ({
chatFeedAlert: jest.fn(() => {}),
}));

describe("SpotifyApiService", () => {
describe("Spotify - Api Service", () => {
let spotify: SpotifyService;
let api: SpotifyApiService;

Expand Down
22 changes: 13 additions & 9 deletions src/utils/spotify/device.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SpotifyDeviceService } from "@utils/spotify/device";

describe("SpotifyDeviceService", () => {
describe("Spotify - Device Service", () => {
let spotifyDevice: SpotifyDeviceService;

const defaults = {
Expand All @@ -12,16 +12,20 @@ describe("SpotifyDeviceService", () => {
spotifyDevice = new SpotifyDeviceService();
});

it("should have default getter values", () => {
for (const [key, value] of Object.entries(defaults)) {
expect(spotifyDevice[key as keyof SpotifyDeviceService]).toBe(value);
}
describe("Getters", () => {
it("should have default getter values", () => {
for (const [key, value] of Object.entries(defaults)) {
expect(spotifyDevice[key as keyof SpotifyDeviceService]).toBe(value);
}
});
});

it("should update device id", () => {
spotifyDevice.updateId("1234");
describe("updateId", () => {
it("should update device id", () => {
spotifyDevice.updateId("1234");

expect(spotifyDevice.isAvailable).toBe(true);
expect(spotifyDevice.id).toBe("1234");
expect(spotifyDevice.isAvailable).toBe(true);
expect(spotifyDevice.id).toBe("1234");
});
});
});
38 changes: 20 additions & 18 deletions src/utils/spotify/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SpotifyService } from "@utils/spotify";
import { jest } from "@jest/globals";
import { testSearchResponse, testTrack } from "@/testData";

describe("SpotifyService", () => {
describe("Spotify Service", () => {
let spotify: SpotifyService;

beforeEach(() => {
Expand All @@ -17,22 +17,24 @@ describe("SpotifyService", () => {
jest.clearAllMocks();
});

it("search returns search response", async () => {
const response = await spotify.searchAsync("testing", "track");

expect(response).toBe(testSearchResponse);
});

it("search returns expected number of tracks", async () => {
testSearchResponse.tracks.items = [
testTrack,
testTrack,
testTrack,
testTrack,
testTrack,
];
const response = await spotify.searchAsync("testing", "track");

expect(response.tracks.items.length).toBe(5);
describe("searchAsync", () => {
it("search returns search response", async () => {
const response = await spotify.searchAsync("testing", "track");

expect(response).toBe(testSearchResponse);
});

it("search returns expected number of tracks", async () => {
testSearchResponse.tracks.items = [
testTrack,
testTrack,
testTrack,
testTrack,
testTrack,
];
const response = await spotify.searchAsync("testing", "track");

expect(response.tracks.items.length).toBe(5);
});
});
});
12 changes: 7 additions & 5 deletions src/utils/spotify/player/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SpotifyPlayerService from ".";
import { SpotifyService } from "..";

describe("SpotifyPlayerService", () => {
describe("Spotify - Player Service", () => {
let spotify: SpotifyService;
let player: SpotifyPlayerService;

Expand All @@ -10,9 +10,11 @@ describe("SpotifyPlayerService", () => {
player = new SpotifyPlayerService(spotify);
});

it("should have default getter values", () => {
expect(player.isPlaying).toBe(false);
expect(player.volume).toBe(-1);
expect(player.volumeWasManuallyChanged).toBe(false);
describe("Getters", () => {
it("should have default getter values", () => {
expect(player.isPlaying).toBe(false);
expect(player.volume).toBe(-1);
expect(player.volumeWasManuallyChanged).toBe(false);
});
});
});
54 changes: 30 additions & 24 deletions src/utils/spotify/player/lyrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { testLyricData } from "@/testData";
import { SpotifyService } from "..";
import { SpotifyLyricsService, LyricsHelpers } from "./lyrics";

describe("SpotifyLyricsService", () => {
describe("Spotify - Lyrics Service", () => {
let spotify: SpotifyService;
let lyrics: SpotifyLyricsService;

Expand Down Expand Up @@ -30,35 +30,41 @@ describe("SpotifyLyricsService", () => {
jest.clearAllMocks();
});

it("should have default getter values", async () => {
jest
.spyOn(LyricsHelpers, "lyricsFileExistsAsync")
.mockImplementation(() => Promise.resolve(false));
describe("Getters", () => {
it("should have default getter values", async () => {
jest
.spyOn(LyricsHelpers, "lyricsFileExistsAsync")
.mockImplementation(() => Promise.resolve(false));

const fileExists = await lyrics.trackHasLyricsFile;
expect(fileExists).toBe(false);
const fileExists = await lyrics.trackHasLyricsFile;
expect(fileExists).toBe(false);

for (const [key, value] of Object.entries(defaults)) {
expect(lyrics[key as keyof SpotifyLyricsService]).toBe(value);
}
for (const [key, value] of Object.entries(defaults)) {
expect(lyrics[key as keyof SpotifyLyricsService]).toBe(value);
}
});
});

it("should return true if file exists if path check resolves true", async () => {
const fileExists = await lyrics.trackHasLyricsFile;
expect(fileExists).toBe(true);
});
describe("Helper Functions", () => {
describe("lyricsFileExistsAsync", () => {
it("should return true if file exists if path check resolves true", async () => {
const fileExists = await lyrics.trackHasLyricsFile;
expect(fileExists).toBe(true);
});

it("should load lyrics file if file exists", async () => {
await lyrics.loadLyricsFileAsync();
it("should load lyrics file if file exists", async () => {
await lyrics.loadLyricsFileAsync();

const response = await lyrics.formatLines(testLyricData);
const response = await lyrics.formatLines(testLyricData);

expect(response).toEqual(
testLyricData.lyrics.lines.map((l) => ({
...l,
startTimeMs: Number(l.startTimeMs),
endTimeMs: Number(l.endTimeMs),
}))
);
expect(response).toEqual(
testLyricData.lyrics.lines.map((l) => ({
...l,
startTimeMs: Number(l.startTimeMs),
endTimeMs: Number(l.endTimeMs),
}))
);
});
});
});
});
66 changes: 36 additions & 30 deletions src/utils/spotify/player/playlist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SpotifyPlaylistService } from "@utils/spotify/player/playlist";
import { testPlaylist } from "@/testData";
import { getBiggestImageUrl } from "@utils/array";

describe("SpotifyPlaylistService", () => {
describe("Spotify - Playlist Service", () => {
let spotify: SpotifyService;
let playlist: SpotifyPlaylistService;

Expand Down Expand Up @@ -36,42 +36,48 @@ describe("SpotifyPlaylistService", () => {
jest.spyOn(spotify.events, "trigger").mockImplementation(() => {});
});

it("should have default getter values", () => {
for (const [key, value] of Object.entries(defaults)) {
expect(playlist[key as keyof SpotifyPlaylistService]).toBe(value);
}
describe("Getters", () => {
it("should have default getter values", () => {
for (const [key, value] of Object.entries(defaults)) {
expect(playlist[key as keyof SpotifyPlaylistService]).toBe(value);
}
});
});

it("should fetch playlist by uri", async () => {
const response = await playlist.fetchByUriAsync(testPlaylist.uri);
expect(response).toBe(testPlaylist);
describe("fetchByUriAsync", () => {
it("should fetch playlist by uri", async () => {
const response = await playlist.fetchByUriAsync(testPlaylist.uri);
expect(response).toBe(testPlaylist);
});
});

it("should update current playlist", async () => {
await playlist.updateByUriAsync(testPlaylist.uri);
describe("updateByUriAsync", () => {
it("should update current playlist", async () => {
await playlist.updateByUriAsync(testPlaylist.uri);

expect(playlist.isActive).toBe(true);
expect(playlist.id).toBe(testPlaylist.id);
expect(playlist.name).toBe(testPlaylist.name);
expect(playlist.description).toBe(testPlaylist.description);
expect(playlist.url).toBe(testPlaylist.external_urls.spotify);
expect(playlist.uri).toBe(testPlaylist.uri);
expect(playlist.coverImageUrl).toBe(
getBiggestImageUrl(testPlaylist.images)
);
expect(playlist.owner).toBe(testPlaylist.owner.display_name);
expect(playlist.ownerUrl).toBe(testPlaylist.owner.external_urls.spotify);
expect(playlist.length).toBe(testPlaylist.tracks.total);
});
expect(playlist.isActive).toBe(true);
expect(playlist.id).toBe(testPlaylist.id);
expect(playlist.name).toBe(testPlaylist.name);
expect(playlist.description).toBe(testPlaylist.description);
expect(playlist.url).toBe(testPlaylist.external_urls.spotify);
expect(playlist.uri).toBe(testPlaylist.uri);
expect(playlist.coverImageUrl).toBe(
getBiggestImageUrl(testPlaylist.images)
);
expect(playlist.owner).toBe(testPlaylist.owner.display_name);
expect(playlist.ownerUrl).toBe(testPlaylist.owner.external_urls.spotify);
expect(playlist.length).toBe(testPlaylist.tracks.total);
});

it("should clear playlist if null is passed through update", async () => {
// fill playlist to ensure null update actually has to do something
await playlist.updateByUriAsync(testPlaylist.uri);
it("should clear playlist if null is passed through update", async () => {
// fill playlist to ensure null update actually has to do something
await playlist.updateByUriAsync(testPlaylist.uri);

await playlist.updateByUriAsync(null);
await playlist.updateByUriAsync(null);

for (const [key, value] of Object.entries(defaults)) {
expect(playlist[key as keyof SpotifyPlaylistService]).toBe(value);
}
for (const [key, value] of Object.entries(defaults)) {
expect(playlist[key as keyof SpotifyPlaylistService]).toBe(value);
}
});
});
});
Loading
Loading