Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
test: add tests for search
Browse files Browse the repository at this point in the history
  • Loading branch information
vaaski committed Feb 19, 2021
1 parent 2780ad8 commit cce7496
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ search.tracks = searchFactory("search/tracks")
search.albums = searchFactory("search/albums")
search.playlists = searchFactory("search/playlists_without_albums")

// TODO write tests
// TODO write jsdoc
// TODO write docs

Expand Down
5 changes: 2 additions & 3 deletions tests/playlist.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import test from "ava"

import { playlist } from "../src"
import { getClientIDv2 } from "../src/util"
import { playlist, util } from "../src"

const examplePlaylistURL = process.env.EXAMPLE_PLAYLIST_URL || ""
const examplePlaylistID = Number(process.env.EXAMPLE_PLAYLIST_ID) || 0

let client_id2: string

test.before(async () => {
client_id2 = await getClientIDv2()
client_id2 = await util.getClientIDv2()
})

test("get playlist using URL", async t => {
Expand Down
56 changes: 56 additions & 0 deletions tests/search.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import test from "ava"
import { search, util } from "../src"

let client_id: string

test.before(async () => {
client_id = await util.getClientIDv2()
})

test("search for everything", async t => {
const data = await search("noisia")
t.assert(data.collection.length)
t.assert(data.collection[0].id)
})

test("search for everything with client_id", async t => {
const data = await search("noisia", { client_id })
t.assert(data.collection.length)
t.assert(data.collection[0].id)
})

test("search for users", async t => {
const data = await search.users("noisia", { client_id })
t.assert(data.collection.length)
t.assert(data.collection[0].id)

const onlyUsers = !data.collection.find(r => r.kind !== "user")
t.assert(onlyUsers)
})

test("search for playlists", async t => {
const data = await search.playlists("noisia", { client_id })
t.assert(data.collection.length)
t.assert(data.collection[0].id)

const onlyPlaylists = !data.collection.find(r => r.kind !== "playlist")
t.assert(onlyPlaylists)
})

test("search for tracks", async t => {
const data = await search.tracks("noisia", { client_id })
t.assert(data.collection.length)
t.assert(data.collection[0].id)

const onlyTracks = !data.collection.find(r => r.kind !== "track")
t.assert(onlyTracks)
})

test("search for albums", async t => {
const data = await search.albums("noisia", { client_id })
t.assert(data.collection.length)
t.assert(data.collection[0].id)

const onlyPlaylists = !data.collection.find(r => r.kind !== "playlist")
t.assert(onlyPlaylists)
})
5 changes: 2 additions & 3 deletions tests/user.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import test from "ava"

import { user } from "../src"
import { getClientIDv2 } from "../src/util"
import { user, util } from "../src"

const exampleUserURL = process.env.EXAMPLE_USER_URL || ""
const exampleUserID = Number(process.env.EXAMPLE_USER_ID) || 0

let client_id: string

test.before(async () => {
client_id = await getClientIDv2()
client_id = await util.getClientIDv2()
})

test("get user using URL", async t => {
Expand Down

0 comments on commit cce7496

Please sign in to comment.