diff --git a/client/src/api.ts b/client/src/api.ts index 80a065b..89c75c5 100644 --- a/client/src/api.ts +++ b/client/src/api.ts @@ -18,17 +18,15 @@ export function checkQuerySongsRequest(req:any): boolean { } // Get song details. -export const SongDetailsEndpoint = '/song/details'; -export interface SongDetailsRequest { - id: Number -} +export const SongDetailsEndpoint = '/song/details/:id'; +export interface SongDetailsRequest {} export interface SongDetailsResponse { title: String, artistIds: Number[], albumIds: Number[], } export function checkSongDetailsRequest(req:any): boolean { - return "id" in req; + return true; } // Query for artists. @@ -42,15 +40,13 @@ export function checkQueryArtistsRequest(req:any): boolean { } // Get artist details. -export const ArtistDetailsEndpoint = '/artist/details'; -export interface ArtistDetailsRequest { - id: Number -} +export const ArtistDetailsEndpoint = '/artist/details/:id'; +export interface ArtistDetailsRequest {} export interface ArtistDetailsResponse { name: String } export function checkArtistDetailsRequest(req:any): boolean { - return "id" in req; + return true; } // Create a new song. diff --git a/server/app.ts b/server/app.ts index 82d4864..a2755e8 100644 --- a/server/app.ts +++ b/server/app.ts @@ -4,8 +4,10 @@ import * as api from '../client/src/api'; import { CreateSongEndpointHandler } from './endpoints/CreateSongEndpointHandler'; import { CreateArtistEndpointHandler } from './endpoints/CreateArtistEndpointHandler'; -import { ListSongsEndpointHandler } from './endpoints/ListSongsEndpointHandler'; -import { ListArtistsEndpointHandler } from './endpoints/ListArtistsEndpointHandler'; +import { QuerySongsEndpointHandler } from './endpoints/QuerySongsEndpointHandler'; +import { QueryArtistsEndpointHandler } from './endpoints/QueryArtistsEndpointHandler'; +import { ArtistDetailsEndpointHandler } from './endpoints/ArtistDetailsEndpointHandler' +import { SongDetailsEndpointHandler } from './endpoints/SongDetailsEndpointHandler'; import { ModifyArtistEndpointHandler } from './endpoints/ModifyArtistEndpointHandler'; import { ModifySongEndpointHandler } from './endpoints/ModifySongEndpointHandler'; import * as endpointTypes from './endpoints/types'; @@ -27,11 +29,13 @@ const SetupApp = (app: any) => { // Set up REST API endpoints app.post(api.CreateSongEndpoint, invokeHandler(CreateSongEndpointHandler)); - app.get(api.ListSongsEndpoint, invokeHandler(ListSongsEndpointHandler)); + app.get(api.QuerySongsEndpoint, invokeHandler(QuerySongsEndpointHandler)); app.post(api.CreateArtistEndpoint, invokeHandler(CreateArtistEndpointHandler)); - app.get(api.ListArtistsEndpoint, invokeHandler(ListArtistsEndpointHandler)); + app.get(api.QueryArtistsEndpoint, invokeHandler(QueryArtistsEndpointHandler)); app.post(api.ModifyArtistEndpoint, invokeHandler(ModifyArtistEndpointHandler)); app.post(api.ModifySongEndpoint, invokeHandler(ModifySongEndpointHandler)); + app.get(api.SongDetailsEndpoint, invokeHandler(SongDetailsEndpointHandler)); + app.get(api.ArtistDetailsEndpoint, invokeHandler(ArtistDetailsEndpointHandler)); } export { SetupApp } \ No newline at end of file diff --git a/server/endpoints/ArtistDetailsEndpointHandler.ts b/server/endpoints/ArtistDetailsEndpointHandler.ts index 5c8bb39..81214de 100644 --- a/server/endpoints/ArtistDetailsEndpointHandler.ts +++ b/server/endpoints/ArtistDetailsEndpointHandler.ts @@ -10,17 +10,16 @@ export const ArtistDetailsEndpointHandler: EndpointHandler = async (req: any, re }; throw e; } - const reqObject: api.ArtistDetailsRequest = req.body; await models.Artist.findAll({ where: { - id: reqObject.id + id: req.params.id } }) .then((artists: any[]) => { if (artists.length != 1) { const e: EndpointError = { - internalMessage: 'There is no artist with id ' + reqObject.id + '.', + internalMessage: 'There is no artist with id ' + req.params.id + '.', httpStatus: 400 }; throw e; diff --git a/server/endpoints/SongDetailsEndpointHandler copy.ts b/server/endpoints/SongDetailsEndpointHandler.ts similarity index 91% rename from server/endpoints/SongDetailsEndpointHandler copy.ts rename to server/endpoints/SongDetailsEndpointHandler.ts index f7c33a1..5ada517 100644 --- a/server/endpoints/SongDetailsEndpointHandler copy.ts +++ b/server/endpoints/SongDetailsEndpointHandler.ts @@ -10,18 +10,17 @@ export const SongDetailsEndpointHandler: EndpointHandler = async (req: any, res: }; throw e; } - const reqObject: api.SongDetailsRequest = req.body; await models.Song.findAll({ include: [models.Artist, models.Album], where: { - id: reqObject.id + id: req.params.id } }) .then((songs: any[]) => { if (songs.length != 1) { const e: EndpointError = { - internalMessage: 'There is no song with id ' + reqObject.id + '.', + internalMessage: 'There is no song with id ' + req.params.id + '.', httpStatus: 400 }; throw e; diff --git a/server/test/integration/flows/ModifyArtistFlow.js b/server/test/integration/flows/ModifyArtistFlow.js index 1a472fe..bb83c5f 100644 --- a/server/test/integration/flows/ModifyArtistFlow.js +++ b/server/test/integration/flows/ModifyArtistFlow.js @@ -34,8 +34,8 @@ describe('POST /artist/modify on nonexistent artist', () => { describe('POST /artist/modify with an existing artist', () => { it('should succeed', done => { init().then((app) => { - async function createArtist() { - await chai.request(app) + async function createArtist(req) { + await req .post('/artist/create') .send({ name: "MyArtist" @@ -48,8 +48,8 @@ describe('POST /artist/modify with an existing artist', () => { }); } - async function modifyArtist() { - chai.request(app) + async function modifyArtist(req) { + await req .post('/artist/modify') .send({ name: "MyNewArtist", @@ -60,11 +60,24 @@ describe('POST /artist/modify with an existing artist', () => { }); } - // TODO: Check artist + async function checkArtist(req) { + await req + .get('/artist/details/1') + .then((res) => { + expect(res).to.have.status(200); + expect(res.body).to.deep.equal({ + name: "MyNewArtist" + }); + }) + } + + var req = chai.request(app).keepOpen(); init() - .then(createArtist) - .then(modifyArtist) + .then(() => createArtist(req)) + .then(() => modifyArtist(req)) + .then(() => checkArtist(req)) + .then(() => req.close()) .then(done); }); });