mirror of
https://github.com/BradNut/graphbrainz
synced 2025-09-08 17:40:32 +00:00
Move test client creation to before()
This commit is contained in:
parent
ed2c68ef22
commit
b6f2e2d3f7
4 changed files with 50 additions and 10 deletions
20
test/api.js
20
test/api.js
|
|
@ -1,23 +1,23 @@
|
|||
import path from 'path'
|
||||
import test from 'ava'
|
||||
import sepia from 'sepia'
|
||||
import MusicBrainz from '../src/api'
|
||||
import MusicBrainz, { MusicBrainzError } from '../src/api'
|
||||
|
||||
sepia.fixtureDir(path.join(__dirname, 'fixtures'))
|
||||
|
||||
test.beforeEach(t => {
|
||||
t.context.client = new MusicBrainz()
|
||||
let client
|
||||
|
||||
test.before(t => {
|
||||
client = new MusicBrainz()
|
||||
})
|
||||
|
||||
test('getLookupURL() generates a lookup URL', t => {
|
||||
const { client } = t.context
|
||||
t.is(client.getLookupURL('artist', 'c8da2e40-bd28-4d4e-813a-bd2f51958ba8', {
|
||||
inc: ['recordings', 'release-groups']
|
||||
}), 'artist/c8da2e40-bd28-4d4e-813a-bd2f51958ba8?inc=recordings%2Brelease-groups')
|
||||
})
|
||||
|
||||
test('getBrowseURL() generates a browse URL', t => {
|
||||
const { client } = t.context
|
||||
t.is(client.getBrowseURL('recording', {
|
||||
artist: 'c8da2e40-bd28-4d4e-813a-bd2f51958ba8',
|
||||
limit: null,
|
||||
|
|
@ -26,14 +26,20 @@ test('getBrowseURL() generates a browse URL', t => {
|
|||
})
|
||||
|
||||
test('getSearchURL() generates a search URL', t => {
|
||||
const { client } = t.context
|
||||
t.is(client.getSearchURL('artist', 'Lures', { inc: null }), 'artist?query=Lures')
|
||||
})
|
||||
|
||||
test('lookup() sends a lookup query', t => {
|
||||
const { client } = t.context
|
||||
return client.lookup('artist', 'c8da2e40-bd28-4d4e-813a-bd2f51958ba8').then(response => {
|
||||
t.is(response.id, 'c8da2e40-bd28-4d4e-813a-bd2f51958ba8')
|
||||
t.is(response.type, 'Group')
|
||||
})
|
||||
})
|
||||
|
||||
test('rejects the promise when the API returns an error', t => {
|
||||
t.throws(
|
||||
client.lookup('artist', '5b11f4ce-a62d-471e-81fc-a69a8278c7da', {
|
||||
inc: ['foobar']
|
||||
}), MusicBrainzError
|
||||
)
|
||||
})
|
||||
|
|
|
|||
1
test/fixtures/215ca91efacd4b7a1e7800813c8382e0
vendored
Normal file
1
test/fixtures/215ca91efacd4b7a1e7800813c8382e0
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"error":"foobar is not a valid inc parameter for the artist resource."}
|
||||
27
test/fixtures/215ca91efacd4b7a1e7800813c8382e0.headers
vendored
Normal file
27
test/fixtures/215ca91efacd4b7a1e7800813c8382e0.headers
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"statusCode": 400,
|
||||
"headers": {
|
||||
"date": "Fri, 09 Dec 2016 00:06:41 GMT",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"content-length": "72",
|
||||
"connection": "keep-alive",
|
||||
"keep-alive": "timeout=15",
|
||||
"x-ratelimit-limit": "700",
|
||||
"x-ratelimit-remaining": "575",
|
||||
"x-ratelimit-reset": "1481242002",
|
||||
"server": "Plack::Handler::Starlet",
|
||||
"etag": "\"d54d2bc5c412c1bb3c02bfc91d13a900\"",
|
||||
"access-control-allow-origin": "*"
|
||||
},
|
||||
"url": "http://musicbrainz.org:80/ws/2/artist/5b11f4ce-a62d-471e-81fc-a69a8278c7da?inc=foobar&fmt=json",
|
||||
"time": 613,
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"headers": {
|
||||
"User-Agent": "graphbrainz/3.1.1 ( https://github.com/exogen/graphbrainz )",
|
||||
"host": "musicbrainz.org",
|
||||
"accept-encoding": "gzip, deflate",
|
||||
"accept": "application/json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,9 +8,15 @@ import createLoaders from '../src/loaders'
|
|||
|
||||
sepia.fixtureDir(path.join(__dirname, 'fixtures'))
|
||||
|
||||
const client = new MusicBrainz()
|
||||
const loaders = createLoaders(client)
|
||||
const context = { client, loaders }
|
||||
let client
|
||||
let loaders
|
||||
let context
|
||||
|
||||
test.before(t => {
|
||||
client = new MusicBrainz()
|
||||
loaders = createLoaders(client)
|
||||
context = { client, loaders }
|
||||
})
|
||||
|
||||
test('schema has a node field', t => {
|
||||
const query = `
|
||||
|
|
|
|||
Loading…
Reference in a new issue