-
Notifications
You must be signed in to change notification settings - Fork 927
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3057b45
commit 0253c0e
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
const find = require('../../builders/v3/find'); | ||
const sort = require('../../builders/v3/sort'); | ||
const project = require('../../builders/v3/project'); | ||
const limit = require('../../builders/v3/limit'); | ||
|
||
module.exports = { | ||
|
||
/** | ||
* Return all landing pads | ||
*/ | ||
all: async ctx => { | ||
const data = await global.db | ||
.collection('landpad') | ||
.find(find(ctx.request)) | ||
.project(project(ctx.request.query)) | ||
.sort(sort(ctx.request)) | ||
.limit(limit(ctx.request.query)) | ||
.toArray(); | ||
ctx.body = data; | ||
}, | ||
|
||
/** | ||
* Return one landing pad by pad id | ||
*/ | ||
one: async ctx => { | ||
const data = await global.db | ||
.collection('landpad') | ||
.find({ id: ctx.params.id }) | ||
.project(project(ctx.request.query)) | ||
.toArray(); | ||
if (data.length === 0) { | ||
ctx.throw(404); | ||
} | ||
ctx.body = data[0]; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Landing Pad Endpoints | ||
|
||
const Router = require('koa-router'); | ||
const landpads = require('../../controllers/v3/landpads'); | ||
|
||
const v3 = new Router({ | ||
prefix: '/v3/landpads', | ||
}); | ||
|
||
// Return all landpads | ||
v3.get('/', landpads.all); | ||
|
||
// Return one landpad | ||
v3.get('/:id', landpads.one); | ||
|
||
module.exports = v3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
const request = require('supertest'); | ||
const app = require('../../../src/app'); | ||
|
||
beforeAll(done => { | ||
app.on('ready', () => { | ||
done(); | ||
}); | ||
}); | ||
|
||
//------------------------------------------------------------ | ||
// Landpads | ||
//------------------------------------------------------------ | ||
|
||
test('It should return all landing pads', async () => { | ||
const response = await request(app.callback()).get('/v3/landpads'); | ||
expect(response.statusCode).toBe(200); | ||
response.body.forEach(item => { | ||
expect(item).toHaveProperty('id'); | ||
expect(item).toHaveProperty('full_name'); | ||
expect(item).toHaveProperty('status'); | ||
expect(item).toHaveProperty('landing_type'); | ||
expect(item).toHaveProperty('successful_landings'); | ||
expect(item).toHaveProperty('attempted_landings'); | ||
}); | ||
}); | ||
|
||
test('It should return LZ-4 info', async () => { | ||
const response = await request(app.callback()).get('/v3/landpads/LZ-4'); | ||
expect(response.statusCode).toBe(200); | ||
expect(response.body).toHaveProperty('id', 'LZ-4'); | ||
}); | ||
|
||
test('It should return no landpad info', async () => { | ||
const response = await request(app.callback()).get('/v3/landpads/LZ-25'); | ||
expect(response.statusCode).toBe(404); | ||
}); |