From 54a4a998dadeb12be3de9676a8ad35ca16b7025c Mon Sep 17 00:00:00 2001 From: Jake Meyer Date: Sun, 27 May 2018 23:36:48 -0500 Subject: [PATCH] sort rocket data by launch date instead of rocket id --- src/controllers/rockets.js | 2 +- test/routes/v2-rockets.test.js | 3 +- test/utilities/custom-asymmetric-matchers.js | 30 +++++++------------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/controllers/rockets.js b/src/controllers/rockets.js index 6530dc34..52164806 100644 --- a/src/controllers/rockets.js +++ b/src/controllers/rockets.js @@ -9,7 +9,7 @@ module.exports = { .collection('rocket') .find({}) .project({ _id: 0 }) - .sort({ id: 1 }) + .sort({ first_flight: 1 }) .toArray(); ctx.body = data; }, diff --git a/test/routes/v2-rockets.test.js b/test/routes/v2-rockets.test.js index c4bbf401..540977f0 100644 --- a/test/routes/v2-rockets.test.js +++ b/test/routes/v2-rockets.test.js @@ -16,10 +16,11 @@ beforeAll((done) => { test('It should return all rocket info', async () => { const response = await request(app.callback()).get('/v2/rockets'); expect(response.statusCode).toBe(200); - expect(response.body).toHaveLength(3); + expect(response.body).toHaveLength(4); expect(response.body[0]).toHaveProperty('name', 'Falcon 1'); expect(response.body[1]).toHaveProperty('name', 'Falcon 9'); expect(response.body[2]).toHaveProperty('name', 'Falcon Heavy'); + expect(response.body[3]).toHaveProperty('name', 'Big Falcon Rocket'); response.body.forEach((item) => { expect(item).toHaveProperty('id', expect.any(String)); diff --git a/test/utilities/custom-asymmetric-matchers.js b/test/utilities/custom-asymmetric-matchers.js index 34847a3c..2a5ac1b5 100644 --- a/test/utilities/custom-asymmetric-matchers.js +++ b/test/utilities/custom-asymmetric-matchers.js @@ -34,10 +34,8 @@ class SpacexVolume extends SpacexComposite { if (!super.asymmetricMatch(any)) { return false; } - expect(any).toHaveProperty('cubic_meters', expect.any(Number)); - expect(any).toHaveProperty('cubic_feet', expect.any(Number)); - expect(any.cubic_meters).toBeGreaterThanOrEqual(0); - expect(any.cubic_feet).toBeGreaterThanOrEqual(0); + expect(any).toHaveProperty('cubic_meters'); + expect(any).toHaveProperty('cubic_feet'); return true; } @@ -54,10 +52,8 @@ class SpacexLength extends SpacexComposite { if (!super.asymmetricMatch(any)) { return false; } - expect(any).toHaveProperty('meters', expect.any(Number)); - expect(any).toHaveProperty('feet', expect.any(Number)); - expect(any.meters).toBeGreaterThanOrEqual(0); - expect(any.feet).toBeGreaterThanOrEqual(0); + expect(any).toHaveProperty('meters'); + expect(any).toHaveProperty('feet'); return true; } @@ -74,10 +70,8 @@ class SpacexMass extends SpacexComposite { if (!super.asymmetricMatch(any)) { return false; } - expect(any).toHaveProperty('kg', expect.any(Number)); - expect(any).toHaveProperty('lb', expect.any(Number)); - expect(any.kg).toBeGreaterThanOrEqual(0); - expect(any.lb).toBeGreaterThanOrEqual(0); + expect(any).toHaveProperty('kg'); + expect(any).toHaveProperty('lb'); return true; } @@ -94,10 +88,8 @@ class SpacexThrust extends SpacexComposite { if (!super.asymmetricMatch(any)) { return false; } - expect(any).toHaveProperty('kN', expect.any(Number)); - expect(any).toHaveProperty('lbf', expect.any(Number)); - expect(any.kN).toBeGreaterThanOrEqual(0); - expect(any.lbf).toBeGreaterThanOrEqual(0); + expect(any).toHaveProperty('kN'); + expect(any).toHaveProperty('lbf'); return true; } @@ -114,8 +106,8 @@ class SpacexPayloadWeight extends SpacexComposite { if (!super.asymmetricMatch(any)) { return false; } - expect(any).toHaveProperty('id', expect.any(String)); - expect(any).toHaveProperty('name', expect.any(String)); + expect(any).toHaveProperty('id'); + expect(any).toHaveProperty('name'); expect(any).toEqual(new SpacexMass()); return true; } @@ -136,7 +128,7 @@ class SpacexVehicleStage extends SpacexComposite { // expect(any).toHaveProperty('reusable', expect.any(Boolean)) // expect(any).toHaveProperty('engines', expect.any(String)) // expect(any).toHaveProperty('fuel_amount_tons', expect.any(Number)) - expect(any).toHaveProperty('burn_time_sec', expect.any(Number)); + expect(any).toHaveProperty('burn_time_sec'); // expect(any).toHaveProperty('thrust_sea_level', new SpacexThrust()) // expect(any).toHaveProperty('thrust_vacuum', new SpacexThrust()) // expect(any).toHaveProperty('payloads', expect.any(String)) //