Skip to content

Commit

Permalink
Merge pull request #179 from ember-nexus/github-issue/163
Browse files Browse the repository at this point in the history
Fix index endpoint to include elements which are directly owned or ar…
  • Loading branch information
Syndesi authored Oct 28, 2023
2 parents 5f66065 + 4329a90 commit 9d17363
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ ELASTIC_AUTH=ember-nexus-elasticsearch:9200
REDIS_AUTH=tcp://ember-nexus-redis?password=redis-password
RABBITMQ_AUTH=amqp://user:password@ember-nexus-rabbitmq:5672

REFERENCE_DATASET_VERSION=0.0.13
REFERENCE_DATASET_VERSION=0.0.16
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- Add explicit feature tests for parents, children and related endpoints to (not) include non-OWNS-relations, related
to #163.
### Changed
- Update readme and docker image labels.
- Increase reference dataset version to 0.0.16, skipped 0.0.15 and 0.0.14 due to erroneous releases.
### Fixed
- Fix index endpoint to include elements which are directly owned or are accessible. Fixes #163.

## 0.0.35 - 2023-10-26

Expand Down
19 changes: 14 additions & 5 deletions docs/api-endpoints/element/get-index/200-response-body.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
{
"type": "_PartialCollection",
"id": "/",
"totalNodes": 2,
"totalNodes": 3,
"links": {
"first": "/",
"previous": null,
"next": null,
"last": "/"
},
"nodes": [
{
"type": "Sphere",
"id": "56fda20c-b238-4034-b555-1df47c47e17a",
"data": {
"created": "2023-10-28T21:03:25+00:00",
"updated": "2023-10-28T21:03:25+00:00",
"name": "Tag"
}
},
{
"type": "Sphere",
"id": "7b80b203-2b82-40f5-accd-c7089fe6114e",
"data": {
"created": "2023-10-06T20:04:04+00:00",
"updated": "2023-10-06T20:04:04+00:00",
"created": "2023-10-28T21:03:25+00:00",
"updated": "2023-10-28T21:03:25+00:00",
"name": "Comment"
}
},
{
"type": "Token",
"id": "e3b81351-fe0c-4f8f-ad22-78b6157edde8",
"data": {
"created": "2023-10-06T20:04:04+00:00",
"updated": "2023-10-06T20:04:04+00:00",
"created": "2023-10-28T21:03:25+00:00",
"updated": "2023-10-28T21:03:25+00:00",
"note": "Token contains token only due to testing purposes."
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Users which immediately own a node, have full access to it.
| `2-01-03-03` | `User` | `🔵 GET /<Data>/children` | - | ✔️ 200 | yes | ✔️ implemented |
| `2-01-03-04` | `User` | `🔵 GET /<Data>/related` | - | ✔️ 200 | yes | ✔️ implemented |
| `2-01-03-05` | `User` | `🟢 POST /<Data>` | Valid request body. | ✔️ 201 | no | ✔️ implemented |
| `2-01-03-06` | `User` | `🟠 PUT /<Data>` | Valid request body. | ✔️ 204 | no | ❌ todo |
| `2-01-03-07` | `User` | `🟠 PATCH /<Data>` | Valid request body. | ✔️ 204 | no | ❌ todo |
| `2-01-03-08` | `User` | `🔴 DELETE /<Data>` | - | ✔️ ? | no | ❌ todo |
| `2-01-03-06` | `User` | `🟠 PUT /<Data>` | Valid request body. | ✔️ 204 | no | ✔️ implemented |
| `2-01-03-07` | `User` | `🟠 PATCH /<Data>` | Valid request body. | ✔️ 204 | no | ✔️ implemented |
| `2-01-03-08` | `User` | `🔴 DELETE /<Data>` | - | ✔️ 204 | no | ✔️ implemented |
| `2-01-03-20` | `User` | `🔵 GET /<Data>/file` | - | ✔️ 200 | yes | ❌ todo v0.2.0 |
| `2-01-03-21` | `User` | `🟢 POST /<Data>/file` | Valid request body. | ✔️ 201 | no | ❌ todo v0.2.0 |
| `2-01-03-22` | `User` | `🟠 PUT /<Data>/file` | Valid request body. | ✔️ 204 | no | ❌ todo v0.2.0 |
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Element/GetIndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getIndex(): Response
$cypherClient = $this->cypherEntityManager->getClient();
$res = $cypherClient->runStatement(Statement::create(
"MATCH (user:User {id: \$userId})\n".
"MATCH (user)-[:PART_OF_GROUP*0..]->()-[:OWNS]->(element)\n".
"MATCH (user)-[:OWNS|IS_IN_GROUP|HAS_READ_ACCESS]->(element)\n".
"RETURN element.id\n".
"ORDER BY element.id\n".
"SKIP \$skip\n".
Expand Down
2 changes: 1 addition & 1 deletion tests/ExampleGenerationController/Element/GetIndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GetIndexTest extends BaseRequestTestCase
public function testGetIndexSuccess(): void
{
$response = $this->runGetRequest('/', self::TOKEN);
$this->assertIsCollectionResponse($response, 2);
$this->assertIsCollectionResponse($response, 3);
$documentationHeadersPath = 'docs/api-endpoints/element/get-index/200-response-header.txt';
$documentationBodyPath = 'docs/api-endpoints/element/get-index/200-response-body.json';
$this->assertHeadersInDocumentationAreIdenticalToHeadersFromRequest(
Expand Down
110 changes: 110 additions & 0 deletions tests/FeatureTests/General/OwnershipModel/OwnershipModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace App\tests\FeatureTests\General\OwnershipModel;

use App\Tests\FeatureTests\BaseRequestTestCase;

class OwnershipModelTest extends BaseRequestTestCase
{
public const TOKEN = 'secret-token:INirKZbnZETk6hLD86rfrL';

public const USER_UUID = 'e5d6c437-e13c-4fe8-85be-fc12e164eb17';
public const GROUP_1_UUID = '3d7bf35e-0188-467f-8cb4-6741a1741429';
public const GROUP_2_UUID = 'dbc96de1-0cb7-4f20-9cfe-d23740af32b0';
public const DATA_UUID = 'b66de74d-791a-4157-a632-4fdf066e80f2';
public const TOKEN_UUID = 'fdc9fc1f-1436-437b-a46d-358dbbb086d1';

public function testIndex(): void
{
$response = $this->runGetRequest('/', self::TOKEN);
$this->assertIsCollectionResponse($response, 2, 0);

$body = $this->getBody($response);
$this->assertSame($body['nodes'][0]['id'], self::GROUP_1_UUID);
$this->assertSame($body['nodes'][1]['id'], self::TOKEN_UUID);
}

public function testUserChildren(): void
{
$response = $this->runGetRequest(sprintf('/%s/children', self::USER_UUID), self::TOKEN);
$this->assertIsCollectionResponse($response, 1, 1);

$body = $this->getBody($response);
$this->assertSame($body['nodes'][0]['id'], self::TOKEN_UUID);
}

public function testUserRelated(): void
{
$response = $this->runGetRequest(sprintf('/%s/related', self::USER_UUID), self::TOKEN);
$this->assertIsCollectionResponse($response, 2, 2);

$body = $this->getBody($response);
$this->assertSame($body['nodes'][0]['id'], self::GROUP_1_UUID);
$this->assertSame($body['nodes'][1]['id'], self::TOKEN_UUID);
}

public function testGroup1Children(): void
{
$response = $this->runGetRequest(sprintf('/%s/children', self::GROUP_1_UUID), self::TOKEN);
$this->assertIsCollectionResponse($response, 0, 0);
}

public function testGroup1Parents(): void
{
$response = $this->runGetRequest(sprintf('/%s/parents', self::GROUP_1_UUID), self::TOKEN);
$this->assertIsCollectionResponse($response, 0, 0);
}

public function testGroup1Related(): void
{
$response = $this->runGetRequest(sprintf('/%s/related', self::GROUP_1_UUID), self::TOKEN);
$this->assertIsCollectionResponse($response, 2, 2);

$body = $this->getBody($response);
$this->assertSame($body['nodes'][0]['id'], self::GROUP_2_UUID);
$this->assertSame($body['nodes'][1]['id'], self::USER_UUID);
}

public function testGroup2Children(): void
{
$response = $this->runGetRequest(sprintf('/%s/children', self::GROUP_2_UUID), self::TOKEN);
$this->assertIsCollectionResponse($response, 1, 1);

$body = $this->getBody($response);
$this->assertSame($body['nodes'][0]['id'], self::DATA_UUID);
}

public function testGroup2Parents(): void
{
$response = $this->runGetRequest(sprintf('/%s/parents', self::GROUP_2_UUID), self::TOKEN);
$this->assertIsCollectionResponse($response, 0, 0);
}

public function testGroup2Related(): void
{
$response = $this->runGetRequest(sprintf('/%s/related', self::GROUP_2_UUID), self::TOKEN);
$this->assertIsCollectionResponse($response, 2, 2);

$body = $this->getBody($response);
$this->assertSame($body['nodes'][0]['id'], self::GROUP_1_UUID);
$this->assertSame($body['nodes'][1]['id'], self::DATA_UUID);
}

public function testDataParents(): void
{
$response = $this->runGetRequest(sprintf('/%s/parents', self::DATA_UUID), self::TOKEN);
$this->assertIsCollectionResponse($response, 1, 1);

$body = $this->getBody($response);
$this->assertSame($body['nodes'][0]['id'], self::GROUP_2_UUID);
}

public function testDataRelated(): void
{
$response = $this->runGetRequest(sprintf('/%s/related', self::DATA_UUID), self::TOKEN);
$this->assertIsCollectionResponse($response, 1, 1);

$body = $this->getBody($response);
$this->assertSame($body['nodes'][0]['id'], self::GROUP_2_UUID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,41 +108,38 @@ public function test2010305(): void
*/
public function test2010306(): void
{
$this->markTestSkipped();
$response = $this->runPutRequest(
sprintf('/%s', self::DATA),
self::TOKEN,
[
'name' => 'I shall not be updated.',
'name' => 'I shall be updated.',
]
);
$this->assertIsProblemResponse($response, 404);
$this->assertNoContentResponse($response);
}

/**
* @description test 2-01-03-07
*/
public function test2010307(): void
{
$this->markTestSkipped();
$response = $this->runPatchRequest(
sprintf('/%s', self::DATA),
self::TOKEN,
[
'name' => 'I shall not be updated.',
'name' => 'I shall be updated, again! :P',
]
);
$this->assertIsProblemResponse($response, 404);
$this->assertNoContentResponse($response);
}

/**
* @description test 2-01-03-08
*/
public function test2010308(): void
{
$this->markTestSkipped();
$response = $this->runDeleteRequest(sprintf('/%s', self::DATA), self::TOKEN);
$this->assertIsProblemResponse($response, 404);
$this->assertIsDeletedResponse($response);
}

/**
Expand Down Expand Up @@ -202,6 +199,8 @@ public function test2010323(): void

/**
* @description test 2-01-03-24
*
* @todo refactor in v0.2.0 with actual request required
*/
public function test2010324(): void
{
Expand Down

0 comments on commit 9d17363

Please sign in to comment.