/* tslint:disable:no-unused-expression */ import chai from 'chai'; import chaiHttp from 'chai-http'; import app from '../../src/app'; import { authorize, clearUsers, createUser } from './helper'; chai.use(chaiHttp); const request = chai.request; chai.should(); describe('Playlist API', () => { describe('POST /v1/users/{user_id}/playlists', () => { let server: ChaiHttp.Agent; let userId: string; beforeEach(async () => { server = request(app).keepOpen(); const res = await createUser(server, { display_name: 'Test', email: 'test@example.com', password: 'passw0rd', }); userId = res.body.id; }); it('when supplied with user and new playlist details, returns that playlist', async () => { const res = await request(app) .post(`/v1/users/${userId}/playlists`) .type('form') .send({ name: 'Test Playlist', }); res.status .should.equal(201); res .should.be.json; res.body.name .should.equal('Test Playlist'); res.body.id .should.not.be.empty; }); afterEach(async () => { await clearUsers(server); server.close(); }); }); describe('GET /v1/me/playlists', () => { let server: ChaiHttp.Agent; let authorization: string; let userId: string; beforeEach(async () => { server = request.agent(app).keepOpen(); userId = (await createUser(server)).body.id; authorization = await authorize(server); }); it('returns http status 200', async () => { const res = await server .get('/v1/me/playlists') .set({Authorization: authorization}); res.status .should.equal(200); }); it('responds with the playlist details when a playlist has been created', async () => { await request(app) .post(`/v1/users/${userId}/playlists`) .type('form') .send({ name: 'Test Playlist', }); const res = await server .get('/v1/me/playlists') .set({Authorization: authorization}); res.status .should.equal(200); res .should.be.json; res.body.items .should.have.lengthOf(1); res.body.items[0].name .should.equal('Test Playlist'); }); afterEach(async () => { await clearUsers(server); server.close(); }); }); });