From 8a02bd0433b7101c5ea36e87a4edb63204d2adec Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Oct 2017 09:43:01 +0200 Subject: Add pod list endpoint with pagination, sort... --- server/tests/api/check-params/pods.ts | 32 ++++++++++++++++++++++++++++++-- server/tests/api/friends-basic.ts | 19 ++++++++++++++++++- server/tests/utils/pods.ts | 16 +++++++++++++++- 3 files changed, 63 insertions(+), 4 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/pods.ts b/server/tests/api/check-params/pods.ts index a897e4dcd..9f9c2e4f0 100644 --- a/server/tests/api/check-params/pods.ts +++ b/server/tests/api/check-params/pods.ts @@ -15,7 +15,6 @@ import { } from '../../utils' describe('Test pods API validators', function () { - const path = '/api/v1/pods/' let server: ServerInfo // --------------------------------------------------------------- @@ -30,6 +29,7 @@ describe('Test pods API validators', function () { }) describe('When managing friends', function () { + const path = '/api/v1/pods/' let userAccessToken = null before(async function () { @@ -110,6 +110,32 @@ describe('Test pods API validators', function () { }) }) + describe('When listing friends', function () { + it('Should fail with a bad start pagination', async function () { + await request(server.url) + .get(path) + .query({ start: 'hello' }) + .set('Accept', 'application/json') + .expect(400) + }) + + it('Should fail with a bad count pagination', async function () { + await request(server.url) + .get(path) + .query({ count: 'hello' }) + .set('Accept', 'application/json') + .expect(400) + }) + + it('Should fail with an incorrect sort', async function () { + await request(server.url) + .get(path) + .query({ sort: 'hello' }) + .set('Accept', 'application/json') + .expect(400) + }) + }) + describe('When quitting friends', function () { it('Should fail with an invalid token', async function () { await request(server.url) @@ -175,7 +201,9 @@ describe('Test pods API validators', function () { }) }) - describe('When adding a pod', function () { + describe('When adding a pod from remote', function () { + const path = '/api/v1/remote/pods/add' + it('Should fail with nothing', async function () { const fields = {} await makePostBodyRequest({ url: server.url, path, fields }) diff --git a/server/tests/api/friends-basic.ts b/server/tests/api/friends-basic.ts index 13edf6273..efca4fda2 100644 --- a/server/tests/api/friends-basic.ts +++ b/server/tests/api/friends-basic.ts @@ -15,7 +15,8 @@ import { makeFriends, getFriendsList, dateIsValid, - quitOneFriend + quitOneFriend, + getPodsListPaginationAndSort } from '../utils' describe('Test basic friends', function () { @@ -120,6 +121,22 @@ describe('Test basic friends', function () { await makeFriends(server.url, server.accessToken, 409) }) + it('Should list friends correctly', async function () { + const start = 1 + const count = 1 + const sort = '-host' + + const res = await getPodsListPaginationAndSort(servers[0].url, start, count, sort) + expect(res.body.total).to.equal(2) + expect(res.body.data).to.have.lengthOf(1) + + const pod = res.body.data[0] + expect(pod.host).to.equal('localhost:9002') + expect(pod.email).to.equal('admin2@example.com') + expect(pod.score).to.equal(20) + expect(dateIsValid(pod.createdAt)).to.be.true + }) + it('Should quit friends of pod 2', async function () { this.timeout(10000) diff --git a/server/tests/utils/pods.ts b/server/tests/utils/pods.ts index a86dd20d9..52e807e70 100644 --- a/server/tests/utils/pods.ts +++ b/server/tests/utils/pods.ts @@ -12,6 +12,19 @@ function getFriendsList (url: string) { .expect('Content-Type', /json/) } +function getPodsListPaginationAndSort (url: string, start: number, count: number, sort: string) { + const path = '/api/v1/pods/' + + return request(url) + .get(path) + .query({ start }) + .query({ count }) + .query({ sort }) + .set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) +} + async function makeFriends (url: string, accessToken: string, expectedStatus = 204) { // Which pod makes friends with which pod const friendsMatrix = { @@ -85,5 +98,6 @@ export { getFriendsList, makeFriends, quitFriends, - quitOneFriend + quitOneFriend, + getPodsListPaginationAndSort } -- cgit v1.2.3