diff --git a/app/Services/FlightService.php b/app/Services/FlightService.php index 7f13f6ddd..6a8c5ecdd 100644 --- a/app/Services/FlightService.php +++ b/app/Services/FlightService.php @@ -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); diff --git a/tests/FlightTest.php b/tests/FlightTest.php index a18d415dd..870cac945 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -45,10 +45,13 @@ 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)); @@ -56,29 +59,38 @@ public function testDuplicateFlight() // 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));