pull/7/head
Sander Vocke 5 years ago
parent b7a83ba857
commit 5b1a2064ce
  1. 2
      .drone.yml
  2. 1
      client/src/api.ts
  3. 2
      client/src/components/QueryBrowseWindow.tsx
  4. 3
      server/endpoints/QueryEndpointHandler.ts
  5. 124
      server/test/integration/flows/QueryFlow.js

@ -13,7 +13,7 @@ steps:
- name: front-end build - name: front-end build
image: node image: node
commands: commands:
- cd client && npm build; cd .. - cd client && npm run-script build; cd ..
- name: back-end test - name: back-end test
image: node image: node

@ -70,6 +70,7 @@ export enum QueryElemProperty {
songTitle = "songTitle", songTitle = "songTitle",
songId = "songId", songId = "songId",
artistName = "artistName", artistName = "artistName",
artistId = "artistId",
albumName = "albumName", albumName = "albumName",
} }
export enum OrderByType { export enum OrderByType {

@ -144,12 +144,14 @@ export default function QueryBrowseWindow(props: IProps) {
const request: serverApi.QueryRequest = { const request: serverApi.QueryRequest = {
query: toApiQuery(props.query), query: toApiQuery(props.query),
offsetsLimits: {
songOffset: 0, songOffset: 0,
songLimit: 5, // TODO songLimit: 5, // TODO
artistOffset: 0, artistOffset: 0,
artistLimit: 5, artistLimit: 5,
tagOffset: 0, tagOffset: 0,
tagLimit: 5, tagLimit: 5,
},
ordering: toServerOrdering(props.resultOrder), ordering: toServerOrdering(props.resultOrder),
} }
const requestOpts = { const requestOpts = {

@ -24,18 +24,21 @@ const sequelizeProps: any = {
[api.QueryElemProperty.songTitle]: "title", [api.QueryElemProperty.songTitle]: "title",
[api.QueryElemProperty.songId]: "id", [api.QueryElemProperty.songId]: "id",
[api.QueryElemProperty.artistName]: "$Artists.name$", [api.QueryElemProperty.artistName]: "$Artists.name$",
[api.QueryElemProperty.artistId]: "$Artists.id$",
[api.QueryElemProperty.albumName]: "$Albums.name$", [api.QueryElemProperty.albumName]: "$Albums.name$",
}, },
[QueryType.Artist]: { [QueryType.Artist]: {
[api.QueryElemProperty.songTitle]: "$Songs.title$", [api.QueryElemProperty.songTitle]: "$Songs.title$",
[api.QueryElemProperty.songId]: "$Songs.id$", [api.QueryElemProperty.songId]: "$Songs.id$",
[api.QueryElemProperty.artistName]: "name", [api.QueryElemProperty.artistName]: "name",
[api.QueryElemProperty.artistId]: "id",
[api.QueryElemProperty.albumName]: "$Albums.name$", [api.QueryElemProperty.albumName]: "$Albums.name$",
}, },
[QueryType.Tag]: { [QueryType.Tag]: {
[api.QueryElemProperty.songTitle]: "$Songs.title$", [api.QueryElemProperty.songTitle]: "$Songs.title$",
[api.QueryElemProperty.songId]: "$Songs.id$", [api.QueryElemProperty.songId]: "$Songs.id$",
[api.QueryElemProperty.artistName]: "$Artists.name$", [api.QueryElemProperty.artistName]: "$Artists.name$",
[api.QueryElemProperty.artistId]: "$Artists.id$",
[api.QueryElemProperty.albumName]: "$Albums.name$", [api.QueryElemProperty.albumName]: "$Albums.name$",
} }
}; };

@ -49,14 +49,68 @@ describe('POST /query with no songs', () => {
describe('POST /query with several songs and filters', () => { describe('POST /query with several songs and filters', () => {
it('should give all correct results', done => { it('should give all correct results', done => {
init().then((app) => { 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) { async function checkAllSongs(req) {
await req await req
.post('/query') .post('/query')
.send({ "query": {} }) .send({
"query": {},
'offsetsLimits': {
'songOffset': 0,
'songLimit': 10,
},
'ordering': {
'orderBy': {
'type': 0,
},
'ascending': true
}
})
.then((res) => { .then((res) => {
expect(res).to.have.status(200); expect(res).to.have.status(200);
expect(res.body).to.deep.equal({ 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') .post('/query')
.send({ .send({
"query": { "query": {
"prop": "id", "prop": "songId",
"propOperator": "IN", "propOperator": "IN",
"propOperand": [1, 3, 5] "propOperand": [1, 3, 5]
},
'offsetsLimits': {
'songOffset': 0,
'songLimit': 10,
},
'ordering': {
'orderBy': {
'type': 0,
},
'ascending': true
} }
}) })
.then((res) => { .then((res) => {
expect(res).to.have.status(200); expect(res).to.have.status(200);
expect(res.body).to.deep.equal({ 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') .post('/query')
.send({ .send({
"query": { "query": {
"prop": "id", "prop": "songId",
"propOperator": "NOTIN", "propOperator": "NOTIN",
"propOperand": [1, 3, 5] "propOperand": [1, 3, 5]
},
'offsetsLimits': {
'songOffset': 0,
'songLimit': 10,
},
'ordering': {
'orderBy': {
'type': 0,
},
'ascending': true
} }
}) })
.then((res) => { .then((res) => {
expect(res).to.have.status(200); expect(res).to.have.status(200);
expect(res.body).to.deep.equal({ 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') .post('/query')
.send({ .send({
"query": { "query": {
"prop": "artistIds", "prop": "artistId",
"propOperator": "IN", "propOperator": "IN",
"propOperand": [1] "propOperand": [1]
},
'offsetsLimits': {
'songOffset': 0,
'songLimit': 10,
},
'ordering': {
'orderBy': {
'type': 0,
},
'ascending': true
} }
}) })
.then((res) => { .then((res) => {
expect(res).to.have.status(200); expect(res).to.have.status(200);
expect(res.body).to.deep.equal({ 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", "childrenOperator": "OR",
"children": [ "children": [
{ {
"prop": "artistIds", "prop": "artistId",
"propOperator": "IN", "propOperator": "IN",
"propOperand": [2] "propOperand": [2]
}, },
{ {
"prop": "id", "prop": "songId",
"propOperator": "EQ", "propOperator": "EQ",
"propOperand": 1 "propOperand": 1
} }
] ]
},
'offsetsLimits': {
'songOffset': 0,
'songLimit': 10,
},
'ordering': {
'orderBy': {
'type': 0,
},
'ascending': true
} }
}) })
.then((res) => { .then((res) => {
expect(res).to.have.status(200); expect(res).to.have.status(200);
expect(res.body).to.deep.equal({ expect(res.body).to.deep.equal({
ids: [1, 3] songs: [ song1, song3 ],
artists: [],
tags: []
}); });
}); });
} }

Loading…
Cancel
Save