-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for listing create with inventory data (#11)
* Add a test for listing create with inventory data * Add comments
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
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
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Api; | ||
|
||
use Tests\TestBase; | ||
use CloudForest\ApiClientPhp\Dto\ListingDto; | ||
use CloudForest\ApiClientPhp\Schema\StandardCompartment; | ||
use CloudForest\ApiClientPhp\Schema\StandardSubCompartment; | ||
|
||
final class ListingTest extends TestBase | ||
{ | ||
public function testCreate(): void | ||
{ | ||
// This is a short cut for now - log in directly using the stored user/pass | ||
// Eventually this should use an access token obtained from the OAuth exchange | ||
$access = $this->login(); | ||
$this->assertIsString($access); | ||
$this->assertNotEmpty($access); | ||
|
||
// Get the API client and set the access token from above. | ||
$api = $this->getCloudForestClient(); | ||
$api->setAccess($access); | ||
|
||
// Create an inventory structure | ||
$compartment = new StandardCompartment('1', 'PHPUnit Forest', '', '', '', []); | ||
$subcompartment = new StandardSubCompartment('2'); | ||
$subcompartment->name = 'PHPUnit Forest SubComp 1A'; | ||
$compartment->subCompartments = [$subcompartment]; | ||
|
||
// Create a listing and attach the inventory | ||
$listing = new ListingDto(); | ||
$listing->title = 'Test Listing from PHP Unit'; | ||
$listing->description = 'This is a test Listing from PHP Unit'; | ||
$listing->inventory = [$compartment]; | ||
|
||
// Use the API to create the listing in CloudForest | ||
$listingUuid = $api->listing->create($listing); | ||
$this->assertIsString($listingUuid); | ||
$this->assertNotEmpty($listingUuid); | ||
|
||
// Fetch the listing from CloudForest using its UUID only | ||
$newListing = $api->listing->findOne($listingUuid); | ||
|
||
// Verify the returned listing has the same data as above. | ||
$this->assertEquals('Test Listing from PHP Unit', $newListing['title']); | ||
$this->assertIsArray($newListing['inventory']); | ||
$inventory = $newListing['inventory']; | ||
$this->assertCount(1, $inventory); | ||
$compartment = $inventory[0]; | ||
$this->assertEquals('PHPUnit Forest', $compartment['name']); | ||
$this->assertIsArray($compartment['subCompartments']); | ||
$this->assertCount(1, $compartment['subCompartments']); | ||
$subcompartment = $compartment['subCompartments'][0]; | ||
$this->assertEquals('PHPUnit Forest SubComp 1A', $subcompartment['name']); | ||
} | ||
} |