Skip to content

Commit

Permalink
VAN-454 service.amadeus / search / implement non-stop filter - added …
Browse files Browse the repository at this point in the history
…non-stop filter
  • Loading branch information
marcuswinkler committed Nov 6, 2017
1 parent c02bb28 commit 7008693
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 1 deletion.
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
6 changes: 6 additions & 0 deletions src/Search/Model/AmadeusRequestTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ public function buildFareMasterRequestOptions(Request $request) : FareMasterPric
$options['cabinClass'] = $request->getFilterCabinClass();
}

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

if (!empty($coopCodes)) {
$options['corporateQualifier'] = FareMasterPricerTbSearch::CORPORATE_QUALIFIER_UNIFARE;
$options['corporateCodesUnifares'] = array_values($coopCodes);
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
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
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
21 changes: 21 additions & 0 deletions tests/unit/Search/Model/AmadeusRequestTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,25 @@ public function testItBuildsClientParams()
$this->assertEquals('password-length', $params->authParams->passwordLength);
$this->assertEquals('user-id', $params->authParams->userId);
}

/**
* Verify that it adds the required flight types if the stops filter is set
*/
public function testItSetsNonStopFilter()
{
$config = new \stdClass();
$config->search = new \stdClass();

$transformer = new AmadeusRequestTransformer($config);

$requestOptions = [
RequestFaker::OPT_NONSTOP_FILTER => true,
];
$request = RequestFaker::buildDefaultRequest($requestOptions);

$options = $transformer->buildFareMasterRequestOptions($request);

$this->assertInstanceOf(Client\RequestOptions\FareMasterPricerTbSearch::class, $options);
$this->assertEquals(['N'], $options->requestedFlightTypes);
}
}

0 comments on commit 7008693

Please sign in to comment.