Skip to content

Commit 38af6b5

Browse files
committed
fix: song suggestions
1 parent dc2fba8 commit 38af6b5

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

src/common/helpers/fetch.helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ export const useFetch = async <T>({
2424
const response = await fetch(url.toString())
2525
const data = await response.json()
2626

27-
return { data: data as T, ...response }
27+
return { data: data as T, ok: response.ok }
2828
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import { beforeAll, describe, it } from 'vitest'
2-
// import { CreateSongStationUseCase, GetSongByIdUseCase } from '#modules/songs/use-cases'
1+
import { beforeAll, describe, expect, it } from 'vitest'
2+
import { CreateSongStationUseCase } from '#modules/songs/use-cases'
33

44
describe('CreateSongStation', () => {
5-
// let createSongStation: CreateSongStationUseCase
5+
let createSongStation: CreateSongStationUseCase
66

77
beforeAll(() => {
8-
// createSongStation = new CreateSongStationUseCase()
8+
createSongStation = new CreateSongStationUseCase()
99
})
1010

1111
it('should create a song station', async () => {
12-
// const station = await createSongStation.execute('3IoDK8qI')
13-
// expect(station).toBeDefined()
12+
const station = await createSongStation.execute('3IoDK8qI')
13+
14+
expect(station).toBeDefined()
1415
})
1516
})

src/modules/songs/use-cases/create-song-station/create-song-station.use-case.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ export class CreateSongStationUseCase implements IUseCase<string, string> {
1414
params: {
1515
entity_id: encodedSongId,
1616
entity_type: 'queue'
17-
}
17+
},
18+
context: 'android'
1819
})
1920

20-
if (!data || !data.stationid || !ok) throw new HTTPException(500, { message: 'could not create station' })
21+
if (!data || !ok || !data.stationid) throw new HTTPException(500, { message: 'could not create station' })
2122

2223
return data.stationid
2324
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { beforeAll, describe, expect, it } from 'vitest'
2+
import { GetSongSuggestionsUseCase } from '#modules/songs/use-cases'
3+
import { SongModel } from '#modules/songs/models'
4+
5+
describe('GetSongSuggestions', () => {
6+
let getSongSuggestions: GetSongSuggestionsUseCase
7+
8+
beforeAll(() => {
9+
getSongSuggestions = new GetSongSuggestionsUseCase()
10+
})
11+
12+
it('should return suggestions for a song', async () => {
13+
const suggestions = await getSongSuggestions.execute({ songId: '3IoDK8qI', limit: 5 })
14+
15+
expect(() => SongModel.parse(suggestions[0])).not.toThrow()
16+
})
17+
})

src/modules/songs/use-cases/get-song-suggestions/get-song-suggestions.use-case.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export class GetSongSuggestionsUseCase implements IUseCase<GetSongSuggestionsArg
2727
params: {
2828
stationid: stationId,
2929
k: limit
30-
}
30+
},
31+
context: 'android'
3132
})
3233

3334
if (!data || !ok) {

0 commit comments

Comments
 (0)