Updated tests
This commit is contained in:
parent
f1ec1b2a05
commit
a6c62c95b0
|
@ -210,7 +210,7 @@ App::get('/v1/database/collections')
|
|||
}
|
||||
|
||||
$response->dynamic(new Document([
|
||||
'collections' => $dbForInternal->find('collections', $queries, $limit, $offset, ['_id'], [$orderType]),
|
||||
'collections' => $dbForInternal->find('collections', $queries, $limit, $offset, [], [$orderType], $afterCollection ?? null),
|
||||
'sum' => $dbForInternal->count('collections', $queries, APP_LIMIT_COUNT),
|
||||
]), Response::MODEL_COLLECTION_LIST);
|
||||
});
|
||||
|
@ -1065,24 +1065,18 @@ App::delete('/v1/database/collections/:collectionId/indexes/:indexId')
|
|||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
/** @var Document[] $indexes */
|
||||
$indexes = $collection->getAttribute('indexes');
|
||||
$index = $dbForInternal->getDocument('indexes', $collectionId.'_'.$indexId);
|
||||
|
||||
// find attribute in collection
|
||||
$index= null;
|
||||
foreach ($indexes as $i) {
|
||||
if ($i->getId() === $indexId) {
|
||||
$index = $i->setAttribute('$collection', $collectionId); // set the collectionId
|
||||
break; // break once index is found
|
||||
}
|
||||
}
|
||||
|
||||
if (\is_null($index)) {
|
||||
if (empty($index->getId())) {
|
||||
throw new Exception('Index not found', 404);
|
||||
}
|
||||
|
||||
$index = $dbForInternal->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'deleting'));
|
||||
$dbForInternal->purgeDocument('collections', $collectionId);
|
||||
|
||||
$database
|
||||
->setParam('type', DATABASE_TYPE_DELETE_INDEX)
|
||||
->setParam('collection', $collection)
|
||||
->setParam('document', $index)
|
||||
;
|
||||
|
||||
|
|
|
@ -184,7 +184,7 @@ Database::addFilter('subQueryAttributes',
|
|||
return $database
|
||||
->find('attributes', [
|
||||
new Query('collectionId', Query::TYPE_EQUAL, [$document->getId()])
|
||||
], 100, 0, ['_id']);
|
||||
], 100, 0, []);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -196,7 +196,7 @@ Database::addFilter('subQueryIndexes',
|
|||
return $database
|
||||
->find('indexes', [
|
||||
new Query('collectionId', Query::TYPE_EQUAL, [$document->getId()])
|
||||
], 100, 0, ['_id']);
|
||||
], 100, 0, []);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -288,7 +288,8 @@ $logs = $this->getParam('logs', null);
|
|||
</td>
|
||||
|
||||
<td data-title="">
|
||||
<form class="pull-end"
|
||||
<form data-ls-if="{{index.status}} !== 'deleting'"
|
||||
class="pull-end"
|
||||
data-analytics
|
||||
data-analytics-activity
|
||||
data-analytics-event="submit"
|
||||
|
@ -307,7 +308,7 @@ $logs = $this->getParam('logs', null);
|
|||
|
||||
<input type="hidden" name="projectId" data-ls-bind="{{router.params.project}}" />
|
||||
<input type="hidden" name="collectionId" data-ls-bind="{{project-collection.$id}}" />
|
||||
<input type="hidden" name="indexId" data-ls-bind="{{index.$id}}" />
|
||||
<input type="hidden" name="indexId" data-ls-bind="{{index.key}}" />
|
||||
|
||||
<button class="danger small">Delete</button>
|
||||
</form>
|
||||
|
|
|
@ -28,6 +28,14 @@ class DatabaseV1 extends Worker
|
|||
$collection = new Document($collection);
|
||||
$document = $this->args['document'] ?? [];
|
||||
$document = new Document($document);
|
||||
|
||||
if($collection->isEmpty()) {
|
||||
throw new Exception('Missing collection');
|
||||
}
|
||||
|
||||
if($document->isEmpty()) {
|
||||
throw new Exception('Missing document');
|
||||
}
|
||||
|
||||
switch (strval($type)) {
|
||||
case DATABASE_TYPE_CREATE_ATTRIBUTE:
|
||||
|
|
|
@ -44,8 +44,6 @@ trait DatabaseBase
|
|||
'required' => true,
|
||||
]);
|
||||
|
||||
sleep(2);
|
||||
|
||||
$releaseYear = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['moviesId'] . '/attributes/integer', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
|
@ -55,8 +53,6 @@ trait DatabaseBase
|
|||
'required' => true,
|
||||
]);
|
||||
|
||||
sleep(2);
|
||||
|
||||
$actors = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['moviesId'] . '/attributes/string', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
|
@ -88,7 +84,7 @@ trait DatabaseBase
|
|||
$this->assertEquals($actors['body']['array'], true);
|
||||
|
||||
// wait for database worker to create attributes
|
||||
sleep(5);
|
||||
sleep(2);
|
||||
|
||||
$movies = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'], array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
@ -127,7 +123,7 @@ trait DatabaseBase
|
|||
$this->assertEquals($titleIndex['body']['attributes'][0], 'title');
|
||||
|
||||
// wait for database worker to create index
|
||||
sleep(5);
|
||||
sleep(2);
|
||||
|
||||
$movies = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'], array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
@ -242,8 +238,8 @@ trait DatabaseBase
|
|||
$this->assertCount(1, $document3['body']['$read']);
|
||||
$this->assertCount(1, $document3['body']['$write']);
|
||||
$this->assertCount(2, $document3['body']['actors']);
|
||||
$this->assertEquals($document2['body']['actors'][0], 'Tom Holland');
|
||||
$this->assertEquals($document2['body']['actors'][1], 'Zendaya Maree Stoermer');
|
||||
$this->assertEquals($document3['body']['actors'][0], 'Tom Holland');
|
||||
$this->assertEquals($document3['body']['actors'][1], 'Zendaya Maree Stoermer');
|
||||
|
||||
$this->assertEquals($document4['headers']['status-code'], 400);
|
||||
|
||||
|
@ -263,6 +259,7 @@ trait DatabaseBase
|
|||
'orderTypes' => ['ASC'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']);
|
||||
$this->assertEquals(2019, $documents['body']['documents'][2]['releaseYear']);
|
||||
|
@ -276,6 +273,7 @@ trait DatabaseBase
|
|||
'orderTypes' => ['DESC'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals(1944, $documents['body']['documents'][2]['releaseYear']);
|
||||
$this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']);
|
||||
$this->assertEquals(2019, $documents['body']['documents'][0]['releaseYear']);
|
||||
|
@ -297,6 +295,7 @@ trait DatabaseBase
|
|||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals($base['headers']['status-code'], 200);
|
||||
$this->assertEquals('Captain America', $base['body']['documents'][0]['title']);
|
||||
$this->assertEquals('Spider-Man: Far From Home', $base['body']['documents'][1]['title']);
|
||||
$this->assertEquals('Spider-Man: Homecoming', $base['body']['documents'][2]['title']);
|
||||
|
@ -309,6 +308,7 @@ trait DatabaseBase
|
|||
'after' => $base['body']['documents'][0]['$id']
|
||||
]);
|
||||
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals($base['body']['documents'][1]['$id'], $documents['body']['documents'][0]['$id']);
|
||||
$this->assertEquals($base['body']['documents'][2]['$id'], $documents['body']['documents'][1]['$id']);
|
||||
$this->assertCount(2, $documents['body']['documents']);
|
||||
|
@ -320,6 +320,7 @@ trait DatabaseBase
|
|||
'after' => $base['body']['documents'][2]['$id']
|
||||
]);
|
||||
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEmpty($documents['body']['documents']);
|
||||
|
||||
/**
|
||||
|
@ -333,6 +334,7 @@ trait DatabaseBase
|
|||
'orderTypes' => ['ASC'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($base['headers']['status-code'], 200);
|
||||
$this->assertEquals(1944, $base['body']['documents'][0]['releaseYear']);
|
||||
$this->assertEquals(2017, $base['body']['documents'][1]['releaseYear']);
|
||||
$this->assertEquals(2019, $base['body']['documents'][2]['releaseYear']);
|
||||
|
@ -347,6 +349,7 @@ trait DatabaseBase
|
|||
'after' => $base['body']['documents'][1]['$id']
|
||||
]);
|
||||
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals($base['body']['documents'][2]['$id'], $documents['body']['documents'][0]['$id']);
|
||||
$this->assertCount(1, $documents['body']['documents']);
|
||||
|
||||
|
@ -361,6 +364,7 @@ trait DatabaseBase
|
|||
'orderTypes' => ['DESC'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($base['headers']['status-code'], 200);
|
||||
$this->assertEquals(1944, $base['body']['documents'][2]['releaseYear']);
|
||||
$this->assertEquals(2017, $base['body']['documents'][1]['releaseYear']);
|
||||
$this->assertEquals(2019, $base['body']['documents'][0]['releaseYear']);
|
||||
|
@ -375,6 +379,7 @@ trait DatabaseBase
|
|||
'after' => $base['body']['documents'][1]['$id']
|
||||
]);
|
||||
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals($base['body']['documents'][2]['$id'], $documents['body']['documents'][0]['$id']);
|
||||
$this->assertCount(1, $documents['body']['documents']);
|
||||
|
||||
|
@ -407,6 +412,7 @@ trait DatabaseBase
|
|||
'orderTypes' => ['ASC'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertCount(1, $documents['body']['documents']);
|
||||
|
||||
|
@ -420,6 +426,7 @@ trait DatabaseBase
|
|||
'orderTypes' => ['ASC'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals(2017, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertEquals(2019, $documents['body']['documents'][1]['releaseYear']);
|
||||
$this->assertCount(2, $documents['body']['documents']);
|
||||
|
@ -439,6 +446,7 @@ trait DatabaseBase
|
|||
'queries' => ['title.search("Captain America")'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertCount(1, $documents['body']['documents']);
|
||||
|
||||
|
@ -449,6 +457,7 @@ trait DatabaseBase
|
|||
'queries' => ['title.search("Homecoming")'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals(2017, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertCount(1, $documents['body']['documents']);
|
||||
|
||||
|
@ -459,6 +468,7 @@ trait DatabaseBase
|
|||
'queries' => ['title.search("spider")'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals(2019, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']);
|
||||
$this->assertCount(2, $documents['body']['documents']);
|
||||
|
@ -742,7 +752,7 @@ trait DatabaseBase
|
|||
// $this->assertEquals('Minimum value must be lesser than maximum value', $invalidRange['body']['message']);
|
||||
|
||||
// wait for worker to add attributes
|
||||
sleep(15);
|
||||
sleep(2);
|
||||
|
||||
$collection = $this->client->call(Client::METHOD_GET, '/database/collections/' . $collectionId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
|
|
@ -148,7 +148,7 @@ class DatabaseCustomServerTest extends Scope
|
|||
]);
|
||||
|
||||
// Wait for database worker to finish creating attributes
|
||||
sleep(5);
|
||||
sleep(2);
|
||||
|
||||
$index = $this->client->call(Client::METHOD_POST, '/database/collections/' . $actors['body']['$id'] . '/indexes', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
@ -163,7 +163,7 @@ class DatabaseCustomServerTest extends Scope
|
|||
]);
|
||||
|
||||
// Wait for database worker to finish creating index
|
||||
sleep(5);
|
||||
sleep(2);
|
||||
|
||||
$collection = $this->client->call(Client::METHOD_GET, '/database/collections/' . $actors['body']['$id'], array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
@ -173,6 +173,7 @@ class DatabaseCustomServerTest extends Scope
|
|||
|
||||
$unneededId = $unneeded['body']['key'];
|
||||
|
||||
$this->assertEquals($collection['headers']['status-code'], 200);
|
||||
$this->assertIsArray($collection['body']['attributes']);
|
||||
$this->assertCount(3, $collection['body']['attributes']);
|
||||
$this->assertEquals($collection['body']['attributes'][0]['key'], $firstName['body']['key']);
|
||||
|
@ -182,13 +183,15 @@ class DatabaseCustomServerTest extends Scope
|
|||
$this->assertEquals($collection['body']['indexes'][0]['key'], $index['body']['key']);
|
||||
|
||||
// Delete attribute
|
||||
$this->client->call(Client::METHOD_DELETE, '/database/collections/' . $actors ['body']['$id'] . '/attributes/' . $unneededId, array_merge([
|
||||
$attribute = $this->client->call(Client::METHOD_DELETE, '/database/collections/' . $actors ['body']['$id'] . '/attributes/' . $unneededId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
sleep(5);
|
||||
$this->assertEquals($attribute['headers']['status-code'], 204);
|
||||
|
||||
sleep(2);
|
||||
|
||||
$collection = $this->client->call(Client::METHOD_GET, '/database/collections/' . $actors['body']['$id'], array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
@ -196,6 +199,7 @@ class DatabaseCustomServerTest extends Scope
|
|||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), []);
|
||||
|
||||
$this->assertEquals($collection['headers']['status-code'], 200);
|
||||
$this->assertIsArray($collection['body']['attributes']);
|
||||
$this->assertCount(2, $collection['body']['attributes']);
|
||||
$this->assertEquals($collection['body']['attributes'][0]['key'], $firstName['body']['key']);
|
||||
|
@ -206,6 +210,7 @@ class DatabaseCustomServerTest extends Scope
|
|||
'indexId' => $index['body']['key'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testDeleteAttribute
|
||||
*/
|
||||
|
@ -217,14 +222,16 @@ class DatabaseCustomServerTest extends Scope
|
|||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$this->assertEquals($index['headers']['status-code'], 204);
|
||||
|
||||
// Wait for database worker to finish deleting index
|
||||
sleep(5);
|
||||
sleep(2);
|
||||
|
||||
$collection = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['collectionId'], array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), []);
|
||||
]), []);
|
||||
|
||||
$this->assertCount(0, $collection['body']['indexes']);
|
||||
|
||||
|
|
Loading…
Reference in a new issue