Skip to content

Commit dd0bdd6

Browse files
committed
feat: add relation lookup column type (tests)
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
1 parent 6daa30d commit dd0bdd6

2 files changed

Lines changed: 138 additions & 0 deletions

File tree

tests/integration/features/APIv1.feature

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,65 @@ Feature: APIv1
700700
When user "participant2" fetches relations for table "secret-orders"
701701
Then the reported status is "404"
702702

703+
@api1 @relation @relation-lookup
704+
Scenario: Create a relation lookup column and fetch relations for a table
705+
Given table "Products" with emoji "📦" exists for user "participant1" as "products"
706+
Then column "name" exists with following properties
707+
| type | text |
708+
| subtype | line |
709+
| mandatory | 0 |
710+
Then column "category" exists with following properties
711+
| type | text |
712+
| subtype | line |
713+
| mandatory | 0 |
714+
Then row exists with following values
715+
| name | Apple |
716+
| category | Fruit |
717+
Then row exists with following values
718+
| name | Banana |
719+
| category | Berry |
720+
Given table "Orders" with emoji "🛒" exists for user "participant1" as "orders"
721+
Then relation column "product" exists on table "orders" pointing to table "products" using label column "name"
722+
Then relation lookup column "product category" exists on table "orders" for relation column "product" using target column "category"
723+
When user "participant1" fetches relations for table "orders"
724+
Then the reported status is "200"
725+
Then the relations response contains 2 entries for column "product"
726+
Then the relations response for column "product" has an entry with label "Apple"
727+
Then the relations response for column "product" has an entry with label "Banana"
728+
Then the relations response contains 2 entries for column "product category"
729+
Then the relations response for column "product category" has an entry with value "Fruit"
730+
Then the relations response for column "product category" has an entry with value "Berry"
731+
732+
@api1 @relation @relation-lookup
733+
Scenario: Create a relation lookup column for a relation pointing to a view
734+
Given table "Fruits" with emoji "🍎" exists for user "participant1" as "fruits"
735+
Then column "name" exists with following properties
736+
| type | text |
737+
| subtype | line |
738+
| mandatory | 0 |
739+
Then column "color" exists with following properties
740+
| type | text |
741+
| subtype | line |
742+
| mandatory | 0 |
743+
Then row exists with following values
744+
| name | Apple |
745+
| color | Red |
746+
Then row exists with following values
747+
| name | Banana |
748+
| color | Yellow |
749+
When user "participant1" create view "Fruit View" with emoji "👁" for "fruits" as "fruit-view"
750+
Given table "Baskets" with emoji "🧺" exists for user "participant1" as "baskets"
751+
Then relation column "fruit" exists on table "baskets" pointing to view "fruit-view" using label column "name"
752+
Then relation lookup column "fruit color" exists on table "baskets" for relation column "fruit" using target column "color"
753+
When user "participant1" fetches relations for table "baskets"
754+
Then the reported status is "200"
755+
Then the relations response contains 2 entries for column "fruit"
756+
Then the relations response for column "fruit" has an entry with label "Apple"
757+
Then the relations response for column "fruit" has an entry with label "Banana"
758+
Then the relations response contains 2 entries for column "fruit color"
759+
Then the relations response for column "fruit color" has an entry with value "Red"
760+
Then the relations response for column "fruit color" has an entry with value "Yellow"
761+
703762
@api1 @columns @rows
704763
Scenario: Column technicalName is returned and dataByAlias maps alias to row values
705764
Given table "Alias test" with emoji "🔖" exists for user "participant1" as "base1"

tests/integration/features/bootstrap/FeatureContext.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,6 +2672,74 @@ public function createRelationColumnToView(string $title, string $tableName, str
26722672
$this->collectionManager->register($newColumn, 'column', $newColumn['id'], $title);
26732673
}
26742674

