Skip to content

Commit

Permalink
Merge branch 'feature/RO-289' into 'release/5.2'
Browse files Browse the repository at this point in the history
filters order

See merge request heseya/core!383
  • Loading branch information
bvlinsky committed Sep 20, 2023
2 parents 6368228 + 60e99b5 commit bb541c7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/Http/Controllers/FilterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ public function indexBySetsIds(FilterIndexRequest $request): JsonResource
}

return AttributeResource::collection(
Attribute::whereHas(
'productSets',
fn ($query) => $query->whereIn('product_set_id', $request->input('sets')),
)->orWhere('global', true)->with('options')->get()
Attribute::query()
->whereHas(
'productSets',
fn ($query) => $query->whereIn('product_set_id', $request->input('sets')),
)
->orWhere('global', true)->with('options')
->orderBy('order')
->get()
);
}
}
46 changes: 46 additions & 0 deletions tests/Feature/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,50 @@ public function testFilterWithSetsIds($user): void
'name' => 'Not in query single option',
]);
}

/**
* @dataProvider authProvider
*/
public function testFiltersAndAttributesSameOrder($user): void
{
$this->{$user}->givePermissionTo('attributes.show');

$productSet = ProductSet::factory()->create();
$productSet->attributes()->attach([
$attr1 = Attribute::factory()->create([
'name' => 'Test A',
'global' => 0,
'order' => 1,
'type' => 'number',
])->getKey(),
$attr2 = Attribute::factory()->create([
'global' => 0,
'name' => 'Test B',
'order' => 2,
'type' => 'date',
])->getKey(),
$attr3 = Attribute::factory()->create([
'global' => 0,
'order' => 0,
'name' => 'Test C',
'type' => 'date',
])->getKey(),
]);

$this
->actingAs($this->{$user})
->getJson('/attributes')
->assertJsonPath('data.0.id', $attr3)
->assertJsonPath('data.1.id', $attr1)
->assertJsonPath('data.2.id', $attr2);

$this
->actingAs($this->{$user})
->json('GET', '/filters', [
'sets' => [$productSet->getKey()],
])
->assertJsonPath('data.0.id', $attr3)
->assertJsonPath('data.1.id', $attr1)
->assertJsonPath('data.2.id', $attr2);
}
}

0 comments on commit bb541c7

Please sign in to comment.