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.
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.

@ -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 }

@ -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;

@ -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;

@ -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);
});
});

Loading…
Cancel
Save