Skip to content

Commit

Permalink
Add basic filter test for layout resource (#150)
Browse files Browse the repository at this point in the history
* Add basic filter test for layout resource

* Split basic filter test for layout

* Add order by reference tests

* Add tests to order layout by createdAt

* Add test to filter layout by uiComponent
  • Loading branch information
bofalke authored Oct 26, 2022
1 parent 602ec77 commit 7db786e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
10 changes: 7 additions & 3 deletions features/bootstrap/DoctrineContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,17 @@ public function thereIsARouteWithRedirects(string $firstPath, string $redirectTo
}

/**
* @Given /^there is a Layout(?: with the reference "([^"]*)"|)$/
* @Given /^there is a Layout(?: with the reference "([^"]+)")*[ and]*(?: with createdAt "([^"]+)")*(?: with the uiComponent "([^"]+)")*$/
*/
public function thereIsALayout(string $reference = 'no-reference'): void
public function thereIsALayout(string $reference = 'no-reference', ?string $createdAt = null, ?string $uiComponent = null): void
{
$layout = new Layout();
$layout->reference = $reference;
$this->timestampedHelper->persistTimestampedFields($layout, true);
$layout->uiComponent = $uiComponent;
if (null !== $createdAt) {
$layout->setCreatedAt(new \DateTimeImmutable($createdAt));
}
$this->timestampedHelper->persistTimestampedFields($layout, $createdAt === null);
$this->manager->persist($layout);
$this->manager->flush();
$this->restContext->resources['layout'] = $this->iriConverter->getIriFromResource($layout);
Expand Down
65 changes: 64 additions & 1 deletion features/main/layout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,67 @@ Feature: Layout resources
When I send a "DELETE" request to the resource "layout"
Then the response status code should be 204

# Todo: Order by and search filter tests needed to ensure it is implemented
@loginUser
Scenario: The layout resources can be filtered by reference
Given there is a Layout with the reference "primary"
And there is a Layout with the reference "secondary"
When I send a "GET" request to "/_/layouts"
Then the response status code should be 200
And the JSON node "hydra:member" should have "2" elements

@loginUser
Scenario: The layout resources can be filtered by reference
Given there is a Layout with the reference "primary"
And there is a Layout with the reference "secondary"
When I send a "GET" request to "/_/layouts?reference=primary"
Then the response status code should be 200
And the JSON node "hydra:member" should have "1" element

@loginUser
Scenario: The layout resources can be ordered ascending by reference
Given there is a Layout with the reference "1"
And there is a Layout with the reference "2"
When I send a "GET" request to "/_/layouts?order[reference]=asc"
Then the response status code should be 200
And the JSON node "hydra:member" should have "2" elements
And the JSON node "hydra:member[0].reference" should be equal to "1"
And the JSON node "hydra:member[1].reference" should be equal to "2"

@loginUser
Scenario: The layout resources can be ordered descending by reference
Given there is a Layout with the reference "1"
And there is a Layout with the reference "2"
When I send a "GET" request to "/_/layouts?order[reference]=desc"
Then the response status code should be 200
And the JSON node "hydra:member" should have "2" elements
And the JSON node "hydra:member[0].reference" should be equal to "2"
And the JSON node "hydra:member[1].reference" should be equal to "1"

@loginUser
Scenario: The layout resources can be ordered ascending by createdAt
Given there is a Layout with the reference "layout_1" and with createdAt "now"
And there is a Layout with the reference "layout_2" and with createdAt "+10 seconds"
When I send a "GET" request to "/_/layouts?order[createdAt]=asc"
Then the response status code should be 200
And the JSON node "hydra:member" should have "2" elements
And the JSON node "hydra:member[0].reference" should be equal to "layout_1"
And the JSON node "hydra:member[1].reference" should be equal to "layout_2"

@loginUser
Scenario: The layout resources can be ordered descending by createdAt
Given there is a Layout with the reference "layout_1" and with createdAt "now"
And there is a Layout with the reference "layout_2" and with createdAt "+10 seconds"
When I send a "GET" request to "/_/layouts?order[createdAt]=desc"
Then the response status code should be 200
And the JSON node "hydra:member" should have "2" elements
And the JSON node "hydra:member[0].reference" should be equal to "layout_2"
And the JSON node "hydra:member[1].reference" should be equal to "layout_1"

@loginUser
Scenario: The layout resources can be filtered by ui components
Given there is a Layout with the reference "primary" and with the uiComponent "PrimaryLayout"
And there is a Layout with the reference "secondary" and with the uiComponent "SecondaryLayout"
When I send a "GET" request to "/_/layouts?uiComponent=PrimaryLayout"
Then the response status code should be 200
And the JSON node "hydra:member" should have "1" elements
And the JSON node "hydra:member[0].reference" should be equal to "primary"

0 comments on commit 7db786e

Please sign in to comment.