|
| 1 | + |
| 2 | +const request = require('supertest'); |
| 3 | +const app = require('../../src/app'); |
| 4 | + |
| 5 | +beforeAll((done) => { |
| 6 | + app.on('ready', () => { |
| 7 | + done(); |
| 8 | + }); |
| 9 | +}); |
| 10 | + |
| 11 | +//------------------------------------------------------------ |
| 12 | +// Launch Query Test |
| 13 | +//------------------------------------------------------------ |
| 14 | + |
| 15 | +test('It should return flight number 42', () => { |
| 16 | + return request(app).get('/v2/launches?flight_number=42').then((response) => { |
| 17 | + expect(response.statusCode).toBe(200); |
| 18 | + response.body.forEach((item) => { |
| 19 | + expect(item).toHaveProperty('flight_number', 42); |
| 20 | + }); |
| 21 | + }); |
| 22 | +}); |
| 23 | + |
| 24 | +test('It should return flight 42 in date range', () => { |
| 25 | + return request(app).get('/v2/launches?start=2017-06-22&final=2017-06-25').then((response) => { |
| 26 | + expect(response.statusCode).toBe(200); |
| 27 | + response.body.forEach((item) => { |
| 28 | + expect(item).toHaveProperty('flight_number', 42); |
| 29 | + }); |
| 30 | + }); |
| 31 | +}); |
| 32 | + |
| 33 | +test('It should return launches in 2017', () => { |
| 34 | + return request(app).get('/v2/launches?launch_year=2017').then((response) => { |
| 35 | + expect(response.statusCode).toBe(200); |
| 36 | + expect(response.body.length).toEqual(18); |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | +test('It should return flight 42 with given launch date in UTC', () => { |
| 41 | + return request(app).get('/v2/launches?launch_date_utc=2017-06-23T19:10:00Z').then((response) => { |
| 42 | + expect(response.statusCode).toBe(200); |
| 43 | + response.body.forEach((item) => { |
| 44 | + expect(item).toHaveProperty('flight_number', 42); |
| 45 | + }); |
| 46 | + }); |
| 47 | +}); |
| 48 | + |
| 49 | +test('It should return flight 42 with given launch date in local time', () => { |
| 50 | + return request(app).get('/v2/launches?launch_date_local=2017-06-23T15:10:00-04:00').then((response) => { |
| 51 | + expect(response.statusCode).toBe(200); |
| 52 | + response.body.forEach((item) => { |
| 53 | + expect(item).toHaveProperty('flight_number', 42); |
| 54 | + }); |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +test('It should return launches with falcon9 rocket id', () => { |
| 59 | + return request(app).get('/v2/launches?rocket_id=falcon9').then((response) => { |
| 60 | + expect(response.statusCode).toBe(200); |
| 61 | + response.body.forEach((item) => { |
| 62 | + expect(item).toHaveProperty('rocket.rocket_id', 'falcon9'); |
| 63 | + }); |
| 64 | + }); |
| 65 | +}); |
| 66 | + |
| 67 | +test('It should return launches with falcon 9 rocket name', () => { |
| 68 | + return request(app).get('/v2/launches?rocket_name=Falcon+9').then((response) => { |
| 69 | + expect(response.statusCode).toBe(200); |
| 70 | + response.body.forEach((item) => { |
| 71 | + expect(item).toHaveProperty('rocket.rocket_name', 'Falcon 9'); |
| 72 | + }); |
| 73 | + }); |
| 74 | +}); |
| 75 | + |
| 76 | +test('It should return launches with FT rocket type', () => { |
| 77 | + return request(app).get('/v2/launches?rocket_type=FT').then((response) => { |
| 78 | + expect(response.statusCode).toBe(200); |
| 79 | + response.body.forEach((item) => { |
| 80 | + expect(item).toHaveProperty('rocket.rocket_type', 'FT'); |
| 81 | + }); |
| 82 | + }); |
| 83 | +}); |
| 84 | + |
| 85 | +test('It should return launches with core serial B1029', () => { |
| 86 | + return request(app).get('/v2/launches?core_serial=B1029').then((response) => { |
| 87 | + expect(response.statusCode).toBe(200); |
| 88 | + response.body.forEach((item) => { |
| 89 | + item.rocket.first_stage.cores.forEach((core) => { |
| 90 | + expect(core).toHaveProperty('core_serial', 'B1029'); |
| 91 | + }); |
| 92 | + }); |
| 93 | + }); |
| 94 | +}); |
| 95 | + |
| 96 | +test('It should return launches with cap serial C113', () => { |
| 97 | + return request(app).get('/v2/launches?cap_serial=C113').then((response) => { |
| 98 | + expect(response.statusCode).toBe(200); |
| 99 | + response.body.forEach((item) => { |
| 100 | + item.rocket.second_stage.payloads.forEach((cap) => { |
| 101 | + expect(cap).toHaveProperty('cap_serial', 'C113'); |
| 102 | + }); |
| 103 | + }); |
| 104 | + }); |
| 105 | +}); |
| 106 | + |
| 107 | +test('It should return launches with 2 core flights', () => { |
| 108 | + return request(app).get('/v2/launches?core_flight=2').then((response) => { |
| 109 | + expect(response.statusCode).toBe(200); |
| 110 | + response.body.forEach((item) => { |
| 111 | + item.rocket.first_stage.cores.forEach((core) => { |
| 112 | + expect(core).toHaveProperty('flight'); |
| 113 | + }); |
| 114 | + }); |
| 115 | + }); |
| 116 | +}); |
| 117 | + |
| 118 | +test('It should return launches with reused cores', () => { |
| 119 | + return request(app).get('/v2/launches?core_reuse=true').then((response) => { |
| 120 | + expect(response.statusCode).toBe(200); |
| 121 | + response.body.forEach((item) => { |
| 122 | + expect(item.reuse).toHaveProperty('core', true); |
| 123 | + }); |
| 124 | + }); |
| 125 | +}); |
| 126 | + |
| 127 | +test('It should return launches with reused side core 1', () => { |
| 128 | + return request(app).get('/v2/launches?side_core1_reuse=true').then((response) => { |
| 129 | + expect(response.statusCode).toBe(200); |
| 130 | + response.body.forEach((item) => { |
| 131 | + expect(item.reuse).toHaveProperty('side_core1', true); |
| 132 | + }); |
| 133 | + }); |
| 134 | +}); |
| 135 | + |
| 136 | +test('It should return launches with reused side core 2', () => { |
| 137 | + return request(app).get('/v2/launches?side_core2_reuse=true').then((response) => { |
| 138 | + expect(response.statusCode).toBe(200); |
| 139 | + response.body.forEach((item) => { |
| 140 | + expect(item.reuse).toHaveProperty('side_core2', true); |
| 141 | + }); |
| 142 | + }); |
| 143 | +}); |
| 144 | + |
| 145 | +test('It should return launches with no reused fairings', () => { |
| 146 | + return request(app).get('/v2/launches?fairings_reuse=false').then((response) => { |
| 147 | + expect(response.statusCode).toBe(200); |
| 148 | + response.body.forEach((item) => { |
| 149 | + expect(item.reuse).toHaveProperty('fairings', false); |
| 150 | + }); |
| 151 | + }); |
| 152 | +}); |
| 153 | + |
| 154 | +test('It should return launches with reused capsules', () => { |
| 155 | + return request(app).get('/v2/launches?capsule_reuse=true').then((response) => { |
| 156 | + expect(response.statusCode).toBe(200); |
| 157 | + response.body.forEach((item) => { |
| 158 | + expect(item.reuse).toHaveProperty('capsule', true); |
| 159 | + }); |
| 160 | + }); |
| 161 | +}); |
| 162 | + |
| 163 | +// test('It should return', () => { |
| 164 | +// return request(app).get('/v2/launches?').then((response) => { |
| 165 | +// expect(response.statusCode).toBe(200); |
| 166 | +// response.body.forEach((item) => { |
| 167 | +// expect(item).toHaveProperty('', ''); |
| 168 | +// }); |
| 169 | +// }); |
| 170 | +// }); |
| 171 | + |
| 172 | +// test('It should return', () => { |
| 173 | +// return request(app).get('/v2/launches?').then((response) => { |
| 174 | +// expect(response.statusCode).toBe(200); |
| 175 | +// response.body.forEach((item) => { |
| 176 | +// expect(item).toHaveProperty('', ''); |
| 177 | +// }); |
| 178 | +// }); |
| 179 | +// }); |
| 180 | + |
| 181 | +// test('It should return', () => { |
| 182 | +// return request(app).get('/v2/launches?').then((response) => { |
| 183 | +// expect(response.statusCode).toBe(200); |
| 184 | +// response.body.forEach((item) => { |
| 185 | +// expect(item).toHaveProperty('', ''); |
| 186 | +// }); |
| 187 | +// }); |
| 188 | +// }); |
| 189 | + |
| 190 | +// test('It should return', () => { |
| 191 | +// return request(app).get('/v2/launches?').then((response) => { |
| 192 | +// expect(response.statusCode).toBe(200); |
| 193 | +// response.body.forEach((item) => { |
| 194 | +// expect(item).toHaveProperty('', ''); |
| 195 | +// }); |
| 196 | +// }); |
| 197 | +// }); |
| 198 | + |
| 199 | +// test('It should return', () => { |
| 200 | +// return request(app).get('/v2/launches?').then((response) => { |
| 201 | +// expect(response.statusCode).toBe(200); |
| 202 | +// response.body.forEach((item) => { |
| 203 | +// expect(item).toHaveProperty('', ''); |
| 204 | +// }); |
| 205 | +// }); |
| 206 | +// }); |
| 207 | + |
| 208 | +// test('It should return', () => { |
| 209 | +// return request(app).get('/v2/launches?').then((response) => { |
| 210 | +// expect(response.statusCode).toBe(200); |
| 211 | +// response.body.forEach((item) => { |
| 212 | +// expect(item).toHaveProperty('', ''); |
| 213 | +// }); |
| 214 | +// }); |
| 215 | +// }); |
| 216 | + |
| 217 | +// test('It should return', () => { |
| 218 | +// return request(app).get('/v2/launches?').then((response) => { |
| 219 | +// expect(response.statusCode).toBe(200); |
| 220 | +// response.body.forEach((item) => { |
| 221 | +// expect(item).toHaveProperty('', ''); |
| 222 | +// }); |
| 223 | +// }); |
| 224 | +// }); |
| 225 | + |
| 226 | +// test('It should return', () => { |
| 227 | +// return request(app).get('/v2/launches?').then((response) => { |
| 228 | +// expect(response.statusCode).toBe(200); |
| 229 | +// response.body.forEach((item) => { |
| 230 | +// expect(item).toHaveProperty('', ''); |
| 231 | +// }); |
| 232 | +// }); |
| 233 | +// }); |
| 234 | + |
| 235 | +// test('It should return', () => { |
| 236 | +// return request(app).get('/v2/launches?').then((response) => { |
| 237 | +// expect(response.statusCode).toBe(200); |
| 238 | +// response.body.forEach((item) => { |
| 239 | +// expect(item).toHaveProperty('', ''); |
| 240 | +// }); |
| 241 | +// }); |
| 242 | +// }); |
| 243 | + |
| 244 | +// test('It should return', () => { |
| 245 | +// return request(app).get('/v2/launches?').then((response) => { |
| 246 | +// expect(response.statusCode).toBe(200); |
| 247 | +// response.body.forEach((item) => { |
| 248 | +// expect(item).toHaveProperty('', ''); |
| 249 | +// }); |
| 250 | +// }); |
| 251 | +// }); |
| 252 | + |
| 253 | +// test('It should return', () => { |
| 254 | +// return request(app).get('/v2/launches?').then((response) => { |
| 255 | +// expect(response.statusCode).toBe(200); |
| 256 | +// response.body.forEach((item) => { |
| 257 | +// expect(item).toHaveProperty('', ''); |
| 258 | +// }); |
| 259 | +// }); |
| 260 | +// }); |
0 commit comments