Skip to content

Commit

Permalink
Merge branch 'dev' into modalForExternalRedirects
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpar06 authored Feb 12, 2024
2 parents 59e32e8 + 499bca3 commit b33ae8a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
5 changes: 4 additions & 1 deletion app/Services/FlightService.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ public function isFlightDuplicate(Flight $flight)
// If this list is > 0, then this has a duplicate
$found_flights = $found_flights->filter(function ($value, $key) use ($flight) {
return $flight->route_code === $value->route_code
&& $flight->route_leg === $value->route_leg;
&& $flight->route_leg === $value->route_leg
&& $flight->dpt_airport_id === $value->dpt_airport_id
&& $flight->arr_airport_id === $value->arr_airport_id
&& $flight->days === $value->days;
});

return !($found_flights->count() === 0);
Expand Down
42 changes: 27 additions & 15 deletions tests/FlightTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,40 +45,52 @@ public function testDuplicateFlight()
$this->assertFalse($this->flightSvc->isFlightDuplicate($flight));

$flight_dupe = new Flight([
'airline_id' => $flight->airline_id,
'flight_number' => $flight->flight_number,
'route_code' => $flight->route_code,
'route_leg' => $flight->route_leg,
'airline_id' => $flight->airline_id,
'flight_number' => $flight->flight_number,
'route_code' => $flight->route_code,
'route_leg' => $flight->route_leg,
'dpt_airport_id' => $flight->dpt_airport_id,
'arr_airport_id' => $flight->arr_airport_id,
'days' => $flight->days,
]);

$this->assertTrue($this->flightSvc->isFlightDuplicate($flight_dupe));

// same flight but diff airline shouldn't be a dupe
$new_airline = Airline::factory()->create();
$flight_dupe = new Flight([
'airline_id' => $new_airline->airline_id,
'flight_number' => $flight->flight_number,
'route_code' => $flight->route_code,
'route_leg' => $flight->route_leg,
'airline_id' => $new_airline->airline_id,
'flight_number' => $flight->flight_number,
'route_code' => $flight->route_code,
'route_leg' => $flight->route_leg,
'dpt_airport_id' => $flight->dpt_airport_id,
'arr_airport_id' => $flight->arr_airport_id,
'days' => $flight->days,
]);

$this->assertFalse($this->flightSvc->isFlightDuplicate($flight_dupe));

// add another flight with a code
$flight_leg = Flight::factory()->create([
'airline_id' => $flight->airline_id,
'flight_number' => $flight->flight_number,
'route_code' => 'A',
'airline_id' => $flight->airline_id,
'flight_number' => $flight->flight_number,
'route_code' => 'A',
'dpt_airport_id' => $flight->dpt_airport_id,
'arr_airport_id' => $flight->arr_airport_id,
'days' => $flight->days,
]);

$this->assertFalse($this->flightSvc->isFlightDuplicate($flight_leg));

// Add both a route and leg
$flight_leg = Flight::factory()->create([
'airline_id' => $flight->airline_id,
'flight_number' => $flight->flight_number,
'route_code' => 'A',
'route_leg' => 1,
'airline_id' => $flight->airline_id,
'flight_number' => $flight->flight_number,
'route_code' => 'A',
'route_leg' => 1,
'dpt_airport_id' => $flight->dpt_airport_id,
'arr_airport_id' => $flight->arr_airport_id,
'days' => $flight->days,
]);

$this->assertFalse($this->flightSvc->isFlightDuplicate($flight_leg));
Expand Down

0 comments on commit b33ae8a

Please sign in to comment.