2675+
/**
2676+
* @Then relation lookup column :title exists on table :tableName for relation column :relationColumnName using target column :targetColumnName
2677+
*/
2678+
public function createRelationLookupColumn(string $title, string $tableName, string $relationColumnName, string $targetColumnName): void {
2679+
$relationColumnId = (int)$this->collectionManager->getByAlias('column', $relationColumnName)['id'];
2680+
$targetColumnId = (int)$this->collectionManager->getByAlias('column', $targetColumnName)['id'];
2681+
2682+
$props = [
2683+
'title' => $title,
2684+
'type' => 'relation_lookup',
2685+
'mandatory' => 0,
2686+
'customSettings' => [
2687+
'relationColumnId' => $relationColumnId,
2688+
'targetColumnId' => $targetColumnId,
2689+
],
2690+
];
2691+
2692+
$this->sendRequest(
2693+
'POST',
2694+
'/apps/tables/api/1/tables/' . $this->tableIds[$tableName] . '/columns',
2695+
$props
2696+
);
2697+
2698+
$newColumn = $this->getDataFromResponse($this->response);
2699+
$this->columnId = $newColumn['id'];
2700+
2701+
Assert::assertEquals(200, $this->response->getStatusCode());
2702+
Assert::assertEquals($title, $newColumn['title']);
2703+
Assert::assertEquals('relation_lookup', $newColumn['type']);
2704+
2705+
$this->collectionManager->register($newColumn, 'column', $newColumn['id'], $title);
2706+
}
2707+
2708+
/**
2709+
* @Then relation lookup column :title exists on table :tableName for relation column :relationColumnName using target column :targetColumnName added to view :viewName
2710+
*/
2711+
public function createRelationLookupColumnAddedToView(string $title, string $tableName, string $relationColumnName, string $targetColumnName, string $viewName): void {
2712+
$relationColumnId = (int)$this->collectionManager->getByAlias('column', $relationColumnName)['id'];
2713+
$targetColumnId = (int)$this->collectionManager->getByAlias('column', $targetColumnName)['id'];
2714+
$viewId = $this->viewIds[$viewName];
2715+
2716+
$props = [
2717+
'title' => $title,
2718+
'type' => 'relation_lookup',
2719+
'mandatory' => 0,
2720+
'selectedViewIds' => [$viewId],
2721+
'customSettings' => [
2722+
'relationColumnId' => $relationColumnId,
2723+
'targetColumnId' => $targetColumnId,
2724+
],
2725+
];
2726+
2727+
$this->sendRequest(
2728+
'POST',
2729+
'/apps/tables/api/1/tables/' . $this->tableIds[$tableName] . '/columns',
2730+
$props
2731+
);
2732+
2733+
$newColumn = $this->getDataFromResponse($this->response);
2734+
$this->columnId = $newColumn['id'];
2735+
2736+
Assert::assertEquals(200, $this->response->getStatusCode());
2737+
Assert::assertEquals($title, $newColumn['title']);
2738+
Assert::assertEquals('relation_lookup', $newColumn['type']);
2739+
2740+
$this->collectionManager->register($newColumn, 'column', $newColumn['id'], $title);
2741+
}
2742+
26752743
/**
26762744
* @When user :user fetches relations for table :tableName
26772745
*/
@@ -2721,6 +2789,17 @@ public function theRelationsResponseForColumnHasEntryWithLabel(string $columnNam
27212789
Assert::assertContains($label, $labels, 'Label "' . $label . '" not found in relations for column "' . $columnName . '"');
27222790
}
27232791

2792+
/**
2793+
* @Then the relations response for column :columnName has an entry with value :value
2794+
*/
2795+
public function theRelationsResponseForColumnHasEntryWithValue(string $columnName, string $value): void {
2796+
Assert::assertNotNull($this->relationsData, 'Relations response was not fetched or returned non-200');
2797+
$columnId = (int)$this->collectionManager->getByAlias('column', $columnName)['id'];
2798+
Assert::assertArrayHasKey($columnId, $this->relationsData, 'Column "' . $columnName . '" not found in relations response');
2799+
$values = array_column($this->relationsData[$columnId]['values'], 'value');
2800+
Assert::assertContains($value, $values, 'Value "' . $value . '" not found in relations for column "' . $columnName . '"');
2801+
}
2802+
27242803
/**
27252804
* @Then the relations response is empty
27262805
*/

0 commit comments

Comments
 (0)