|
1 | 1 |
|
2 | 2 | const request = require("supertest") |
3 | 3 | const app = require("../app") |
| 4 | +const customMatchers = require("./utilities/custom-asymmetric-matchers") |
4 | 5 |
|
5 | 6 | beforeAll((done) => { |
6 | 7 | app.on("ready", () => { |
7 | 8 | done() |
8 | 9 | }) |
9 | 10 | }) |
10 | 11 |
|
| 12 | +//------------------------------------------------------------ |
| 13 | +// Home Page V2 |
| 14 | +//------------------------------------------------------------ |
| 15 | + |
| 16 | +test("It should return home info", () => { |
| 17 | + return request(app).get("/v2").then(response => { |
| 18 | + expect(response.statusCode).toBe(200) |
| 19 | + expect(response.body).toHaveProperty("description") |
| 20 | + expect(response.body).toHaveProperty("organization", "r/SpaceX") |
| 21 | + expect(response.body).toHaveProperty("organization_link", "https://github.com/r-spacex") |
| 22 | + expect(response.body).toHaveProperty("project_link", "https://github.com/r-spacex/SpaceX-API") |
| 23 | + expect(response.body).toHaveProperty("project_name", "SpaceX-API") |
| 24 | + expect(response.body).toHaveProperty("version") |
| 25 | + }) |
| 26 | +}) |
| 27 | + |
| 28 | +//------------------------------------------------------------ |
| 29 | +// Company Info V2 |
| 30 | +//------------------------------------------------------------ |
| 31 | + |
| 32 | +test("It should return company info", () => { |
| 33 | + return request(app).get("/v2/info").then(response => { |
| 34 | + expect(response.statusCode).toBe(200) |
| 35 | + expect(response.body).toHaveProperty("name", "SpaceX") |
| 36 | + expect(response.body).toHaveProperty("founder", "Elon Musk") |
| 37 | + expect(response.body).toHaveProperty("founded", 2002) |
| 38 | + expect(response.body).toHaveProperty("employees") |
| 39 | + expect(response.body).toHaveProperty("vehicles") |
| 40 | + expect(response.body).toHaveProperty("launch_sites") |
| 41 | + expect(response.body).toHaveProperty("test_sites") |
| 42 | + expect(response.body).toHaveProperty("ceo") |
| 43 | + expect(response.body).toHaveProperty("cto") |
| 44 | + expect(response.body).toHaveProperty("coo") |
| 45 | + expect(response.body).toHaveProperty("cto_propulsion") |
| 46 | + expect(response.body).toHaveProperty("valuation") |
| 47 | + expect(response.body).toHaveProperty("headquarters.address", "Rocket Road") |
| 48 | + expect(response.body).toHaveProperty("headquarters.city", "Hawthorne") |
| 49 | + expect(response.body).toHaveProperty("headquarters.state", "California") |
| 50 | + expect(response.body).toHaveProperty("summary") |
| 51 | + }) |
| 52 | +}) |
| 53 | + |
| 54 | +//------------------------------------------------------------ |
| 55 | +// Vehicles V2 |
| 56 | +//------------------------------------------------------------ |
| 57 | + |
| 58 | +test("It should return all vehicle info", () => { |
| 59 | + return request(app).get("/v2/vehicles").then(response => { |
| 60 | + expect(response.statusCode).toBe(200) |
| 61 | + expect(response.body).toHaveLength(4) |
| 62 | + expect(response.body[0]).toHaveProperty("name", "Falcon 1") |
| 63 | + expect(response.body[1]).toHaveProperty("name", "Falcon 9") |
| 64 | + expect(response.body[2]).toHaveProperty("name", "Falcon Heavy") |
| 65 | + expect(response.body[3]).toHaveProperty("name", "Dragon 1") |
| 66 | + |
| 67 | + response.body.forEach(item => { |
| 68 | + expect(item).toHaveProperty("id", expect.any(String)) |
| 69 | + expect(item).toHaveProperty("name", expect.any(String)) |
| 70 | + expect(item).toHaveProperty("type", expect.stringMatching(/^(?:rocket|capsule)$/)) |
| 71 | + expect(item).toHaveProperty("active", expect.any(Boolean)) |
| 72 | + if (item.type === "rocket") { |
| 73 | + expect(item).toHaveProperty("stages", expect.any(Number)) |
| 74 | + // expect(item).toHaveProperty("boosters", expect.any(Number)) // missing from falcon1 |
| 75 | + expect(item).toHaveProperty("cost_per_launch", expect.any(Number)) |
| 76 | + // expect(item).toHaveProperty("orbit_duration_yr", expect.any(Number)) // missing from falcon1 |
| 77 | + // expect(item).toHaveProperty("success_rate_pct", expect.any(Number)) // missing from FH |
| 78 | + expect(item).toHaveProperty("first_flight", expect.stringMatching(/^(?:[0-9]{4}-[0-9]{2}-[0-9]{2}|TBD)$/)) |
| 79 | + // expect(item).toHaveProperty("launchpad", expect.any(String)) // missing from falcon9 |
| 80 | + expect(item).toHaveProperty("country", expect.any(String)) |
| 81 | + expect(item).toHaveProperty("company", expect.any(String)) |
| 82 | + expect(item).toHaveProperty("height", customMatchers.length()) |
| 83 | + // expect(item).toHaveProperty("diameter", customMatchers.length()) // missing from FH |
| 84 | + // expect(item).toHaveProperty("total_width",customMatchers.length()) // missing from falcon1 |
| 85 | + expect(item).toHaveProperty("mass", customMatchers.mass()) |
| 86 | + expect(item).toHaveProperty("payload_weights", expect.any(Array)) |
| 87 | + item.payload_weights.forEach(weight => { |
| 88 | + expect(weight).toEqual(customMatchers.payloadWeight()) |
| 89 | + }) |
| 90 | + expect(item).toHaveProperty("first_stage", customMatchers.vehicleStage()) |
| 91 | + expect(item).toHaveProperty("second_stage", customMatchers.vehicleStage()) |
| 92 | + // expect(item).toHaveProperty("landing_legs", expect.any(Number)) // missing from falcon1 |
| 93 | + expect(item).toHaveProperty("description", expect.any(String)) |
| 94 | + } |
| 95 | + else if (item.type === "capsule") { |
| 96 | + expect(item).toHaveProperty("sidewall_angle_deg", expect.any(Number)) |
| 97 | + expect(item).toHaveProperty("orbit_duration_yr", expect.any(Number)) |
| 98 | + expect(item).toHaveProperty("variations", expect.any(Object)) // TODO test it deeper |
| 99 | + expect(item).toHaveProperty("heat_shield.dev_partner", expect.any(String)) |
| 100 | + expect(item).toHaveProperty("heat_shield.material", expect.any(String)) |
| 101 | + expect(item).toHaveProperty("heat_shield.size_meters", expect.any(Number)) |
| 102 | + expect(item).toHaveProperty("heat_shield.temp_degrees", expect.any(Number)) |
| 103 | + expect(item).toHaveProperty("thrusters.amount", expect.any(Number)) |
| 104 | + expect(item).toHaveProperty("thrusters.fuel_1", expect.any(String)) |
| 105 | + expect(item).toHaveProperty("thrusters.fuel_2", expect.any(String)) |
| 106 | + expect(item).toHaveProperty("thrusters.pods", expect.any(Number)) |
| 107 | + expect(item).toHaveProperty("thrusters.thrust", customMatchers.thrust()) |
| 108 | + expect(item).toHaveProperty("thrusters.type", expect.any(String)) |
| 109 | + expect(item).toHaveProperty("launch_payload_mass", customMatchers.mass()) |
| 110 | + expect(item).toHaveProperty("launch_payload_vol", customMatchers.volume()) |
| 111 | + expect(item).toHaveProperty("return_payload_mass", customMatchers.mass()) |
| 112 | + expect(item).toHaveProperty("return_payload_vol", customMatchers.volume()) |
| 113 | + expect(item).toHaveProperty("pressurized_capsule.payload_volume", customMatchers.volume()) |
| 114 | + expect(item).toHaveProperty("trunk.cargo.solar_array", expect.any(Number)) |
| 115 | + expect(item).toHaveProperty("trunk.cargo.unpressurized_cargo", expect.any(Boolean)) |
| 116 | + expect(item).toHaveProperty("trunk.trunk_volume", customMatchers.volume()) |
| 117 | + expect(item).toHaveProperty("height_w_trunk", customMatchers.length()) |
| 118 | + expect(item).toHaveProperty("diameter", customMatchers.length()) |
| 119 | + } |
| 120 | + }) |
| 121 | + }) |
| 122 | +}) |
| 123 | + |
| 124 | +test("It should return Falcon 1 info", () => { |
| 125 | + return request(app).get("/v2/vehicles/falcon1").then(response => { |
| 126 | + expect(response.statusCode).toBe(200) |
| 127 | + expect(response.body).toHaveProperty("name", "Falcon 1") |
| 128 | + expect(response.body).toHaveProperty("stages", 2) |
| 129 | + expect(response.body).toHaveProperty("cost_per_launch") |
| 130 | + expect(response.body).toHaveProperty("success_rate_pct") |
| 131 | + expect(response.body).toHaveProperty("first_flight", "2006-03-24") |
| 132 | + expect(response.body).toHaveProperty("country") |
| 133 | + expect(response.body).toHaveProperty("company", "SpaceX") |
| 134 | + expect(response.body).toHaveProperty("description") |
| 135 | + expect(Object.keys(response.body)).toEqual([ |
| 136 | + "id", |
| 137 | + "name", |
| 138 | + "type", |
| 139 | + "active", |
| 140 | + "stages", |
| 141 | + // "boosters", |
| 142 | + "cost_per_launch", |
| 143 | + "success_rate_pct", |
| 144 | + "first_flight", |
| 145 | + "launchpad", |
| 146 | + "country", |
| 147 | + "company", |
| 148 | + "height", |
| 149 | + "diameter", |
| 150 | + // "total_width", |
| 151 | + "mass", |
| 152 | + "payload_weights", |
| 153 | + "first_stage", |
| 154 | + "second_stage", |
| 155 | + // "engines", |
| 156 | + // "landing_legs", |
| 157 | + "description" |
| 158 | + ]) |
| 159 | + }) |
| 160 | +}) |
| 161 | + |
| 162 | +test("It should return Falcon 9 info", () => { |
| 163 | + return request(app).get("/v2/vehicles/falcon9").then(response => { |
| 164 | + expect(response.statusCode).toBe(200) |
| 165 | + expect(response.body).toHaveProperty("name", "Falcon 9") |
| 166 | + expect(response.body).toHaveProperty("stages", 2) |
| 167 | + expect(response.body).toHaveProperty("cost_per_launch") |
| 168 | + expect(response.body).toHaveProperty("success_rate_pct") |
| 169 | + expect(response.body).toHaveProperty("first_flight", "2010-06-04") |
| 170 | + expect(response.body).toHaveProperty("country") |
| 171 | + expect(response.body).toHaveProperty("company", "SpaceX") |
| 172 | + expect(response.body).toHaveProperty("description") |
| 173 | + expect(Object.keys(response.body)).toEqual([ |
| 174 | + "id", |
| 175 | + "name", |
| 176 | + "type", |
| 177 | + "active", |
| 178 | + "stages", |
| 179 | + // "boosters", |
| 180 | + "cost_per_launch", |
| 181 | + "success_rate_pct", |
| 182 | + "first_flight", |
| 183 | + // "launchpad", |
| 184 | + "country", |
| 185 | + "company", |
| 186 | + "height", |
| 187 | + "diameter", |
| 188 | + // "total_width", |
| 189 | + "mass", |
| 190 | + "payload_weights", |
| 191 | + "first_stage", |
| 192 | + "second_stage", |
| 193 | + "engines", |
| 194 | + "landing_legs", |
| 195 | + "description" |
| 196 | + ]) |
| 197 | + }) |
| 198 | +}) |
| 199 | + |
| 200 | +test("It should return Falcon Heavy info", () => { |
| 201 | + return request(app).get("/v2/vehicles/falconheavy").then(response => { |
| 202 | + expect(response.statusCode).toBe(200) |
| 203 | + expect(response.body).toHaveProperty("name", "Falcon Heavy") |
| 204 | + expect(response.body).toHaveProperty("stages", 2) |
| 205 | + expect(response.body).toHaveProperty("cost_per_launch") |
| 206 | + // expect(response.body).toHaveProperty("success_rate_pct") |
| 207 | + // expect(response.body).toHaveProperty("first_flight") |
| 208 | + expect(response.body).toHaveProperty("country") |
| 209 | + expect(response.body).toHaveProperty("company", "SpaceX") |
| 210 | + expect(response.body).toHaveProperty("description") |
| 211 | + expect(Object.keys(response.body)).toEqual([ |
| 212 | + "id", |
| 213 | + "name", |
| 214 | + "type", |
| 215 | + "active", |
| 216 | + "stages", |
| 217 | + "boosters", |
| 218 | + "cost_per_launch", |
| 219 | + // "success_rate_pct", |
| 220 | + "first_flight", |
| 221 | + // "launchpad", |
| 222 | + "country", |
| 223 | + "company", |
| 224 | + "height", |
| 225 | + // "diameter", |
| 226 | + "total_width", |
| 227 | + "mass", |
| 228 | + "payload_weights", |
| 229 | + "first_stage", |
| 230 | + "second_stage", |
| 231 | + "engines", |
| 232 | + "landing_legs", |
| 233 | + "description" |
| 234 | + ]) |
| 235 | + }) |
| 236 | +}) |
| 237 | + |
| 238 | +test("It should return Dragon info", () => { |
| 239 | + return request(app).get("/v2/vehicles/dragon").then(response => { |
| 240 | + expect(response.statusCode).toBe(200) |
| 241 | + expect(response.body).toHaveProperty("name", "Dragon 1") |
| 242 | + expect(Object.keys(response.body)).toEqual([ |
| 243 | + "id", |
| 244 | + "name", |
| 245 | + "type", |
| 246 | + "active", |
| 247 | + // "stages", |
| 248 | + // "cost_per_launch", |
| 249 | + // "success_rate_pct", |
| 250 | + // "first_flight", |
| 251 | + // "launchpad", |
| 252 | + // "country", |
| 253 | + // "company", |
| 254 | + // "height", |
| 255 | + "sidewall_angle_deg", // capsule specific field |
| 256 | + "orbit_duration_yr", // capsule specific field |
| 257 | + "variations", // capsule specific field |
| 258 | + "heat_shield", // capsule specific field |
| 259 | + "thrusters", // capsule specific field |
| 260 | + "launch_payload_mass", // capsule specific field |
| 261 | + "launch_payload_vol", // capsule specific field |
| 262 | + "return_payload_mass", // capsule specific field |
| 263 | + "return_payload_vol", // capsule specific field |
| 264 | + "pressurized_capsule", // capsule specific field |
| 265 | + "trunk", // capsule specific field |
| 266 | + "height_w_trunk", // capsule specific field |
| 267 | + "diameter", |
| 268 | + // "mass", |
| 269 | + // "payload_weights", |
| 270 | + // "first_stage", |
| 271 | + // "second_stage", |
| 272 | + // "description" |
| 273 | + ]) |
| 274 | + }) |
| 275 | +}) |
| 276 | + |
| 277 | +//------------------------------------------------------------ |
| 278 | +// Launchpads V2 |
| 279 | +//------------------------------------------------------------ |
| 280 | + |
| 281 | +test("It should return all launchpads", () => { |
| 282 | + return request(app).get("/v2/launchpads").then(response => { |
| 283 | + expect(response.statusCode).toBe(200) |
| 284 | + expect(response.body).toHaveLength(8) |
| 285 | + response.body.forEach(item => { |
| 286 | + expect(item).toHaveProperty("id") |
| 287 | + expect(item).toHaveProperty("full_name") |
| 288 | + expect(item).toHaveProperty("status") |
| 289 | + expect(item).toHaveProperty("vehicles_launched") |
| 290 | + expect(item).toHaveProperty("details") |
| 291 | + }) |
| 292 | + }) |
| 293 | +}) |
| 294 | + |
| 295 | +test("It should return LC-39A info", () => { |
| 296 | + return request(app).get("/v2/launchpads/ksc_lc_39a").then(response => { |
| 297 | + expect(response.statusCode).toBe(200) |
| 298 | + expect(response.text).toContain("ksc_lc_39a") |
| 299 | + }) |
| 300 | +}) |
| 301 | + |
| 302 | +test("It should return no launchpads found info", () => { |
| 303 | + return request(app).get("/v2/launchpads/ksc_lc_40a").then(response => { |
| 304 | + expect(response.statusCode).toBe(404) |
| 305 | + expect(response.text).toContain("No results found") |
| 306 | + }) |
| 307 | +}) |
| 308 | + |
11 | 309 | //------------------------------------------------------------ |
12 | 310 | // Past Launches V2 |
13 | 311 | //------------------------------------------------------------ |
@@ -72,3 +370,68 @@ test("It should return all past launches", () => { |
72 | 370 | }) |
73 | 371 | }) |
74 | 372 | }) |
| 373 | + |
| 374 | +//------------------------------------------------------------ |
| 375 | +// Upcoming Launches V2 |
| 376 | +//------------------------------------------------------------ |
| 377 | + |
| 378 | +test("It should return all past launches", () => { |
| 379 | + return request(app.listen()).get("/v2/launches/upcoming").then(response => { |
| 380 | + expect(response.statusCode).toBe(200) |
| 381 | + response.body.forEach(item => { |
| 382 | + expect(item).toHaveProperty("flight_number", expect.anything()) |
| 383 | + expect(item).toHaveProperty("launch_year", expect.stringMatching(/^[0-9]{4}$/)) |
| 384 | + expect(item).toHaveProperty("launch_date_unix") |
| 385 | + expect(item).toHaveProperty("launch_date_utc", expect.anything()) |
| 386 | + expect(item).toHaveProperty("launch_date_local", expect.anything()) |
| 387 | + expect(item).toHaveProperty("rocket.rocket_id") |
| 388 | + expect(item).toHaveProperty("rocket.rocket_name") |
| 389 | + expect(item).toHaveProperty("rocket.rocket_type") |
| 390 | + expect(item.rocket.first_stage.cores.length).toBeGreaterThan(0) |
| 391 | + item.rocket.first_stage.cores.forEach(core => { |
| 392 | + expect(core).toHaveProperty("core_serial") |
| 393 | + expect(core).toHaveProperty("reused") |
| 394 | + expect(core).toHaveProperty("land_success") |
| 395 | + expect(core).toHaveProperty("landing_type") |
| 396 | + expect(core).toHaveProperty("landing_vehicle") |
| 397 | + }) |
| 398 | + expect(item.rocket.second_stage.payloads.length).toBeGreaterThan(0) |
| 399 | + if (item.hasOwnProperty("cap_serial")) { |
| 400 | + item.rocket.second_stage.payloads.forEach(payload => { |
| 401 | + expect(payload).toHaveProperty("payload_id") |
| 402 | + expect(payload).toHaveProperty("reused") |
| 403 | + expect(payload).toHaveProperty("cap_serial") |
| 404 | + expect(payload.customers.length).toBeGreaterThan(0) |
| 405 | + expect(payload).toHaveProperty("payload_mass_kg") |
| 406 | + expect(payload).toHaveProperty("payload_mass_lbs") |
| 407 | + expect(payload).toHaveProperty("orbit") |
| 408 | + expect(payload).toHaveProperty("mass_returned_kg") |
| 409 | + expect(payload).toHaveProperty("mass_returned_lbs") |
| 410 | + expect(payload).toHaveProperty("flight_time_sec") |
| 411 | + expect(payload).toHaveProperty("cargo_manifest") |
| 412 | + }) |
| 413 | + } else { |
| 414 | + item.rocket.second_stage.payloads.forEach(payload => { |
| 415 | + expect(payload).toHaveProperty("payload_id") |
| 416 | + expect(payload).toHaveProperty("reused") |
| 417 | + expect(payload.customers.length).toBeGreaterThan(0) |
| 418 | + expect(payload).toHaveProperty("payload_mass_kg") |
| 419 | + expect(payload).toHaveProperty("payload_mass_lbs") |
| 420 | + expect(payload).toHaveProperty("orbit") |
| 421 | + }) |
| 422 | + } |
| 423 | + expect(item).toHaveProperty("telemetry.flight_club") |
| 424 | + expect(item).toHaveProperty("reuse.core") |
| 425 | + expect(item).toHaveProperty("reuse.side_core1") |
| 426 | + expect(item).toHaveProperty("reuse.side_core2") |
| 427 | + expect(item).toHaveProperty("reuse.fairings") |
| 428 | + expect(item).toHaveProperty("reuse.capsule") |
| 429 | + expect(item).toHaveProperty("launch_site.site_id") |
| 430 | + expect(item).toHaveProperty("launch_site.site_name") |
| 431 | + expect(item).toHaveProperty("launch_site.site_name_long") |
| 432 | + expect(item).toHaveProperty("launch_success") |
| 433 | + expect(item).toHaveProperty("links") |
| 434 | + expect(item).toHaveProperty("details") |
| 435 | + }) |
| 436 | + }) |
| 437 | +}) |
0 commit comments