Skip to content

Commit

Permalink
Merge pull request amabnl#13 in FLIGHT/service.amadeus from feature/V…
Browse files Browse the repository at this point in the history
…AN-454-service.amadeus-search-implement to master

* commit '70086939ed82ccbaa5fc53ae5f5443ef5c078672':
  VAN-454 service.amadeus / search / implement non-stop filter - added non-stop filter
  VAN-454 service.amadeus / search / implement non-stop filter - fixed bug airline-filter bug
  • Loading branch information
H0m3rS1mp50n committed Nov 7, 2017
2 parents 0994902 + 7008693 commit f473262
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 205 deletions.
1 change: 1 addition & 0 deletions docs/api.apib
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ format.
+ `filter-cabin-class` (array, optional)
+ Y, F, C (enum) - request with this cabin class(es)
+ `filter-airline`: AB (array, optional) - list of airline IATA codes
+ `filter-stops`: 0 (number, optional) - if set to zero, will only return non-stop flights
+ `legs` (array, fixed-type, required)
+ (object)
+ `departure`: BER (string, required) - name of departure IATA airport code
Expand Down
28 changes: 17 additions & 11 deletions src/Search/Model/AmadeusRequestTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Flight\Service\Amadeus\Search\Model;

use Amadeus\Client;
use Amadeus\Client\RequestOptions\FareMasterPricerTbSearch;
use Flight\SearchRequestMapping\Entity\BusinessCase;
use Flight\SearchRequestMapping\Entity\Leg;
use Flight\SearchRequestMapping\Entity\Request;
Expand Down Expand Up @@ -75,9 +76,9 @@ public function buildClientParams(BusinessCase $businessCase, LoggerInterface $l
*
* @param Request $request
*
* @return Client\RequestOptions\FareMasterPricerTbSearch
* @return FareMasterPricerTbSearch
*/
public function buildFareMasterRequestOptions(Request $request) : Client\RequestOptions\FareMasterPricerTbSearch
public function buildFareMasterRequestOptions(Request $request) : FareMasterPricerTbSearch
{
/** @var BusinessCase $businessCase */
$businessCase = $request->getBusinessCases()->first()->first();
Expand All @@ -102,26 +103,31 @@ public function buildFareMasterRequestOptions(Request $request) : Client\Request
'flightOptions' => $this->buildFlightOptions($businessCase, $coopCodes)
];

if (!empty($excludedAirlines)) {
$options['airlineOptions'][Client\RequestOptions\FareMasterPricerTbSearch::AIRLINEOPT_EXCLUDED] = $excludedAirlines;
}

if (!empty($request->getFilterAirline())) {
$options['airlineOptions'][Client\RequestOptions\FareMasterPricerTbSearch::AIRLINEOPT_MANDATORY ] = $request->getFilterAirline();
$options['airlineOptions'][FareMasterPricerTbSearch::AIRLINEOPT_MANDATORY] =
array_diff($request->getFilterAirline(), $excludedAirlines);
} elseif (!empty($excludedAirlines)) {
$options['airlineOptions'][FareMasterPricerTbSearch::AIRLINEOPT_EXCLUDED] = $excludedAirlines;
}

if (!empty(($request->getFilterCabinClass()))) {
$options['cabinOption'] = Client\RequestOptions\FareMasterPricerTbSearch::CABINOPT_MANDATORY;
$options['cabinOption'] = FareMasterPricerTbSearch::CABINOPT_MANDATORY;
$options['cabinClass'] = $request->getFilterCabinClass();
}

if ($request->getFilterStops() === 0) {
$options['requestedFlightTypes'] = [
FareMasterPricerTbSearch::FLIGHTTYPE_NONSTOP,
];
}

if (!empty($coopCodes)) {
$options['corporateQualifier'] = Client\RequestOptions\FareMasterPricerTbSearch::CORPORATE_QUALIFIER_UNIFARE;
$options['corporateQualifier'] = FareMasterPricerTbSearch::CORPORATE_QUALIFIER_UNIFARE;
$options['corporateCodesUnifares'] = array_values($coopCodes);

}

return new Client\RequestOptions\FareMasterPricerTbSearch($options);
return new FareMasterPricerTbSearch($options);
}

