Get modification and such working.

pull/7/head
Sander Vocke 5 years ago
parent 63ac5b5d84
commit e07a76acc1
  1. 16
      client/src/api.ts
  2. 12
      server/app.ts
  3. 5
      server/endpoints/ArtistDetailsEndpointHandler.ts
  4. 5
      server/endpoints/SongDetailsEndpointHandler.ts
  5. 27
      server/test/integration/flows/ModifyArtistFlow.js

@ -18,17 +18,15 @@ export function checkQuerySongsRequest(req:any): boolean {
} }
// Get song details. // Get song details.
export const SongDetailsEndpoint = '/song/details'; export const SongDetailsEndpoint = '/song/details/:id';
export interface SongDetailsRequest { export interface SongDetailsRequest {}
id: Number
}
export interface SongDetailsResponse { export interface SongDetailsResponse {
title: String, title: String,
artistIds: Number[], artistIds: Number[],
albumIds: Number[], albumIds: Number[],
} }
export function checkSongDetailsRequest(req:any): boolean { export function checkSongDetailsRequest(req:any): boolean {
return "id" in req; return true;
} }
// Query for artists. // Query for artists.
@ -42,15 +40,13 @@ export function checkQueryArtistsRequest(req:any): boolean {
} }
// Get artist details. // Get artist details.
export const ArtistDetailsEndpoint = '/artist/details'; export const ArtistDetailsEndpoint = '/artist/details/:id';
export interface ArtistDetailsRequest { export interface ArtistDetailsRequest {}
id: Number
}
export interface ArtistDetailsResponse { export interface ArtistDetailsResponse {
name: String name: String
} }
export function checkArtistDetailsRequest(req:any): boolean { export function checkArtistDetailsRequest(req:any): boolean {
return "id" in req; return true;
} }
// Create a new song. // Create a new song.

@ -4,8 +4,10 @@ import * as api from '../client/src/api';
import { CreateSongEndpointHandler } from './endpoints/CreateSongEndpointHandler'; import { CreateSongEndpointHandler } from './endpoints/CreateSongEndpointHandler';
import { CreateArtistEndpointHandler } from './endpoints/CreateArtistEndpointHandler'; import { CreateArtistEndpointHandler } from './endpoints/CreateArtistEndpointHandler';
import { ListSongsEndpointHandler } from './endpoints/ListSongsEndpointHandler'; import { QuerySongsEndpointHandler } from './endpoints/QuerySongsEndpointHandler';
import { ListArtistsEndpointHandler } from './endpoints/ListArtistsEndpointHandler'; import { QueryArtistsEndpointHandler } from './endpoints/QueryArtistsEndpointHandler';
import { ArtistDetailsEndpointHandler } from './endpoints/ArtistDetailsEndpointHandler'
import { SongDetailsEndpointHandler } from './endpoints/SongDetailsEndpointHandler';
import { ModifyArtistEndpointHandler } from './endpoints/ModifyArtistEndpointHandler'; import { ModifyArtistEndpointHandler } from './endpoints/ModifyArtistEndpointHandler';
import { ModifySongEndpointHandler } from './endpoints/ModifySongEndpointHandler'; import { ModifySongEndpointHandler } from './endpoints/ModifySongEndpointHandler';
import * as endpointTypes from './endpoints/types'; import * as endpointTypes from './endpoints/types';
@ -27,11 +29,13 @@ const SetupApp = (app: any) => {
// Set up REST API endpoints // Set up REST API endpoints
app.post(api.CreateSongEndpoint, invokeHandler(CreateSongEndpointHandler)); 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.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.ModifyArtistEndpoint, invokeHandler(ModifyArtistEndpointHandler));
app.post(api.ModifySongEndpoint, invokeHandler(ModifySongEndpointHandler)); app.post(api.ModifySongEndpoint, invokeHandler(ModifySongEndpointHandler));
app.get(api.SongDetailsEndpoint, invokeHandler(SongDetailsEndpointHandler));
app.get(api.ArtistDetailsEndpoint, invokeHandler(ArtistDetailsEndpointHandler));
} }
export { SetupApp } export { SetupApp }

@ -10,17 +10,16 @@ export const ArtistDetailsEndpointHandler: EndpointHandler = async (req: any, re
}; };
throw e; throw e;
} }
const reqObject: api.ArtistDetailsRequest = req.body;
await models.Artist.findAll({ await models.Artist.findAll({
where: { where: {
id: reqObject.id id: req.params.id
} }
}) })
.then((artists: any[]) => { .then((artists: any[]) => {
if (artists.length != 1) { if (artists.length != 1) {
const e: EndpointError = { const e: EndpointError = {
internalMessage: 'There is no artist with id ' + reqObject.id + '.', internalMessage: 'There is no artist with id ' + req.params.id + '.',
httpStatus: 400 httpStatus: 400
}; };
throw e; throw e;

@ -10,18 +10,17 @@ export const SongDetailsEndpointHandler: EndpointHandler = async (req: any, res:
}; };
throw e; throw e;
} }
const reqObject: api.SongDetailsRequest = req.body;
await models.Song.findAll({ await models.Song.findAll({
include: [models.Artist, models.Album], include: [models.Artist, models.Album],
where: { where: {
id: reqObject.id id: req.params.id
} }
}) })
.then((songs: any[]) => { .then((songs: any[]) => {
if (songs.length != 1) { if (songs.length != 1) {
const e: EndpointError = { const e: EndpointError = {
internalMessage: 'There is no song with id ' + reqObject.id + '.', internalMessage: 'There is no song with id ' + req.params.id + '.',
httpStatus: 400 httpStatus: 400
}; };
throw e; throw e;

@ -34,8 +34,8 @@ describe('POST /artist/modify on nonexistent artist', () => {
describe('POST /artist/modify with an existing artist', () => { describe('POST /artist/modify with an existing artist', () => {
it('should succeed', done => { it('should succeed', done => {
init().then((app) => { init().then((app) => {
async function createArtist() { async function createArtist(req) {
await chai.request(app) await req
.post('/artist/create') .post('/artist/create')
.send({ .send({
name: "MyArtist" name: "MyArtist"
@ -48,8 +48,8 @@ describe('POST /artist/modify with an existing artist', () => {
}); });
} }
async function modifyArtist() { async function modifyArtist(req) {
chai.request(app) await req
.post('/artist/modify') .post('/artist/modify')
.send({ .send({
name: "MyNewArtist", 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() init()
.then(createArtist) .then(() => createArtist(req))
.then(modifyArtist) .then(() => modifyArtist(req))
.then(() => checkArtist(req))
.then(() => req.close())
.then(done); .then(done);
}); });
}); });

Loading…
Cancel
Save