diff --git a/src/adapters/apple-music.ts b/src/adapters/apple-music.ts index f3df285..9b5b9ee 100644 --- a/src/adapters/apple-music.ts +++ b/src/adapters/apple-music.ts @@ -1,5 +1,5 @@ import { ENV } from '~/config/env'; -import { MetadataType, ServiceType } from '~/config/enum'; +import { MetadataType, Adapter } from '~/config/enum'; import { RESPONSE_COMPARE_MIN_SCORE } from '~/config/constants'; import HttpClient from '~/utils/http-client'; @@ -31,7 +31,7 @@ export async function getAppleMusicLink(query: string, metadata: SearchMetadata) // apple music does not support x-www-form-urlencoded encoding const params = `term=${encodeURIComponent(query)}`; - const url = new URL(`${ENV.services.appleMusic.apiUrl}/search?${params}`); + const url = new URL(`${ENV.adapters.appleMusic.apiUrl}/search?${params}`); const cache = await getCachedSearchResultLink(url); if (cache) { @@ -50,7 +50,7 @@ export async function getAppleMusicLink(query: string, metadata: SearchMetadata) const { href, score } = getResultWithBestScore(doc, listElements, query); const searchResultLink = { - type: ServiceType.AppleMusic, + type: Adapter.AppleMusic, url: href, isVerified: score > RESPONSE_COMPARE_MIN_SCORE, } as SearchResultLink; diff --git a/src/adapters/deezer.ts b/src/adapters/deezer.ts index 9a56258..1c50c54 100644 --- a/src/adapters/deezer.ts +++ b/src/adapters/deezer.ts @@ -1,5 +1,5 @@ import { ENV } from '~/config/env'; -import { MetadataType, ServiceType } from '~/config/enum'; +import { MetadataType, Adapter } from '~/config/enum'; import { ADAPTERS_QUERY_LIMIT } from '~/config/constants'; import HttpClient from '~/utils/http-client'; @@ -41,7 +41,7 @@ export async function getDeezerLink(query: string, metadata: SearchMetadata) { limit: String(ADAPTERS_QUERY_LIMIT), }); - const url = new URL(`${ENV.services.deezer.apiUrl}/${searchType}`); + const url = new URL(`${ENV.adapters.deezer.apiUrl}/${searchType}`); url.search = params.toString(); const cache = await getCachedSearchResultLink(url); @@ -60,7 +60,7 @@ export async function getDeezerLink(query: string, metadata: SearchMetadata) { const [{ title, name, link }] = response.data; const searchResultLink = { - type: ServiceType.Deezer, + type: Adapter.Deezer, url: link, isVerified: responseMatchesQuery(title ?? name ?? '', query), } as SearchResultLink; diff --git a/src/adapters/soundcloud.ts b/src/adapters/soundcloud.ts index a410a10..e57608c 100644 --- a/src/adapters/soundcloud.ts +++ b/src/adapters/soundcloud.ts @@ -1,5 +1,5 @@ import { ENV } from '~/config/env'; -import { MetadataType, ServiceType } from '~/config/enum'; +import { MetadataType, Adapter } from '~/config/enum'; import { RESPONSE_COMPARE_MIN_SCORE } from '~/config/constants'; import HttpClient from '~/utils/http-client'; @@ -19,7 +19,7 @@ export async function getSoundCloudLink(query: string, metadata: SearchMetadata) q: query, }); - const url = new URL(`${ENV.services.soundCloud.baseUrl}/search`); + const url = new URL(`${ENV.adapters.soundCloud.baseUrl}/search`); url.search = params.toString(); const cache = await getCachedSearchResultLink(url); @@ -45,8 +45,8 @@ export async function getSoundCloudLink(query: string, metadata: SearchMetadata) } const searchResultLink = { - type: ServiceType.SoundCloud, - url: `${ENV.services.soundCloud.baseUrl}${href}`, + type: Adapter.SoundCloud, + url: `${ENV.adapters.soundCloud.baseUrl}${href}`, isVerified: true, } as SearchResultLink; diff --git a/src/adapters/spotify.ts b/src/adapters/spotify.ts index 6d6133c..1840791 100644 --- a/src/adapters/spotify.ts +++ b/src/adapters/spotify.ts @@ -5,7 +5,7 @@ import { SPOTIFY_LINK_DESKTOP_REGEX, SPOTIFY_LINK_MOBILE_REGEX, } from '~/config/constants'; -import { MetadataType, ServiceType } from '~/config/enum'; +import { MetadataType, Adapter } from '~/config/enum'; import HttpClient from '~/utils/http-client'; import { logger } from '~/utils/logger'; @@ -61,7 +61,7 @@ export async function getSpotifyLink(query: string, metadata: SearchMetadata) { limit: String(ADAPTERS_QUERY_LIMIT), }); - const url = new URL(ENV.services.spotify.apiUrl); + const url = new URL(ENV.adapters.spotify.apiUrl); url.search = params.toString(); const cache = await getCachedSearchResultLink(url); @@ -86,7 +86,7 @@ export async function getSpotifyLink(query: string, metadata: SearchMetadata) { const { name, external_urls } = data.items[0]; const searchResultLink = { - type: ServiceType.Spotify, + type: Adapter.Spotify, url: external_urls.spotify, isVerified: responseMatchesQuery(name ?? '', query), } as SearchResultLink; @@ -103,7 +103,7 @@ export async function fetchSpotifyMetadata(spotifyLink: string) { let url = spotifyLink; const spotifyHeaders = { - 'User-Agent': `${ENV.services.spotify.clientVersion} (Macintosh; Apple Silicon)`, + 'User-Agent': `${ENV.adapters.spotify.clientVersion} (Macintosh; Apple Silicon)`, }; let html = await HttpClient.get(url, { @@ -145,7 +145,7 @@ export async function getOrUpdateSpotifyAccessToken() { }); const response = await HttpClient.post( - ENV.services.spotify.authUrl, + ENV.adapters.spotify.authUrl, data, { headers: { @@ -154,7 +154,7 @@ export async function getOrUpdateSpotifyAccessToken() { Authorization: 'Basic ' + Buffer.from( - ENV.services.spotify.clientId + ':' + ENV.services.spotify.clientSecret + ENV.adapters.spotify.clientId + ':' + ENV.adapters.spotify.clientSecret ).toString('base64'), }, } diff --git a/src/adapters/tidal.ts b/src/adapters/tidal.ts index 1de64ae..55aa296 100644 --- a/src/adapters/tidal.ts +++ b/src/adapters/tidal.ts @@ -1,5 +1,5 @@ import { ENV } from '~/config/env'; -import { ServiceType } from '~/config/enum'; +import { Adapter } from '~/config/enum'; import { SearchResultLink } from '~/services/search'; @@ -8,11 +8,11 @@ export function getTidalLink(query: string) { q: query, }); - const url = new URL(`${ENV.services.tidal.baseUrl}/search`); + const url = new URL(`${ENV.adapters.tidal.baseUrl}/search`); url.search = params.toString(); return { - type: ServiceType.Tidal, + type: Adapter.Tidal, url: url.toString(), } as SearchResultLink; } diff --git a/src/adapters/youtube.ts b/src/adapters/youtube.ts index c147c72..cff7a44 100644 --- a/src/adapters/youtube.ts +++ b/src/adapters/youtube.ts @@ -1,5 +1,5 @@ import { ENV } from '~/config/env'; -import { MetadataType, ServiceType } from '~/config/enum'; +import { MetadataType, Adapter } from '~/config/enum'; import { logger } from '~/utils/logger'; @@ -23,7 +23,7 @@ export async function getYouTubeLink(query: string, metadata: SearchMetadata) { q: `${query} ${YOUTUBE_SEARCH_TYPES[metadata.type]}`, }); - const url = new URL(ENV.services.youTube.musicUrl); + const url = new URL(ENV.adapters.youTube.musicUrl); url.search = params.toString(); const cache = await getCachedSearchResultLink(url); @@ -40,7 +40,7 @@ export async function getYouTubeLink(query: string, metadata: SearchMetadata) { secure: true, }; - const cookies = ENV.services.youTube.cookies.split(';').map(cookie => { + const cookies = ENV.adapters.youTube.cookies.split(';').map(cookie => { const [name, value] = cookie.split('='); return { ...youtubeCookie, @@ -60,7 +60,7 @@ export async function getYouTubeLink(query: string, metadata: SearchMetadata) { } const searchResultLink = { - type: ServiceType.YouTube, + type: Adapter.YouTube, url: link, isVerified: true, } as SearchResultLink; @@ -78,7 +78,7 @@ export async function fetchYoutubeMetadata(youtubeLink: string) { const html = await HttpClient.get(youtubeLink, { headers: { - Cookie: ENV.services.youTube.cookies, + Cookie: ENV.adapters.youTube.cookies, }, }); diff --git a/src/config/enum.ts b/src/config/enum.ts index 53d1a0f..62815cb 100644 --- a/src/config/enum.ts +++ b/src/config/enum.ts @@ -1,4 +1,4 @@ -export enum ServiceType { +export enum Adapter { Spotify = 'spotify', YouTube = 'youTube', AppleMusic = 'appleMusic', diff --git a/src/config/env.ts b/src/config/env.ts index 8ef8968..050758d 100644 --- a/src/config/env.ts +++ b/src/config/env.ts @@ -1,7 +1,7 @@ import { version } from '../../package.json'; export const ENV = { - services: { + adapters: { spotify: { authUrl: Bun.env.SPOTIFY_AUTH_URL!, clientId: Bun.env.SPOTIFY_CLIENT_ID!, diff --git a/src/parsers/link.ts b/src/parsers/link.ts index 6833d3e..069a6aa 100644 --- a/src/parsers/link.ts +++ b/src/parsers/link.ts @@ -1,25 +1,25 @@ import { ParseError } from 'elysia'; import { SPOTIFY_LINK_REGEX, YOUTUBE_LINK_REGEX } from '~/config/constants'; -import { ServiceType } from '~/config/enum'; +import { Adapter } from '~/config/enum'; import { getSourceFromId } from '~/utils/encoding'; import { logger } from '~/utils/logger'; -export type SearchService = { +export type SearchParser = { id: string; type: string; source: string; }; -export const getSearchService = async (link?: string, searchId?: string) => { +export const getSearchParser = async (link?: string, searchId?: string) => { const decodedSource = searchId ? getSourceFromId(searchId) : undefined; let source = link; if (searchId && decodedSource) { logger.info( - `[${getSearchService.name}] (${searchId}) source decoded: ${decodedSource}` + `[${getSearchParser.name}] (${searchId}) source decoded: ${decodedSource}` ); source = decodedSource; } @@ -29,24 +29,24 @@ export const getSearchService = async (link?: string, searchId?: string) => { const spotifyId = source!.match(SPOTIFY_LINK_REGEX)?.[3]; if (spotifyId) { id = spotifyId; - type = ServiceType.Spotify; + type = Adapter.Spotify; } const youtubeId = source!.match(YOUTUBE_LINK_REGEX)?.[1]; if (youtubeId) { id = youtubeId; - type = ServiceType.YouTube; + type = Adapter.YouTube; } if (!id || !type) { throw new ParseError('Service id could not be extracted from source.'); } - const searchService = { + const searchParser = { id, type, source, - } as SearchService; + } as SearchParser; - return searchService; + return searchParser; }; diff --git a/src/routes/api.ts b/src/routes/api.ts index 72ae533..f2f400f 100644 --- a/src/routes/api.ts +++ b/src/routes/api.ts @@ -1,6 +1,7 @@ import { Elysia } from 'elysia'; import { logger } from '~/utils/logger'; +import { Adapter } from '~/config/enum'; import { apiVersionValidator, searchPayloadValidator } from '~/validations/search'; @@ -18,8 +19,8 @@ export const apiRouter = new Elysia().group('/api', app => }) .post( '/search', - async ({ body: { link } }) => { - const searchResult = await search(link); + async ({ body: { link, adapters } }) => { + const searchResult = await search({ link, adapters: adapters as Adapter[] }); return searchResult; }, diff --git a/src/routes/page.tsx b/src/routes/page.tsx index f630bee..da617a9 100644 --- a/src/routes/page.tsx +++ b/src/routes/page.tsx @@ -36,7 +36,7 @@ export const pageRouter = new Elysia() '/', async ({ query: { id }, redirect }) => { try { - const searchResult = id ? await search(undefined, id) : undefined; + const searchResult = id ? await search({ searchId: id }) : undefined; return ( { - const searchResult = await search(link); + const searchResult = await search({ link }); return ; }, { diff --git a/src/services/search.ts b/src/services/search.ts index afc7539..9317838 100644 --- a/src/services/search.ts +++ b/src/services/search.ts @@ -1,9 +1,9 @@ import { ENV } from '~/config/env'; -import { MetadataType, ServiceType } from '~/config/enum'; +import { MetadataType, Adapter } from '~/config/enum'; import { logger } from '~/utils/logger'; -import { getSearchService } from '~/parsers/link'; +import { getSearchParser } from '~/parsers/link'; import { getSpotifyMetadata, getSpotifyQueryFromMetadata } from '~/parsers/spotify'; import { getYouTubeMetadata, getYouTubeQueryFromMetadata } from '~/parsers/youtube'; @@ -25,7 +25,7 @@ export type SearchMetadata = { }; export type SearchResultLink = { - type: ServiceType; + type: Adapter; url: string; isVerified?: boolean; }; @@ -42,18 +42,35 @@ export type SearchResult = { links: SearchResultLink[]; }; -export const search = async (link?: string, searchId?: string) => { - const searchService = await getSearchService(link, searchId); +export const search = async ({ + link, + searchId, + adapters, +}: { + link?: string; + searchId?: string; + adapters?: Adapter[]; +}) => { + const searchAdapters = adapters ?? [ + Adapter.Spotify, + Adapter.YouTube, + Adapter.AppleMusic, + Adapter.Deezer, + Adapter.SoundCloud, + Adapter.Tidal, + ]; + + const searchParser = await getSearchParser(link, searchId); let metadata, query; - if (searchService.type === ServiceType.Spotify) { - metadata = await getSpotifyMetadata(searchService.id, link!); + if (searchParser.type === Adapter.Spotify) { + metadata = await getSpotifyMetadata(searchParser.id, link!); query = getSpotifyQueryFromMetadata(metadata); } - if (searchService.type === ServiceType.YouTube) { - metadata = await getYouTubeMetadata(searchService.id, link!); + if (searchParser.type === Adapter.YouTube) { + metadata = await getYouTubeMetadata(searchParser.id, link!); query = getYouTubeQueryFromMetadata(metadata); } @@ -62,32 +79,62 @@ export const search = async (link?: string, searchId?: string) => { } logger.info( - `[${search.name}] (params) ${JSON.stringify({ searchService, metadata, query }, null, 2)}` + `[${search.name}] (params) ${JSON.stringify({ searchParser, metadata, query }, null, 2)}` ); - const id = generateId(searchService.source); - const universalLinkPromise = shortenLink(`${ENV.app.url}?id=${id}`); + const id = generateId(searchParser.source); + const universalLink = `${ENV.app.url}?id=${id}`; + + if (searchAdapters.length === 1 && searchAdapters[0] === searchParser.type) { + logger.info(`[${search.name}] early return - adapter is equal to parser type`); + + return { + id, + type: metadata.type, + title: metadata.title, + description: metadata.description, + image: metadata.image, + audio: metadata.audio, + source: searchParser.source, + universalLink, + links: [ + { + type: searchParser.type, + url: link, + isVerified: true, + }, + ], + }; + } const searchResultsPromise = Promise.all([ - searchService.type !== ServiceType.Spotify ? getSpotifyLink(query, metadata) : null, - searchService.type !== ServiceType.YouTube ? getYouTubeLink(query, metadata) : null, - getAppleMusicLink(query, metadata), - getDeezerLink(query, metadata), - getSoundCloudLink(query, metadata), + searchAdapters.includes(Adapter.Spotify) && searchParser.type !== Adapter.Spotify + ? getSpotifyLink(query, metadata) + : null, + searchAdapters.includes(Adapter.YouTube) && searchParser.type !== Adapter.YouTube + ? getYouTubeLink(query, metadata) + : null, + searchAdapters.includes(Adapter.AppleMusic) + ? getAppleMusicLink(query, metadata) + : null, + searchAdapters.includes(Adapter.Deezer) ? getDeezerLink(query, metadata) : null, + searchAdapters.includes(Adapter.SoundCloud) + ? getSoundCloudLink(query, metadata) + : null, ]); - const [searchResults, universalLink] = await Promise.all([ + const [searchResults, shortLink] = await Promise.all([ searchResultsPromise, - universalLinkPromise, + shortenLink(`${ENV.app.url}?id=${id}`), ]); const links = searchResults.filter(Boolean); logger.info(`[${search.name}] (results) ${JSON.stringify(links, null, 2)}`); - // add no-verified links if at least one link is verified - const tidalLink = getTidalLink(query); - if (links.some(link => link?.isVerified)) { + // Add Tidal link if at least one link is verified and Tidal is included in the adapters + if (links.some(link => link?.isVerified) && searchAdapters.includes(Adapter.Tidal)) { + const tidalLink = getTidalLink(query); links.push(tidalLink); } @@ -98,8 +145,8 @@ export const search = async (link?: string, searchId?: string) => { description: metadata.description, image: metadata.image, audio: metadata.audio, - source: searchService.source, - universalLink, + source: searchParser.source, + universalLink: shortLink, links: links as SearchResultLink[], }; diff --git a/src/utils/compare.ts b/src/utils/compare.ts index bfbf91d..0ef6cda 100644 --- a/src/utils/compare.ts +++ b/src/utils/compare.ts @@ -33,5 +33,9 @@ export function getResultWithBestScore( } }); + if (resultWithBestScore.href === '') { + throw new Error(`Result with best score not found for: ${query}`); + } + return resultWithBestScore; } diff --git a/src/utils/http-client.ts b/src/utils/http-client.ts index 63a2ae6..b126946 100644 --- a/src/utils/http-client.ts +++ b/src/utils/http-client.ts @@ -67,8 +67,10 @@ export default class HttpClient { return data as T; } catch (err) { - logger.error(`[${HttpClient.request.name}] Request failed.`); - logger.error(err); + logger.error( + `[${HttpClient.request.name}] Request failed ${(err as Error).message}` + ); + logger.debug(err); throw err; } } diff --git a/src/validations/search.ts b/src/validations/search.ts index b6d5cc8..026dd8a 100644 --- a/src/validations/search.ts +++ b/src/validations/search.ts @@ -1,5 +1,8 @@ import { t } from 'elysia'; import { SPOTIFY_LINK_REGEX, YOUTUBE_LINK_REGEX } from '~/config/constants'; +import { Adapter } from '~/config/enum'; + +const allowedAdapters = Object.values(Adapter); export const searchQueryValidator = t.Object({ id: t.Optional(t.String({ minLength: 1, error: 'Invalid search id' })), @@ -12,6 +15,17 @@ export const searchPayloadValidator = t.Object({ error: 'Invalid link, please try with Spotify or Youtube links.', } ), + adapters: t.Optional( + t.Array( + t.String({ + validate: (value: string) => allowedAdapters.includes(value as Adapter), + error: 'Invalid adapter, please use one of the allowed adapters.', + }), + { + error: 'Invalid adapters array, please provide an array of adapter types.', + } + ) + ), }); export const apiVersionValidator = t.Object({ diff --git a/src/views/components/search-link.tsx b/src/views/components/search-link.tsx index ca6b2b2..4a0bfc1 100644 --- a/src/views/components/search-link.tsx +++ b/src/views/components/search-link.tsx @@ -1,34 +1,34 @@ -import { ServiceType } from '~/config/enum'; +import { Adapter } from '~/config/enum'; const SEARCH_LINK_DICT = { - [ServiceType.Spotify]: { + [Adapter.Spotify]: { icon: 'fab fa-spotify', label: 'Listen on Spotify', }, - [ServiceType.YouTube]: { + [Adapter.YouTube]: { icon: 'fab fa-youtube', label: 'Listen on YouTube Music', }, - [ServiceType.Deezer]: { + [Adapter.Deezer]: { icon: 'fab fa-deezer', label: 'Listen on Deezer', }, - [ServiceType.AppleMusic]: { + [Adapter.AppleMusic]: { icon: 'fab fa-apple', label: 'Listen on Apple Music', }, - [ServiceType.Tidal]: { + [Adapter.Tidal]: { icon: 'fa fa-music', label: 'Listen on Tidal', }, - [ServiceType.SoundCloud]: { + [Adapter.SoundCloud]: { icon: 'fab fa-soundcloud', label: 'Listen on SoundCloud', }, }; export default function SearchLink(props: { - type: ServiceType; + type: Adapter; url: string; isVerified?: boolean; }) { diff --git a/tests/integration/page.test.ts b/tests/integration/page.test.ts index 4f94cb3..0b036a8 100644 --- a/tests/integration/page.test.ts +++ b/tests/integration/page.test.ts @@ -6,7 +6,7 @@ import { formDataRequest } from '../utils/request'; import { app } from '~/index'; -import { MetadataType, ServiceType } from '~/config/enum'; +import { MetadataType, Adapter } from '~/config/enum'; import { cacheSearchMetadata, @@ -69,7 +69,7 @@ describe('Page router', () => { cacheSearchResultLink( new URL('https://music.youtube.com/search?q=Do+Not+Disturb+Drake+song'), { - type: ServiceType.YouTube, + type: Adapter.YouTube, url: 'https://music.youtube.com/watch?v=zhY_0DoQCQs', isVerified: true, } @@ -77,7 +77,7 @@ describe('Page router', () => { cacheSearchResultLink( new URL('https://music.apple.com/ca/search?term=Do%20Not%20Disturb%20Drake'), { - type: ServiceType.AppleMusic, + type: Adapter.AppleMusic, url: 'https://music.apple.com/us/album/do-not-disturb/1440890708?i=1440892237', isVerified: true, } @@ -85,7 +85,7 @@ describe('Page router', () => { cacheSearchResultLink( new URL('https://api.deezer.com/search/track?q=Do+Not+Disturb+Drake&limit=1'), { - type: ServiceType.Deezer, + type: Adapter.Deezer, url: 'https://www.deezer.com/track/144572248', isVerified: true, } @@ -93,7 +93,7 @@ describe('Page router', () => { cacheSearchResultLink( new URL('https://soundcloud.com/search?q=Do+Not+Disturb+Drake'), { - type: ServiceType.SoundCloud, + type: Adapter.SoundCloud, url: 'https://soundcloud.com/octobersveryown/drake-do-not-disturb', isVerified: true, } @@ -166,9 +166,9 @@ describe('Page router', () => { }); it('should return error message when internal server error', async () => { - const getSearchServiceMock = spyOn(linkParser, 'getSearchService'); + const getSearchParserMock = spyOn(linkParser, 'getSearchParser'); - getSearchServiceMock.mockImplementationOnce(() => { + getSearchParserMock.mockImplementationOnce(() => { throw new Error('Injected Error'); }); @@ -180,7 +180,7 @@ describe('Page router', () => { const errorMessage = doc('p').text(); expect(errorMessage).toContain('Something went wrong, try again later.'); - expect(getSearchServiceMock).toHaveBeenCalledTimes(1); + expect(getSearchParserMock).toHaveBeenCalledTimes(1); }); }); }); diff --git a/tests/unit/apple-music.test.ts b/tests/unit/apple-music.test.ts index 5e023d0..7281a02 100644 --- a/tests/unit/apple-music.test.ts +++ b/tests/unit/apple-music.test.ts @@ -3,7 +3,7 @@ import { beforeAll, afterEach, describe, expect, it } from 'bun:test'; import axios from 'axios'; import AxiosMockAdapter from 'axios-mock-adapter'; -import { MetadataType, ServiceType } from '~/config/enum'; +import { MetadataType, Adapter } from '~/config/enum'; import { getAppleMusicLink } from '~/adapters/apple-music'; import { SearchMetadata } from '~/services/search'; @@ -35,7 +35,7 @@ describe('Adapter - Apple Music', () => { } as SearchMetadata); expect(appleMusicLink).toEqual({ - type: ServiceType.AppleMusic, + type: Adapter.AppleMusic, url: 'https://music.apple.com/us/album/do-not-disturb/1440890708?i=1440892237', isVerified: true, }); diff --git a/tests/unit/deezer.test.ts b/tests/unit/deezer.test.ts index 37adc1c..7d58584 100644 --- a/tests/unit/deezer.test.ts +++ b/tests/unit/deezer.test.ts @@ -3,7 +3,7 @@ import { beforeAll, afterEach, describe, expect, it } from 'bun:test'; import axios from 'axios'; import AxiosMockAdapter from 'axios-mock-adapter'; -import { MetadataType, ServiceType } from '~/config/enum'; +import { MetadataType, Adapter } from '~/config/enum'; import { getDeezerLink } from '~/adapters/deezer'; import { SearchMetadata } from '~/services/search'; @@ -33,7 +33,7 @@ describe('Adapter - Deezer', () => { } as SearchMetadata); expect(deezerLink).toEqual({ - type: ServiceType.Deezer, + type: Adapter.Deezer, url: 'https://www.deezer.com/track/144572248', isVerified: true, }); diff --git a/tests/unit/soundcloud.test.ts b/tests/unit/soundcloud.test.ts index b92a24a..701c8f2 100644 --- a/tests/unit/soundcloud.test.ts +++ b/tests/unit/soundcloud.test.ts @@ -3,7 +3,7 @@ import { beforeAll, afterEach, describe, expect, it } from 'bun:test'; import axios from 'axios'; import AxiosMockAdapter from 'axios-mock-adapter'; -import { MetadataType, ServiceType } from '~/config/enum'; +import { MetadataType, Adapter } from '~/config/enum'; import { getSoundCloudLink } from '~/adapters/soundcloud'; import { SearchMetadata } from '~/services/search'; @@ -35,7 +35,7 @@ describe('Adapter - SoundCloud', () => { } as SearchMetadata); expect(soundCloudLink).toEqual({ - type: ServiceType.SoundCloud, + type: Adapter.SoundCloud, url: 'https://soundcloud.com/octobersveryown/drake-do-not-disturb', isVerified: true, }); diff --git a/tests/unit/youtube.test.ts b/tests/unit/youtube.test.ts index e94855d..405a1a1 100644 --- a/tests/unit/youtube.test.ts +++ b/tests/unit/youtube.test.ts @@ -1,6 +1,6 @@ import { afterEach, describe, expect, it, mock, jest } from 'bun:test'; -import { MetadataType, ServiceType } from '~/config/enum'; +import { MetadataType, Adapter } from '~/config/enum'; import { getYouTubeLink } from '~/adapters/youtube'; import { getLinkWithPuppeteer } from '~/utils/scraper'; import { SearchMetadata } from '~/services/search'; @@ -31,7 +31,7 @@ describe('Adapter - YouTube', () => { } as SearchMetadata); expect(youTubeLink).toEqual({ - type: ServiceType.YouTube, + type: Adapter.YouTube, url: mockedYoutubeLink, isVerified: true, }); diff --git a/tests/utils/shared.ts b/tests/utils/shared.ts index 25b7eca..022a0cb 100644 --- a/tests/utils/shared.ts +++ b/tests/utils/shared.ts @@ -58,7 +58,7 @@ export const getYouTubeSearchLink = (query: string, type: string) => { q: `${query} ${type}`, }); - const url = new URL(ENV.services.youTube.musicUrl); + const url = new URL(ENV.adapters.youTube.musicUrl); url.search = params.toString(); return url.toString(); @@ -67,7 +67,7 @@ export const getYouTubeSearchLink = (query: string, type: string) => { export const getAppleMusicSearchLink = (query: string) => { const params = `?term=${encodeURIComponent(query)}`; - const url = new URL(`${ENV.services.appleMusic.apiUrl}/search${params}`); + const url = new URL(`${ENV.adapters.appleMusic.apiUrl}/search${params}`); url.search = params.toString(); return url.toString(); @@ -79,7 +79,7 @@ export const getDeezerSearchLink = (query: string, type: string) => { limit: '1', }); - const url = new URL(`${ENV.services.deezer.apiUrl}/${type}`); + const url = new URL(`${ENV.adapters.deezer.apiUrl}/${type}`); url.search = params.toString(); return url.toString(); @@ -90,7 +90,7 @@ export const getSoundCloudSearchLink = (query: string) => { q: query, }); - const url = new URL(`${ENV.services.soundCloud.baseUrl}/search`); + const url = new URL(`${ENV.adapters.soundCloud.baseUrl}/search`); url.search = params.toString(); return url.toString();