/**
Expand Down Expand Up @@ -252,7 +258,7 @@ protected function buildFlightOptions(BusinessCase $businessCase, array $coopCod

//removes CorpUnifare option if no CoopCode is set in config
if (empty($coopCodes)) {
$pricingOptions = array_diff($pricingOptions, [Client\RequestOptions\FareMasterPricerTbSearch::FLIGHTOPT_CORPORATE_UNIFARES]);
$pricingOptions = array_diff($pricingOptions, [FareMasterPricerTbSearch::FLIGHTOPT_CORPORATE_UNIFARES]);
}

if ($businessCase->getOptions()->isOvernight()) {
Expand Down
2 changes: 2 additions & 0 deletions src/Search/Request/Validator/AmadeusRequestValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ function ($element) {
}
);

$validator->optional('filter-stops')->integer(true);

$validator->required('legs')->each(
function (Validator $validator) {
$validator->required('departure');
Expand Down
82 changes: 82 additions & 0 deletions tests/_data/requests/valid-request-with-filters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"search-hash": "",
"flight-hash": "",
"agent": "fluege.de",
"departure": [
"BER"
],
"depart-at": [
1514725420
],
"is-flexible-date": [
],
"arrival": [
"LON"
],
"adults": 2,
"children": 0,
"infants": 0,
"is-synthetic": false,
"filter-airline": [
"LH", "AB", "4U", "EJ"
],
"filter-cabin-class": [
"Y", "F"
],
"filter-arrive-before": [

],
"filter-depart-after": [

],
"filter-duration": [

],
"filter-free-beggage": false,
"filter-identical-origin": false,
"filter-airports": [

],
"filter-payment-method": [

],
"filter-price-min": "",
"filter-price-max": "",
"filter-stops": 0,
"page": 1,
"legs": [
{
"departure": "BER",
"arrival": "LON",
"depart-at": 1514725420,
"is-flexible-date": false,
"filter": [

]
}
],
"business-cases": [
[
{
"content-provider": "amadeus",
"type": "one-way",
"fare-type": "net",
"options": {
"is-one-way-combination": true,
"is-overnight": false,
"is-area-search": false,
"is-benchmark": false,
"result-limit": 1
},
"authentication": {
"office-id": "LEJL128AC",
"user-id": "WSTBDUFI",
"password-data": "dkhBM1J5VTU=",
"password-length": 8,
"duty-code": "SU",
"organization-id": "NMC-GERMAN"
}
}
]
]
}
2 changes: 1 addition & 1 deletion tests/_data/requests/wrong-filter-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
],
"filter-price-min": "",
"filter-price-max": "",
"filter-stops": null,
"filter-stops": true,
"page": 1,
"legs": [
{
Expand Down
9 changes: 9 additions & 0 deletions tests/api/Search/RequestErrorHandling/CheckFilterCept.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
]
]]
);
$I->canSeeResponseContainsJson(
['filter-stops' => [
[
'code' => ValidationException::INTERNAL_ERROR_CODE,
'message' => 'INVALID OR MISSING REQUEST PARAM - filter-stops must be an integer',
'status' => 400
]
]]
);

$I->canSeeResponseContainsJson(
[
Expand Down
24 changes: 24 additions & 0 deletions tests/api/Search/ValidWithFiltersCept.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/** @var \Codeception\Scenario $scenario */
$I = new ApiTester($scenario);
$I->wantTo('see an response that matches the response schema even if I set all supported filters');
$I->sendPOST(
'/flight-search/',
file_get_contents(codecept_data_dir('requests/valid-request-with-filters.json'))
);
$I->seeResponseCodeIs(200);
$I->seeHttpHeader('content-type', 'application/hal+json');

$response = $I->grabResponse();

$validator = new \JsonSchema\Validator();
$validator->validate(
$response,
(object)[
'$ref' => 'file://' . codecept_data_dir('schema/response-schema.json')
]
);

$I->expect($validator->isValid());

$I->seeResponseHasLinkToSelf('/flight-search/');
4 changes: 4 additions & 0 deletions tests/unit/Helper/RequestFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class RequestFaker
const OPT_FLEXIBLE_LEG_DATES = 'flexibleDate';
const OPT_AIRLINE_FILTER = 'airlineFilter';
const OPT_CABIN_CLASS_FILTER = 'cabinClassFilter';
const OPT_NONSTOP_FILTER = 'nonstopFilter';
const OPT_AREA_SEARCH = 'areaSearch';
const OPT_PAX = 'pax';
const OPT_RESULT_LIMIT = 'resultLimit';
Expand All @@ -49,6 +50,9 @@ public static function getFakeRequest(array $options) : Request
if (isset($options[self::OPT_CABIN_CLASS_FILTER])) {
$request->setFilterCabinClass($options[self::OPT_CABIN_CLASS_FILTER]);
}
if (isset($options[self::OPT_NONSTOP_FILTER])) {
$request->setFilterStops(0);
}
$request->setBusinessCases(new ArrayCollection());
$request->getBusinessCases()->add(new ArrayCollection());
$request->getBusinessCases()->first()->add(self::buildBusinessCase($options));
Expand Down
Loading

0 comments on commit f473262

Please sign in to comment.