Skip to content

Commit

Permalink
[PLA-1443] Add new params GetListings (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner authored Mar 11, 2024
1 parent 56f7def commit 9f71ddb
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
22 changes: 21 additions & 1 deletion src/GraphQL/Queries/GetListingsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ public function args(): array
'type' => GraphQL::type('MultiTokenIdInput'),
'description' => __('enjin-platform-marketplace::type.marketplace_listing.field.takeAssetId'),
],
'collectionIds' => [
'type' => GraphQL::type('[BigInt]'),
'description' => __('enjin-platform::input_type.multi_token_id.field.collectionId'),
'rules' => [new MinBigInt(), new MaxBigInt(Hex::MAX_UINT128)],
],
'states' => [
'type' => GraphQL::type('[ListingStateEnum!]'),
'description' => __('enjin-platform-marketplace::type.listing_state.description'),
],
]);
}

Expand Down Expand Up @@ -110,7 +119,18 @@ public function resolve(
'take_collection_chain_id' => Arr::get($takeAsset, 'collectionId'),
'take_token_chain_id' => $this->encodeTokenId(Arr::get($args, 'takeAssetId')),
])
)->cursorPaginateWithTotalDesc('marketplace_listings.id', $args['first']);
)->when(
$collectionId = Arr::get($args, 'collectionIds'),
fn ($query) => $query->where(
fn ($subquery) => $subquery->whereIn('make_collection_chain_id', $collectionId)
->orWhereIn('take_collection_chain_id', $collectionId)
)
)
->when(
$states = Arr::get($args, 'states'),
fn ($query) => $query->whereHas('state', fn ($query) => $query->whereIn('state', $states))
)
->cursorPaginateWithTotalDesc('marketplace_listings.id', $args['first']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/GraphQL/Mutations/CancelListingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CancelListingTest extends TestCaseGraphQL

public function test_it_can_cancel_listing(): void
{
$listing = $this->createListing();
$listing = $this->createListing(null, 'ACTIVE');
$response = $this->graphql(
$this->method,
$params = ['listingId' => $listing->listing_chain_id]
Expand Down
5 changes: 4 additions & 1 deletion tests/Feature/GraphQL/Mutations/PlaceBidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public function test_it_can_place_bid(): void
$listing = $this->createListing();
$response = $this->graphql(
$this->method,
$params = ['listingId' => $listing->listing_chain_id, 'price' => fake()->numberBetween(1, 1000)]
$params = [
'listingId' => $listing->listing_chain_id,
'price' => fake()->numberBetween(1, $listing->price + 1000),
]
);
$this->assertEquals(
$response['encodedData'],
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/GraphQL/Queries/GetListingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ public function test_it_can_get_listings(): void
['takeAssetId' => ['collectionId' => $listing->take_collection_chain_id, 'tokenId' => ['integer' => $listing->take_token_chain_id]]]
);
$this->assertNotEmpty($response['totalCount']);


$response = $this->graphql(
$this->method,
['collectionIds' => [$listing->make_collection_chain_id]],
);
$this->assertNotEmpty($response['totalCount']);

$response = $this->graphql(
$this->method,
['states' => [$listing->states->first()->state]],
);
$this->assertNotEmpty($response['totalCount']);
}

public function test_it_will_fail_with_invalid_parameter_ids(): void
Expand Down
4 changes: 4 additions & 0 deletions tests/Feature/GraphQL/Resources/GetListings.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ query GetListings(
$account: String
$makeAssetId: MultiTokenIdInput
$takeAssetId: MultiTokenIdInput
$collectionIds: [BigInt]
$states: [ListingStateEnum!]
) {
GetListings(
ids: $ids
listingIds: $listingIds
account: $account
makeAssetId: $makeAssetId
takeAssetId: $takeAssetId
collectionIds: $collectionIds
states: $states
) {
totalCount
pageInfo {
Expand Down
17 changes: 11 additions & 6 deletions tests/Feature/GraphQL/TestCaseGraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Enjin\Platform\CoreServiceProvider;
use Enjin\Platform\Marketplace\Enums\ListingState;
use Enjin\Platform\Marketplace\MarketplaceServiceProvider;
use Enjin\Platform\MarketPlace\Models\MarketplaceBid;
use Enjin\Platform\Marketplace\Models\MarketplaceListing;
Expand Down Expand Up @@ -97,7 +98,7 @@ public function graphql(string $query, array $arguments = [], ?bool $expectError
/**
* Seed marketplace listing related data.
*/
protected function seedRelatedData(MarketplaceListing $listing): void
protected function seedRelatedData(MarketplaceListing $listing, ?string $state): void
{
LaravelCollection::updateOrCreate(
['collection_chain_id' => $listing->make_collection_chain_id],
Expand Down Expand Up @@ -133,22 +134,26 @@ protected function seedRelatedData(MarketplaceListing $listing): void

$listing->setRelation(
'states',
MarketplaceState::factory(fake()->numberBetween(1, 1))->make(['marketplace_listing_id' => $listing->id])
MarketplaceState::factory(fake()->numberBetween(1, 1))
->create([
'marketplace_listing_id' => $listing->id,
'state' => $state ?? ListingState::caseNamesAsCollection()->random(),
])
);
}

/**
* Create listing.
*/
protected function createListing(?int $count = null): Collection | MarketplaceListing
protected function createListing(?int $count = null, ?string $state = 'ACTIVE'): Collection | MarketplaceListing
{
$listing = MarketplaceListing::factory($count)->create(['seller_wallet_id' => $this->wallet->id]);
if ($listing instanceof MarketplaceListing) {
$this->seedRelatedData($listing);
$this->seedRelatedData($listing, $state);
} else {
$listing->each(
function (MarketplaceListing $listing) {
$this->seedRelatedData($listing);
function (MarketplaceListing $listing) use ($state) {
$this->seedRelatedData($listing, $state);
}
);
}
Expand Down

0 comments on commit 9f71ddb

Please sign in to comment.