From 5b1a2064ce643ac80035a1efdc763fd25378532b Mon Sep 17 00:00:00 2001 From: Sander Vocke Date: Fri, 14 Aug 2020 11:45:24 +0200 Subject: [PATCH] Fix tests. --- .drone.yml | 2 +- client/src/api.ts | 1 + client/src/components/QueryBrowseWindow.tsx | 18 +-- server/endpoints/QueryEndpointHandler.ts | 3 + server/test/integration/flows/QueryFlow.js | 124 ++++++++++++++++++-- 5 files changed, 128 insertions(+), 20 deletions(-) diff --git a/.drone.yml b/.drone.yml index bba996c..b91b134 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,7 +13,7 @@ steps: - name: front-end build image: node commands: - - cd client && npm build; cd .. + - cd client && npm run-script build; cd .. - name: back-end test image: node diff --git a/client/src/api.ts b/client/src/api.ts index 7902ed1..41cf5a1 100644 --- a/client/src/api.ts +++ b/client/src/api.ts @@ -70,6 +70,7 @@ export enum QueryElemProperty { songTitle = "songTitle", songId = "songId", artistName = "artistName", + artistId = "artistId", albumName = "albumName", } export enum OrderByType { diff --git a/client/src/components/QueryBrowseWindow.tsx b/client/src/components/QueryBrowseWindow.tsx index cb7d732..0415403 100644 --- a/client/src/components/QueryBrowseWindow.tsx +++ b/client/src/components/QueryBrowseWindow.tsx @@ -96,8 +96,8 @@ function OrderingWidget(props: OrderingWidgetProps) { ; } -function toServerOrdering(o: QueryOrdering | undefined) : serverApi.Ordering { - if(!o) { +function toServerOrdering(o: QueryOrdering | undefined): serverApi.Ordering { + if (!o) { return { orderBy: { type: serverApi.OrderByType.Name @@ -144,12 +144,14 @@ export default function QueryBrowseWindow(props: IProps) { const request: serverApi.QueryRequest = { query: toApiQuery(props.query), - songOffset: 0, - songLimit: 5, // TODO - artistOffset: 0, - artistLimit: 5, - tagOffset: 0, - tagLimit: 5, + offsetsLimits: { + songOffset: 0, + songLimit: 5, // TODO + artistOffset: 0, + artistLimit: 5, + tagOffset: 0, + tagLimit: 5, + }, ordering: toServerOrdering(props.resultOrder), } const requestOpts = { diff --git a/server/endpoints/QueryEndpointHandler.ts b/server/endpoints/QueryEndpointHandler.ts index ac3872d..041e088 100644 --- a/server/endpoints/QueryEndpointHandler.ts +++ b/server/endpoints/QueryEndpointHandler.ts @@ -24,18 +24,21 @@ const sequelizeProps: any = { [api.QueryElemProperty.songTitle]: "title", [api.QueryElemProperty.songId]: "id", [api.QueryElemProperty.artistName]: "$Artists.name$", + [api.QueryElemProperty.artistId]: "$Artists.id$", [api.QueryElemProperty.albumName]: "$Albums.name$", }, [QueryType.Artist]: { [api.QueryElemProperty.songTitle]: "$Songs.title$", [api.QueryElemProperty.songId]: "$Songs.id$", [api.QueryElemProperty.artistName]: "name", + [api.QueryElemProperty.artistId]: "id", [api.QueryElemProperty.albumName]: "$Albums.name$", }, [QueryType.Tag]: { [api.QueryElemProperty.songTitle]: "$Songs.title$", [api.QueryElemProperty.songId]: "$Songs.id$", [api.QueryElemProperty.artistName]: "$Artists.name$", + [api.QueryElemProperty.artistId]: "$Artists.id$", [api.QueryElemProperty.albumName]: "$Albums.name$", } }; diff --git a/server/test/integration/flows/QueryFlow.js b/server/test/integration/flows/QueryFlow.js index b20f13b..741a884 100644 --- a/server/test/integration/flows/QueryFlow.js +++ b/server/test/integration/flows/QueryFlow.js @@ -49,14 +49,68 @@ describe('POST /query with no songs', () => { describe('POST /query with several songs and filters', () => { it('should give all correct results', done => { init().then((app) => { + const song1 = { + songId: 1, + title: 'Song1', + storeLinks: [], + artists: [ + { + artistId: 1, + name: 'Artist1' + } + ], + tags: [], + rankings: [] + }; + const song2 = { + songId: 2, + title: 'Song2', + storeLinks: [], + artists: [ + { + artistId: 1, + name: 'Artist1' + } + ], + tags: [], + rankings: [] + }; + const song3 = { + songId: 3, + title: 'Song3', + storeLinks: [], + artists: [ + { + artistId: 2, + name: 'Artist2' + } + ], + tags: [], + rankings: [] + }; + async function checkAllSongs(req) { await req .post('/query') - .send({ "query": {} }) + .send({ + "query": {}, + 'offsetsLimits': { + 'songOffset': 0, + 'songLimit': 10, + }, + 'ordering': { + 'orderBy': { + 'type': 0, + }, + 'ascending': true + } + }) .then((res) => { expect(res).to.have.status(200); expect(res.body).to.deep.equal({ - ids: [1, 2, 3] + songs: [ song1, song2, song3 ], + artists: [], + tags: [] }); }); } @@ -66,15 +120,27 @@ describe('POST /query with several songs and filters', () => { .post('/query') .send({ "query": { - "prop": "id", + "prop": "songId", "propOperator": "IN", "propOperand": [1, 3, 5] + }, + 'offsetsLimits': { + 'songOffset': 0, + 'songLimit': 10, + }, + 'ordering': { + 'orderBy': { + 'type': 0, + }, + 'ascending': true } }) .then((res) => { expect(res).to.have.status(200); expect(res.body).to.deep.equal({ - ids: [1, 3] + songs: [ song1, song3 ], + artists: [], + tags: [] }); }); } @@ -84,15 +150,27 @@ describe('POST /query with several songs and filters', () => { .post('/query') .send({ "query": { - "prop": "id", + "prop": "songId", "propOperator": "NOTIN", "propOperand": [1, 3, 5] + }, + 'offsetsLimits': { + 'songOffset': 0, + 'songLimit': 10, + }, + 'ordering': { + 'orderBy': { + 'type': 0, + }, + 'ascending': true } }) .then((res) => { expect(res).to.have.status(200); expect(res.body).to.deep.equal({ - ids: [2] + songs: [ song2 ], + artists: [], + tags: [] }); }); } @@ -102,15 +180,27 @@ describe('POST /query with several songs and filters', () => { .post('/query') .send({ "query": { - "prop": "artistIds", + "prop": "artistId", "propOperator": "IN", "propOperand": [1] + }, + 'offsetsLimits': { + 'songOffset': 0, + 'songLimit': 10, + }, + 'ordering': { + 'orderBy': { + 'type': 0, + }, + 'ascending': true } }) .then((res) => { expect(res).to.have.status(200); expect(res.body).to.deep.equal({ - ids: [1, 2] + songs: [ song1, song2 ], + artists: [], + tags: [] }); }); } @@ -123,22 +213,34 @@ describe('POST /query with several songs and filters', () => { "childrenOperator": "OR", "children": [ { - "prop": "artistIds", + "prop": "artistId", "propOperator": "IN", "propOperand": [2] }, { - "prop": "id", + "prop": "songId", "propOperator": "EQ", "propOperand": 1 } ] + }, + 'offsetsLimits': { + 'songOffset': 0, + 'songLimit': 10, + }, + 'ordering': { + 'orderBy': { + 'type': 0, + }, + 'ascending': true } }) .then((res) => { expect(res).to.have.status(200); expect(res.body).to.deep.equal({ - ids: [1, 3] + songs: [ song1, song3 ], + artists: [], + tags: [] }); }); }