Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Modules/ListingModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,28 @@ public function findOne(string $listingUuid)
$data = $this->getDataAsArray($content);
return $data;
}

/**
* Find all the listings belonging to the user associated with the JWT.
* @return mixed The listing data as an associative array.
*/
public function findOwn()
{
try {
$response = $this->client->request(
'GET',
'/api/listings/own',
[
'headers' => $this->getHeadersWithAccessBearer(),
]
);
} catch (GuzzleException $e) {
throw $e;
}

$body = $response->getBody()->getContents();
$content = json_decode($body, true);
$data = $this->getDataAsArray($content);
return $data;
}
}
37 changes: 37 additions & 0 deletions tests/api/ListingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,41 @@ public function testCreate(): void
$this->assertEquals('1976', $inventory['plantingYear']);
$this->assertEquals('1267.13', $inventory['volumePerSubcompartment']);
}

// A test to lookup all of a user's listings and then get more information
// about one of them.
public function testLookup(): 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);

// Get all of the user's listings
$ownListings = $api->listing->findOwn();

// We don't know how many users there will be are because the marketplace
// test server is out of our control here. But there should be at least
// one because we created one above.
$this->assertGreaterThan(1, count($ownListings));

// Get the first listing
$first = $ownListings[0];
$title = $first['title'];
$state = $first['state'];
$this->assertIsString($title);
$this->assertIsString($state);

// Verify that we can also get this listing by its UUID
$uuid = $first['id'];
$listing = $api->listing->findOne($uuid);
$this->assertIsArray($listing);
$this->assertEquals($listing['title'], $title);
$this->assertEquals($listing['state'], $state);
}
}