Skip to content

Commit

Permalink
Add new fairings data to sort and launch query builders
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewmeyer committed Aug 30, 2018
1 parent ac6e83b commit 739ad06
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/builders/query/launch-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ module.exports = q => {
query['rocket.second_stage.block'] = parseInt(q.second_stage_block, 10);
}

if (q.fairings_reused) {
query['rocket.fairings.reused'] = (q.fairings_reused === 'true');
}

if (q.fairings_recovery_attempt) {
query['rocket.fairings.recovery_attempt'] = (q.fairings_recovery_attempt === 'true');
}

if (q.fairings_recovered) {
query['rocket.fairings.recovered'] = (q.fairings_recovered === 'true');
}

if (q.fairings_ship) {
query['rocket.fairings.ship'] = q.fairings_ship;
}

if (q.core_reuse) {
query['reuse.core'] = (q.core_reuse === 'true');
}
Expand Down
12 changes: 12 additions & 0 deletions src/builders/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ module.exports = r => {
if (r.query.sort === 'orbit') {
query['rocket.second_stage.payloads.orbit'] = direction;
}
if (r.query.sort === 'fairings_reused') {
query['rocket.fairings.reused'] = direction;
}
if (r.query.sort === 'fairings_recovery_attempt') {
query['rocket.fairings.recovery_attempt'] = direction;
}
if (r.query.sort === 'fairings_recovered') {
query['rocket.fairings.recovered'] = direction;
}
if (r.query.sort === 'fairings_ship') {
query['rocket.fairings.ship'] = direction;
}
if (r.query.sort === 'launch_success') {
query.launch_success = direction;
}
Expand Down
32 changes: 32 additions & 0 deletions test/builders/launch-query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,38 @@ test('It should return launches with GTO orbit', async () => {
});
});

test('It should return launches with no reused fairings', async () => {
const response = await request(app.callback()).get('/v2/launches?fairings_recovered=false');
expect(response.statusCode).toBe(200);
response.body.forEach(item => {
expect(item.rocket.fairings.reused).toEqual(false);
});
});

test('It should return launches with fairing recovery attempts', async () => {
const response = await request(app.callback()).get('/v2/launches?fairings_recovery_attempt=true');
expect(response.statusCode).toBe(200);
response.body.forEach(item => {
expect(item.rocket.fairings.recovery_attempt).toEqual(true);
});
});

test('It should return launches with no recovered fairings', async () => {
const response = await request(app.callback()).get('/v2/launches?fairings_recovered=false');
expect(response.statusCode).toBe(200);
response.body.forEach(item => {
expect(item.rocket.fairings.recovered).toEqual(false);
});
});

test('It should return launches with MR STEVEN fairing ship', async () => {
const response = await request(app.callback()).get('/v2/launches?fairings_ship=MR%20STEVEN');
expect(response.statusCode).toBe(200);
response.body.forEach(item => {
expect(item.rocket.fairings.ship).toEqual('MR STEVEN');
});
});

test('It should return launches with successful launches', async () => {
const response = await request(app.callback()).get('/v2/launches?launch_success=true');
expect(response.statusCode).toBe(200);
Expand Down
24 changes: 24 additions & 0 deletions test/builders/sort.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,30 @@ test('It should return launches sorted by second stage block number', async () =
expect(response.body[response.body.length - 1].rocket.second_stage).toHaveProperty('block', 4);
});

test('It should return launches sorted by fairing reuse', async () => {
const response = await request(app.callback()).get('/v2/launches?sort=fairings_reused');
expect(response.statusCode).toBe(200);
expect(response.body[response.body.length - 1].rocket.fairings.reused).toEqual(false);
});

test('It should return launches sorted by fairing recovery attempts', async () => {
const response = await request(app.callback()).get('/v2/launches?sort=fairings_recovery_attempt');
expect(response.statusCode).toBe(200);
expect(response.body[response.body.length - 1].rocket.fairings.recovery_attempt).toEqual(true);
});

test('It should return launches sorted by fairing recoveries', async () => {
const response = await request(app.callback()).get('/v2/launches?sort=fairings_recovery');
expect(response.statusCode).toBe(200);
expect(response.body[response.body.length - 1].rocket.fairings.recovered).toEqual(false);
});

test('It should return launches sorted by fairing recovery ship', async () => {
const response = await request(app.callback()).get('/v2/launches?sort=fairings_ship');
expect(response.statusCode).toBe(200);
expect(response.body[response.body.length - 1].rocket.fairings.ship).toEqual('MR STEVEN');
});

test('It should return launches sorted by core reuse', async () => {
const response = await request(app.callback()).get('/v2/launches?sort=core_reuse&launch_year=2017');
expect(response.statusCode).toBe(200);
Expand Down

0 comments on commit 739ad06

Please sign in to comment.