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
7 changes: 1 addition & 6 deletions composables/useApi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,6 @@ export interface Videos {
type MediaType = 'audiobook' | 'music' | 'podcast' | 'podcastepisode' | 'video';

type PodcastStatus =
| 'completed'
| 'deleted'
| 'downloading'
| 'error'
| 'new'
| 'skipped';
'completed' | 'deleted' | 'downloading' | 'error' | 'new' | 'skipped';

type ResponseStatus = 'failed' | 'ok';
12 changes: 5 additions & 7 deletions composables/useAudioPlayer/mediaSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,11 @@ export function useMediaSession(actions: MediaSessionActions) {
}

function setMediaSessionPositionState() {
if (
!(
hasMediaSession &&
actions.hasCurrentTrack.value &&
!actions.isRadioStation.value
)
) {
if (!(
hasMediaSession &&
actions.hasCurrentTrack.value &&
!actions.isRadioStation.value
)) {
return;
}

Expand Down
12 changes: 5 additions & 7 deletions middleware/albums.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
export default defineNuxtRouteMiddleware((to) => {
if (
!(
to.params[ROUTE_PARAM_KEYS.albums.sortBy] &&
Object.keys(ALBUMS_SORT_BY).includes(
to.params[ROUTE_PARAM_KEYS.albums.sortBy] as string,
)
if (!(
to.params[ROUTE_PARAM_KEYS.albums.sortBy] &&
Object.keys(ALBUMS_SORT_BY).includes(
to.params[ROUTE_PARAM_KEYS.albums.sortBy] as string,
)
) {
)) {
return navigateTo({
name: ROUTE_NAMES.albums,
params: {
Expand Down
12 changes: 5 additions & 7 deletions middleware/favourites.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
export default defineNuxtRouteMiddleware((to) => {
if (
!(
to.params[ROUTE_PARAM_KEYS.favourites.mediaType] &&
Object.values(ROUTE_MEDIA_TYPE_PARAMS).includes(
to.params[ROUTE_PARAM_KEYS.favourites.mediaType] as never,
)
if (!(
to.params[ROUTE_PARAM_KEYS.favourites.mediaType] &&
Object.values(ROUTE_MEDIA_TYPE_PARAMS).includes(
to.params[ROUTE_PARAM_KEYS.favourites.mediaType] as never,
)
) {
)) {
return navigateTo({
name: ROUTE_NAMES.favourites,
params: {
Expand Down
14 changes: 6 additions & 8 deletions middleware/genre.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
export default defineNuxtRouteMiddleware((to) => {
if (
!(
to.params[ROUTE_PARAM_KEYS.genre.mediaType] &&
to.params[ROUTE_PARAM_KEYS.genre.genre] &&
[ROUTE_MEDIA_TYPE_PARAMS.Albums, ROUTE_MEDIA_TYPE_PARAMS.Tracks].includes(
to.params[ROUTE_PARAM_KEYS.genre.mediaType] as never,
)
if (!(
to.params[ROUTE_PARAM_KEYS.genre.mediaType] &&
to.params[ROUTE_PARAM_KEYS.genre.genre] &&
[ROUTE_MEDIA_TYPE_PARAMS.Albums, ROUTE_MEDIA_TYPE_PARAMS.Tracks].includes(
to.params[ROUTE_PARAM_KEYS.genre.mediaType] as never,
)
) {
)) {
return navigateTo({
name: ROUTE_NAMES.genres,
});
Expand Down
14 changes: 6 additions & 8 deletions middleware/podcast.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
export default defineNuxtRouteMiddleware((to) => {
if (
!(
to.params[ROUTE_PARAM_KEYS.podcast.sortBy] &&
to.params[ROUTE_PARAM_KEYS.podcast.id] &&
Object.values(ROUTE_PODCAST_FILTER_PARAMS).includes(
to.params[ROUTE_PARAM_KEYS.podcast.sortBy] as never,
)
if (!(
to.params[ROUTE_PARAM_KEYS.podcast.sortBy] &&
to.params[ROUTE_PARAM_KEYS.podcast.id] &&
Object.values(ROUTE_PODCAST_FILTER_PARAMS).includes(
to.params[ROUTE_PARAM_KEYS.podcast.sortBy] as never,
)
) {
)) {
return navigateTo({
name: ROUTE_NAMES.podcasts,
});
Expand Down
14 changes: 6 additions & 8 deletions middleware/search.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
export default defineNuxtRouteMiddleware((to) => {
if (
!(
to.params[ROUTE_PARAM_KEYS.search.mediaType] &&
to.params[ROUTE_PARAM_KEYS.search.query] &&
Object.values(ROUTE_MEDIA_TYPE_PARAMS).includes(
to.params[ROUTE_PARAM_KEYS.search.mediaType] as never,
)
if (!(
to.params[ROUTE_PARAM_KEYS.search.mediaType] &&
to.params[ROUTE_PARAM_KEYS.search.query] &&
Object.values(ROUTE_MEDIA_TYPE_PARAMS).includes(
to.params[ROUTE_PARAM_KEYS.search.mediaType] as never,
)
) {
)) {
return navigateTo({
name: ROUTE_NAMES.index,
});
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,50 @@
"dependencies": {
"@phosphor-icons/vue": "^2.2.1",
"crypto-js": "^4.2.0",
"nuxt": "^4.4.7",
"nuxt": "^4.5.1",
"nuxt-swiper": "^2.0.2",
"vue": "^3.5.29"
},
"description": "A responsive, modern web-based client designed for Subsonic music servers.",
"devDependencies": {
"@csstools/postcss-global-data": "^4.0.0",
"@eslint/compat": "^2.1.0",
"@nuxt/eslint": "^1.15.2",
"@nuxt/eslint": "^1.16.0",
"@nuxt/test-utils": "^3.23.0",
"@nuxtjs/stylelint-module": "^5.2.1",
"@playwright/test": "^1.60.0",
"@playwright/test": "^1.62.1",
"@types/crypto-js": "^4.2.2",
"@types/node": "^26.1.0",
"@types/node": "^26.1.2",
"@vite-pwa/assets-generator": "^1.0.2",
"@vite-pwa/nuxt": "^1.1.1",
"@vitest/coverage-istanbul": "^4.1.8",
"@vue/test-utils": "^2.4.10",
"@vitest/coverage-istanbul": "^4.1.10",
"@vue/test-utils": "^2.4.11",
"eslint": "^9.39.2",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-perfectionist": "^5.9.0",
"eslint-plugin-perfectionist": "^5.10.0",
"eslint-plugin-prettier": "^5.5.6",
"eslint-plugin-vitest": "^0.5.4",
"eslint-plugin-vue": "^10.9.1",
"happy-dom": "^20.9.0",
"eslint-plugin-vue": "^10.10.0",
"happy-dom": "^20.11.1",
"husky": "^9.1.7",
"lint-staged": "^17.0.7",
"playwright-core": "^1.60.0",
"postcss": "^8.5.23",
"lint-staged": "^17.3.0",
"playwright-core": "^1.62.1",
"postcss": "^8.5.25",
"postcss-custom-media": "^12.0.1",
"postcss-extend-rule": "^4.0.0",
"postcss-html": "^1.8.1",
"postcss-preset-env": "^11.3.0",
"postcss-preset-env": "^11.3.2",
"postcss-pxtorem": "^6.1.0",
"postcss-rem": "^3.1.0",
"prettier": "^3.8.3",
"prettier": "^3.9.6",
"stylelint": "^16.26.1",
"stylelint-config-recess-order": "^7.7.0",
"stylelint-config-recommended-vue": "^1.6.1",
"stylelint-config-standard": "^39.0.1",
"stylelint-order": "^8.1.1",
"typescript": "^5.9.3",
"vitest": "^4.1.8",
"vue-tsc": "^3.3.3"
"vitest": "^4.1.10",
"vue-tsc": "^3.3.9"
},
"homepage": "https://github.com/VD39/subsonic-player#readme",
"keywords": [
Expand Down
19 changes: 13 additions & 6 deletions plugins/api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { mockNuxtImport } from '@nuxt/test-utils/runtime';

import apiPlugin from './api';

let onResponseCallback: (typeof $fetch)['arguments'][0]['onResponse'];

globalThis.$fetch = {
create: vi.fn().mockImplementation((options) => {
onResponseCallback = options.onResponse;
const $fetchMock = vi.hoisted(() => {
const baseFetchMock = vi.fn();

return Object.assign(baseFetchMock, {
create: vi.fn().mockImplementation((options) => {
onResponseCallback = options?.onResponse;
return baseFetchMock;
}),
});
});

return vi.fn();
}),
} as unknown as typeof $fetch;
mockNuxtImport('$fetch', () => $fetchMock);

describe('api plugin', () => {
beforeEach(() => {
Expand Down
51 changes: 49 additions & 2 deletions server/api/artist.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { MockInstance } from 'vitest';
import { mockNuxtImport } from '@nuxt/test-utils/runtime';

import { artistDataMock, artistInfo2Mock, cookieMock } from '@/test/fixtures';

import artistApi from './artist';

const $fetchMock = vi.spyOn(globalThis, '$fetch') as MockInstance;
const $fetchMock = vi.hoisted(() => vi.fn());

mockNuxtImport('$fetch', () => $fetchMock);

describe('artist-api', () => {
afterEach(() => {
Expand Down Expand Up @@ -109,4 +111,49 @@ describe('artist-api', () => {
});
});
});

describe('when $fetch response for all endpoints returns a value', () => {
beforeEach(() => {
$fetchMock
.mockResolvedValueOnce({
'subsonic-response': {
artistInfo2: artistInfo2Mock,
status: 'ok',
},
})
.mockResolvedValueOnce({
'subsonic-response': {
artist: artistDataMock,
status: 'ok',
},
})
.mockResolvedValueOnce({
'subsonic-response': {
similarSongs2: {
song: [],
},
status: 'ok',
},
})
.mockResolvedValueOnce({
'subsonic-response': {
status: 'ok',
topSongs: {
song: [],
},
},
});
});

it('returns the correct response', async () => {
expect(await artistApi({} as never)).toEqual({
data: expect.objectContaining({
id: 'id',
name: 'name',
similarTracks: [],
topTracks: [],
}),
});
});
});
});
6 changes: 1 addition & 5 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ export type PageNavigationMap = Record<string, ToProp>;
export type PlayableTrack = PodcastEpisode | RadioStation | Track;

export type QueueableMedia =
| Album
| PlayableTrack
| Playlist
| Podcast
| PodcastEpisode;
Album | PlayableTrack | Playlist | Podcast | PodcastEpisode;

export type ReplayGainMode = (typeof REPLAY_GAIN_OPTIONS)[number]['value'];

Expand Down
27 changes: 0 additions & 27 deletions vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,3 @@ config.global.stubs = {

vi.stubGlobal('defineEventHandler', (func: unknown) => func);
vi.stubGlobal('getQuery', () => ({ id: 'id' }));

// Assign $fetch directly on globalThis (not via vi.stubGlobal) so that it
// survives vitest's per-file cleanup. Nuxt's payload.client plugin schedules
// `setTimeout(getAppManifest, 1e3)` which fires *after* the test file is torn
// down, and vi.stubGlobal values are restored (removed) at that point.
if (!globalThis.$fetch) {
const fetchFn = (..._args: unknown[]) => Promise.resolve({});
globalThis.$fetch = Object.assign(fetchFn, {
create: () =>
Object.assign((..._args: unknown[]) => Promise.resolve({}), {
create:
() =>
(..._args: unknown[]) =>
Promise.resolve({}),
}),
}) as typeof globalThis.$fetch;
}

vi.mock('virtual:pwa-register/vue', () => {
return {
useRegisterSW: vi.fn(() => ({
needRefresh: { value: false },
offlineReady: { value: false },
updateServiceWorker: vi.fn(),
})),
};
});
Loading