-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): Regression on Data Export API + side effects between API te…
…sts (#418) * local optim: run docker:seed just once * test: "data export api provides profile tracks of given user id" * Revert "local optim: run docker:seed just once" This reverts commit 93d9f65. * test: "provides profile tracks of given user id, as a list of links" * add same tests by username instead of user_id * new tests: "provides playlist tracks of given user id" * same, with username => error because "admin" user handle conflicts with admin routes * => use DUMMY_USER to prevent conflict between handle and admin routes => "User not found..." error * fix: don't let the presence of a playlistId preempt the retrieval of user by their handle * add links to API docs * fix: use DUMMY_USER instead of ADMIN_USER in post.api.tests.js * extract data.api.tests.js from user.api.tests.js * ❌ new test: "provides list of playlists" * fix: make the /playlists handler return the actual list of playlists * /playlists route now works in JSON format * fix tests * fix test expectation * normalize formatting conditions * make "bareFormats" ('json' / 'links') easier to find * clean up playlist processing logic
- Loading branch information
1 parent
dda5b1c
commit f4f1466
Showing
6 changed files
with
185 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* global describe, it, before */ | ||
|
||
const assert = require('assert'); | ||
const request = require('request'); | ||
|
||
const { URL_PREFIX, DUMMY_USER, cleanup } = require('../fixtures.js'); | ||
const api = require('../api-client.js'); | ||
|
||
const reqGet = (url) => | ||
new Promise((resolve, reject) => | ||
request.get({ url }, (err, response, body) => | ||
err ? reject(err) : resolve({ response, body }) | ||
) | ||
); | ||
|
||
const addTrackToPlaylist = (user, plName, post) => | ||
new Promise((resolve, reject) => { | ||
const postInPlaylist = { ...post, pl: { id: 'create', name: plName } }; | ||
api.loginAs(DUMMY_USER, (error, { jar }) => { | ||
api.addPost(jar, postInPlaylist, (error, res) => | ||
error ? reject(error) : resolve(res) | ||
); | ||
}); | ||
}); | ||
|
||
describe(`Data Export API`, () => { | ||
// API documentation: https://openwhyd.github.io/openwhyd/API.html#openwhyd-data-export-api | ||
|
||
before(cleanup); // to prevent side effects between tests | ||
|
||
// add a playlist with one track | ||
const user = DUMMY_USER; | ||
const plName = 'my first playlist'; | ||
const track = { | ||
name: 'my first track', | ||
eId: '/yt/59MdiE1IsBY', | ||
url: '//youtube.com/watch?v=59MdiE1IsBY', | ||
}; | ||
before(function () { | ||
this.timeout(4000); | ||
return addTrackToPlaylist(user, plName, track); | ||
}); | ||
|
||
describe(`provides profile tracks`, () => { | ||
it(`of given user id, as JSON`, async () => { | ||
const { body } = await reqGet(`${URL_PREFIX}/u/${user.id}?format=json`); | ||
const parsedBody = JSON.parse(body) || {}; | ||
assert.strictEqual(parsedBody.error, undefined); | ||
assert.strictEqual(parsedBody.length, 1); | ||
assert.strictEqual(parsedBody[0].name, track.name); | ||
}); | ||
|
||
it(`of given user id, as a list of links`, async () => { | ||
const { body } = await reqGet(`${URL_PREFIX}/u/${user.id}?format=links`); | ||
assert.strictEqual(body, track.url); | ||
}); | ||
|
||
it(`of given user handle, as JSON`, async () => { | ||
const { body } = await reqGet(`${URL_PREFIX}/${user.handle}?format=json`); | ||
const parsedBody = JSON.parse(body) || {}; | ||
assert.strictEqual(parsedBody.error, undefined); | ||
assert.strictEqual(parsedBody.length, 1); | ||
assert.strictEqual(parsedBody[0].name, track.name); | ||
}); | ||
|
||
it(`of given user handle, as a list of links`, async () => { | ||
const { body } = await reqGet( | ||
`${URL_PREFIX}/${user.handle}?format=links` | ||
); | ||
assert.strictEqual(body, track.url); | ||
}); | ||
}); | ||
|
||
describe(`provides list of playlists`, () => { | ||
it(`of given user id, as JSON`, async () => { | ||
const plUrl = `${URL_PREFIX}/u/${user.id}/playlists`; | ||
const { body } = await reqGet(`${plUrl}?format=json`); | ||
const parsedBody = JSON.parse(body) || {}; | ||
assert.strictEqual(parsedBody.error, undefined); | ||
assert.strictEqual(parsedBody.length, 1); | ||
assert.strictEqual(parsedBody[0].name, plName); | ||
}); | ||
|
||
it(`of given user id, as list`, async () => { | ||
const expectedRes = `<a href="/u/${user.id}/playlist/0">${plName}</a>`; | ||
const plUrl = `${URL_PREFIX}/u/${user.id}/playlists`; | ||
const { body } = await reqGet(`${plUrl}?format=list`); | ||
assert.notStrictEqual(body.indexOf(expectedRes), -1); | ||
}); | ||
|
||
it(`of given user handle, as JSON`, async () => { | ||
const plUrl = `${URL_PREFIX}/${user.handle}/playlists`; | ||
const { body } = await reqGet(`${plUrl}?format=json`); | ||
const parsedBody = JSON.parse(body) || {}; | ||
assert.strictEqual(parsedBody.error, undefined); | ||
assert.strictEqual(parsedBody.length, 1); | ||
assert.strictEqual(parsedBody[0].name, plName); | ||
}); | ||
|
||
it(`of given user handle, as list`, async () => { | ||
const expectedRes = `<a href="/u/${user.id}/playlist/0">${plName}</a>`; | ||
const plUrl = `${URL_PREFIX}/${user.handle}/playlists`; | ||
const { body } = await reqGet(`${plUrl}?format=list`); | ||
assert.notStrictEqual(body.indexOf(expectedRes), -1); | ||
}); | ||
}); | ||
|
||
describe(`provides playlist tracks`, () => { | ||
it(`of given user id, as JSON`, async () => { | ||
const plUrl = `${URL_PREFIX}/u/${user.id}/playlist/0`; | ||
const { body } = await reqGet(`${plUrl}?format=json`); | ||
const parsedBody = JSON.parse(body) || {}; | ||
assert.strictEqual(parsedBody.error, undefined); | ||
assert.strictEqual(parsedBody.length, 1); | ||
assert.strictEqual(parsedBody[0].name, track.name); | ||
}); | ||
|
||
it(`of given user id, as a list of links`, async () => { | ||
const plUrl = `${URL_PREFIX}/u/${user.id}/playlist/0`; | ||
const { body } = await reqGet(`${plUrl}?format=links`); | ||
assert.strictEqual(body, track.url); | ||
}); | ||
|
||
it(`of given user handle, as JSON`, async () => { | ||
const plUrl = `${URL_PREFIX}/${user.handle}/playlist/0`; | ||
const { body } = await reqGet(`${plUrl}?format=json`); | ||
const parsedBody = JSON.parse(body) || {}; | ||
assert.strictEqual(parsedBody.error, undefined); | ||
assert.strictEqual(parsedBody.length, 1); | ||
assert.strictEqual(parsedBody[0].name, track.name); | ||
}); | ||
|
||
it(`of given user handle, as a list of links`, async () => { | ||
const plUrl = `${URL_PREFIX}/u/${user.id}/playlist/0`; | ||
const { body } = await reqGet(`${plUrl}?format=links`); | ||
assert.strictEqual(body, track.url); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters