Skip to content

Commit 7f7c952

Browse files
committed
move v2 rockets test to unique file
1 parent 38f4f66 commit 7f7c952

File tree

2 files changed

+76
-66
lines changed

2 files changed

+76
-66
lines changed

test/v2-rockets.test.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
const request = require('supertest');
3+
const app = require('../src/app');
4+
const customMatchers = require('./utilities/custom-asymmetric-matchers');
5+
6+
beforeAll((done) => {
7+
app.on('ready', () => {
8+
done();
9+
});
10+
});
11+
12+
//------------------------------------------------------------
13+
// Rockets V2
14+
//------------------------------------------------------------
15+
16+
test('It should return all rocket info', () => {
17+
return request(app).get('/v2/rockets').then((response) => {
18+
expect(response.statusCode).toBe(200);
19+
expect(response.body).toHaveLength(3);
20+
expect(response.body[0]).toHaveProperty('name', 'Falcon 1');
21+
expect(response.body[1]).toHaveProperty('name', 'Falcon 9');
22+
expect(response.body[2]).toHaveProperty('name', 'Falcon Heavy');
23+
24+
response.body.forEach((item) => {
25+
expect(item).toHaveProperty('id', expect.any(String));
26+
expect(item).toHaveProperty('name', expect.any(String));
27+
expect(item).toHaveProperty('type', expect.stringMatching(/^(?:rocket|capsule)$/));
28+
expect(item).toHaveProperty('active', expect.any(Boolean));
29+
expect(item).toHaveProperty('stages', expect.any(Number));
30+
expect(item).toHaveProperty('boosters', expect.any(Number));
31+
expect(item).toHaveProperty('cost_per_launch', expect.any(Number));
32+
expect(item).toHaveProperty('success_rate_pct', expect.any(Number));
33+
expect(item).toHaveProperty('first_flight', expect.stringMatching(/^(?:[0-9]{4}-[0-9]{2}-[0-9]{2}|TBD)$/));
34+
expect(item).toHaveProperty('country', expect.any(String));
35+
expect(item).toHaveProperty('company', expect.any(String));
36+
expect(item).toHaveProperty('height', customMatchers.length());
37+
expect(item).toHaveProperty('diameter', customMatchers.length());
38+
expect(item).toHaveProperty('mass', customMatchers.mass());
39+
expect(item).toHaveProperty('payload_weights', expect.any(Array));
40+
item.payload_weights.forEach((weight) => {
41+
expect(weight).toEqual(customMatchers.payloadWeight());
42+
});
43+
expect(item).toHaveProperty('first_stage', customMatchers.vehicleStage());
44+
expect(item).toHaveProperty('second_stage', customMatchers.vehicleStage());
45+
expect(item).toHaveProperty('description', expect.any(String));
46+
});
47+
});
48+
});
49+
50+
test('It should return Falcon 1 info', () => {
51+
return request(app).get('/v2/rockets/falcon1').then((response) => {
52+
expect(response.statusCode).toBe(200);
53+
expect(response.body).toHaveProperty('name', 'Falcon 1');
54+
expect(response.body).toHaveProperty('stages', 2);
55+
expect(response.body).toHaveProperty('cost_per_launch');
56+
expect(response.body).toHaveProperty('success_rate_pct');
57+
expect(response.body).toHaveProperty('first_flight', '2006-03-24');
58+
expect(response.body).toHaveProperty('country');
59+
expect(response.body).toHaveProperty('company', 'SpaceX');
60+
expect(response.body).toHaveProperty('description');
61+
});
62+
});
63+
64+
test('It should return Falcon Heavy info', () => {
65+
return request(app).get('/v2/rockets/falconheavy').then((response) => {
66+
expect(response.statusCode).toBe(200);
67+
expect(response.body).toHaveProperty('name', 'Falcon Heavy');
68+
expect(response.body).toHaveProperty('stages', 2);
69+
expect(response.body).toHaveProperty('cost_per_launch');
70+
expect(response.body).toHaveProperty('success_rate_pct');
71+
expect(response.body).toHaveProperty('first_flight');
72+
expect(response.body).toHaveProperty('country');
73+
expect(response.body).toHaveProperty('company', 'SpaceX');
74+
expect(response.body).toHaveProperty('description');
75+
});
76+
});

test/v2-routes.test.js

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,6 @@ beforeAll((done) => {
99
});
1010
});
1111

12-
//------------------------------------------------------------
13-
// Rockets V2
14-
//------------------------------------------------------------
15-
16-
test('It should return all rocket info', () => {
17-
return request(app).get('/v2/rockets').then((response) => {
18-
expect(response.statusCode).toBe(200);
19-
expect(response.body).toHaveLength(3);
20-
expect(response.body[0]).toHaveProperty('name', 'Falcon 1');
21-
expect(response.body[1]).toHaveProperty('name', 'Falcon 9');
22-
expect(response.body[2]).toHaveProperty('name', 'Falcon Heavy');
23-
24-
response.body.forEach((item) => {
25-
expect(item).toHaveProperty('id', expect.any(String));
26-
expect(item).toHaveProperty('name', expect.any(String));
27-
expect(item).toHaveProperty('type', expect.stringMatching(/^(?:rocket|capsule)$/));
28-
expect(item).toHaveProperty('active', expect.any(Boolean));
29-
expect(item).toHaveProperty('stages', expect.any(Number));
30-
expect(item).toHaveProperty('boosters', expect.any(Number));
31-
expect(item).toHaveProperty('cost_per_launch', expect.any(Number));
32-
expect(item).toHaveProperty('success_rate_pct', expect.any(Number));
33-
expect(item).toHaveProperty('first_flight', expect.stringMatching(/^(?:[0-9]{4}-[0-9]{2}-[0-9]{2}|TBD)$/));
34-
expect(item).toHaveProperty('country', expect.any(String));
35-
expect(item).toHaveProperty('company', expect.any(String));
36-
expect(item).toHaveProperty('height', customMatchers.length());
37-
expect(item).toHaveProperty('diameter', customMatchers.length());
38-
expect(item).toHaveProperty('mass', customMatchers.mass());
39-
expect(item).toHaveProperty('payload_weights', expect.any(Array));
40-
item.payload_weights.forEach((weight) => {
41-
expect(weight).toEqual(customMatchers.payloadWeight());
42-
});
43-
expect(item).toHaveProperty('first_stage', customMatchers.vehicleStage());
44-
expect(item).toHaveProperty('second_stage', customMatchers.vehicleStage());
45-
expect(item).toHaveProperty('description', expect.any(String));
46-
});
47-
});
48-
});
49-
50-
test('It should return Falcon 1 info', () => {
51-
return request(app).get('/v2/rockets/falcon1').then((response) => {
52-
expect(response.statusCode).toBe(200);
53-
expect(response.body).toHaveProperty('name', 'Falcon 1');
54-
expect(response.body).toHaveProperty('stages', 2);
55-
expect(response.body).toHaveProperty('cost_per_launch');
56-
expect(response.body).toHaveProperty('success_rate_pct');
57-
expect(response.body).toHaveProperty('first_flight', '2006-03-24');
58-
expect(response.body).toHaveProperty('country');
59-
expect(response.body).toHaveProperty('company', 'SpaceX');
60-
expect(response.body).toHaveProperty('description');
61-
});
62-
});
63-
64-
test('It should return Falcon Heavy info', () => {
65-
return request(app).get('/v2/rockets/falconheavy').then((response) => {
66-
expect(response.statusCode).toBe(200);
67-
expect(response.body).toHaveProperty('name', 'Falcon Heavy');
68-
expect(response.body).toHaveProperty('stages', 2);
69-
expect(response.body).toHaveProperty('cost_per_launch');
70-
expect(response.body).toHaveProperty('success_rate_pct');
71-
expect(response.body).toHaveProperty('first_flight');
72-
expect(response.body).toHaveProperty('country');
73-
expect(response.body).toHaveProperty('company', 'SpaceX');
74-
expect(response.body).toHaveProperty('description');
75-
});
76-
});
77-
7812
//------------------------------------------------------------
7913
// Launchpads V2
8014
//------------------------------------------------------------

0 commit comments

Comments
 (0)