-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add availabilities to the REST API client (#20)
* add support for the availability endpoints
- Loading branch information
1 parent
c63dcbe
commit bc98a29
Showing
9 changed files
with
688 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php namespace Meplato\Store2\Availabilities\Tests; | ||
// Copyright (c) 2015 Meplato GmbH, Switzerland. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed under the License | ||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
// or implied. See the License for the specific language governing permissions and limitations under | ||
// the License. | ||
|
||
/** | ||
* Base test for the Availabilities service. | ||
*/ | ||
abstract class BaseTest extends \Meplato\Store2\Tests\BaseTest | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
public function getService() | ||
{ | ||
$client = $this->getHttpClient(); | ||
$this->service = new \Meplato\Store2\Availabilities\Service($client); | ||
$this->service->setBaseURL("http://store2.go/api/v2"); | ||
return $this->service; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php namespace Meplato\Store2\Availabilities\Tests; | ||
// Copyright (c) 2015 Meplato GmbH, Switzerland. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed under the License | ||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
// or implied. See the License for the specific language governing permissions and limitations under | ||
// the License. | ||
|
||
use Meplato\Store2\HttpClient; | ||
use Meplato\Store2\Availabilities\Service; | ||
|
||
/** | ||
* Tests deleting availabilities. | ||
*/ | ||
class DeleteTest extends BaseTest | ||
{ | ||
/** | ||
* Tests a successful call to delete availabilities. | ||
* | ||
* @group availabilities | ||
* @group availabilities.delete | ||
*/ | ||
public function testDelete() | ||
{ | ||
|
||
$service = $this->getService(); | ||
$this->mockResponseFromFile('availabilities.delete.success'); | ||
$response = $service->delete()->spn('1234')->execute(); | ||
|
||
$this->assertIsArray($response); | ||
$this->assertArrayHasKey('kind', $response); | ||
$this->assertEquals('store#availabilities/deleteResponse', $response['kind']); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php namespace Meplato\Store2\Availabilities\Tests; | ||
// Copyright (c) 2015 Meplato GmbH, Switzerland. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed under the License | ||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
// or implied. See the License for the specific language governing permissions and limitations under | ||
// the License. | ||
|
||
use Meplato\Store2\HttpClient; | ||
use Meplato\Store2\Availabilities\Service; | ||
|
||
/** | ||
* Tests retrieving of availabilities. | ||
*/ | ||
class GetTest extends BaseTest | ||
{ | ||
/** | ||
* Tests a successful call to retrieve availabilities. | ||
* | ||
* @group availabilities | ||
* @group availabilities.get | ||
*/ | ||
public function testGet() | ||
{ | ||
$service = $this->getService(); | ||
$this->mockResponseFromFile('availabilities.get.success'); | ||
$response = $service->get()->spn("1234")->execute(); | ||
$this->assertIsArray($response); | ||
$this->assertArrayHasKey('kind', $response); | ||
$this->assertEquals('store#availabilities/getResponse', $response['kind']); | ||
|
||
$this->assertArrayHasKey('items', $response); | ||
$this->assertIsArray($response['items']); | ||
$this->assertCount(3, $response['items']); | ||
$this->assertEquals('1234', $response['items'][0]['spn']); | ||
} | ||
|
||
/** | ||
* Test what happens when availabilities are not found. | ||
* | ||
* @group availabilities | ||
* @group availabilities.get | ||
*/ | ||
public function testGetNotFound() | ||
{ | ||
$service = $this->getService(); | ||
$this->mockResponseFromFile('availabilities.get.not_found'); | ||
|
||
$response = $service->get()->spn('no-such-product')->execute(); | ||
|
||
$this->assertIsArray($response); | ||
$this->assertArrayHasKey('kind', $response); | ||
$this->assertEquals('store#availabilities/getResponse', $response['kind']); | ||
|
||
$this->assertArrayHasKey('items', $response); | ||
$this->assertNull($response['items']); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php namespace Meplato\Store2\Availabilities\Tests; | ||
// Copyright (c) 2015 Meplato GmbH, Switzerland. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed under the License | ||
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
// or implied. See the License for the specific language governing permissions and limitations under | ||
// the License. | ||
|
||
use Meplato\Store2\HttpClient; | ||
use Meplato\Store2\Availabilities\Service; | ||
|
||
class UpsertTest extends BaseTest | ||
{ | ||
/** | ||
* Tests a successful call to upsert of availabilities. | ||
* | ||
* @group availabilities | ||
* @group availabilities.upsert | ||
*/ | ||
public function testUpsert() | ||
{ | ||
$availability = [ | ||
'Message'=> "not in stock", | ||
'Quantity'=> 0, | ||
'Region'=> "AQ", | ||
'Updated'=> "Q1/2024", | ||
'ZipCode'=> "1234", | ||
]; | ||
|
||
$service = $this->getService(); | ||
|
||
// Upsert availabilities, i.e. either create or update. | ||
$this->mockResponseFromFile('availabilities.upsert.success'); | ||
$response = $service->upsert()->spn(1234)->availability($availability)->execute(); | ||
$this->assertIsArray($response); | ||
$this->assertArrayHasKey('kind', $response); | ||
$this->assertEquals('store#availabilities/upsertResponse', $response['kind']); | ||
$this->assertArrayHasKey('link', $response); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
HTTP/1.1 202 OK | ||
Cache-Control: private, no-cache | ||
Content-Type: application/json; charset=utf-8 | ||
Last-Modified: Tue, 31 Mar 2015 14:18:15 GMT | ||
P3p: CP="This is not a P3P policy!" | ||
Vary: Cookie | ||
X-Content-Type-Options: nosniff | ||
X-Frame-Options: SAMEORIGIN | ||
X-Ua-Compatible: IE=edge | ||
X-Xss-Protection: 1; mode=block | ||
Date: Tue, 25 Mar 2024 14:18:15 GMT | ||
|
||
{ | ||
"kind": "store#availabilities/deleteResponse" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
HTTP/1.1 200 | ||
Cache-Control: private, no-cache | ||
Content-Type: application/json; charset=utf-8 | ||
Last-Modified: Tue, 31 Mar 2015 14:15:25 GMT | ||
P3p: CP="This is not a P3P policy!" | ||
Vary: Cookie | ||
X-Content-Type-Options: nosniff | ||
X-Frame-Options: SAMEORIGIN | ||
X-Ua-Compatible: IE=edge | ||
X-Xss-Protection: 1; mode=block | ||
Date: Tue, 31 Mar 2015 14:15:25 GMT | ||
|
||
{ | ||
"kind": "store#availabilities/getResponse", | ||
"items": null, | ||
"Error": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
HTTP/1.1 200 OK | ||
Cache-Control: private, no-cache | ||
Content-Type: application/json; charset=utf-8 | ||
Last-Modified: Tue, 31 Mar 2015 14:18:15 GMT | ||
P3p: CP="This is not a P3P policy!" | ||
Vary: Cookie | ||
X-Content-Type-Options: nosniff | ||
X-Frame-Options: SAMEORIGIN | ||
X-Ua-Compatible: IE=edge | ||
X-Xss-Protection: 1; mode=block | ||
Date: Tue, 25 Mar 2024 14:18:15 GMT | ||
|
||
{ | ||
"kind": "store#availabilities/getResponse", | ||
"Error": null, | ||
"items": [ | ||
{ | ||
"message": "in stock", | ||
"mpcc": "meplato", | ||
"quantity": 15.3, | ||
"region": "UK", | ||
"spn": "1234", | ||
"updated": "Q4/2022", | ||
"zipCode": "04109" | ||
}, | ||
{ | ||
"message": "in stock", | ||
"mpcc": "meplato", | ||
"quantity": 35.0, | ||
"region": "DK", | ||
"spn": "1234", | ||
"updated": "Q4/2022", | ||
"zipCode": "05109" | ||
}, | ||
{ | ||
"message": "in stock", | ||
"mpcc": "meplato", | ||
"quantity": 20.4, | ||
"region": "DE", | ||
"spn": "1234", | ||
"updated": "Q4/2022", | ||
"zipCode": "06109" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
HTTP/1.1 202 OK | ||
Cache-Control: private, no-cache | ||
Content-Type: application/json; charset=utf-8 | ||
Last-Modified: Tue, 31 Mar 2015 14:18:15 GMT | ||
P3p: CP="This is not a P3P policy!" | ||
Vary: Cookie | ||
X-Content-Type-Options: nosniff | ||
X-Frame-Options: SAMEORIGIN | ||
X-Ua-Compatible: IE=edge | ||
X-Xss-Protection: 1; mode=block | ||
Date: Tue, 25 Mar 2024 14:18:15 GMT | ||
|
||
{ | ||
"kind": "store#availabilities/upsertResponse", | ||
"link": "string" | ||
} |