Add query e2e tests to check for strict matching
This commit is contained in:
parent
af52dbd074
commit
d6b794d305
|
@ -601,6 +601,22 @@ trait DatabaseBase
|
|||
$this->assertCount(1, $titleIndex['body']['attributes']);
|
||||
$this->assertEquals('title', $titleIndex['body']['attributes'][0]);
|
||||
|
||||
$releaseYearIndex = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['moviesId'] . '/indexes', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'indexId' => 'releaseYear',
|
||||
'type' => 'key',
|
||||
'attributes' => ['releaseYear'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $releaseYearIndex['headers']['status-code']);
|
||||
$this->assertEquals('releaseYear', $releaseYearIndex['body']['key']);
|
||||
$this->assertEquals('key', $releaseYearIndex['body']['type']);
|
||||
$this->assertCount(1, $releaseYearIndex['body']['attributes']);
|
||||
$this->assertEquals('releaseYear', $releaseYearIndex['body']['attributes'][0]);
|
||||
|
||||
// wait for database worker to create index
|
||||
sleep(2);
|
||||
|
||||
|
@ -611,9 +627,11 @@ trait DatabaseBase
|
|||
]), []);
|
||||
|
||||
$this->assertIsArray($movies['body']['indexes']);
|
||||
$this->assertCount(1, $movies['body']['indexes']);
|
||||
$this->assertCount(2, $movies['body']['indexes']);
|
||||
$this->assertEquals($titleIndex['body']['key'], $movies['body']['indexes'][0]['key']);
|
||||
$this->assertEquals($releaseYearIndex['body']['key'], $movies['body']['indexes'][1]['key']);
|
||||
$this->assertEquals('available', $movies['body']['indexes'][0]['status']);
|
||||
$this->assertEquals('available', $movies['body']['indexes'][1]['status']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@ -1025,93 +1043,79 @@ trait DatabaseBase
|
|||
/**
|
||||
* @depends testCreateDocument
|
||||
*/
|
||||
// public function testDocumentsListSuccessSearch(array $data):array
|
||||
// {
|
||||
// $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ], $this->getHeaders()), [
|
||||
// 'queries' => ['title.search("Captain America")'],
|
||||
// ]);
|
||||
public function testDocumentsListQueries(array $data):array
|
||||
{
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => ['title.search("Captain America")'],
|
||||
]);
|
||||
|
||||
// var_dump($documents);
|
||||
var_dump($documents);
|
||||
|
||||
// $this->assertEquals($documents['headers']['status-code'], 200);
|
||||
// $this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
|
||||
// $this->assertCount(1, $documents['body']['documents']);
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertCount(1, $documents['body']['documents']);
|
||||
|
||||
// $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ], $this->getHeaders()), [
|
||||
// 'queries' => ['title.search("Homecoming")'],
|
||||
// ]);
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'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']);
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals(2017, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertCount(1, $documents['body']['documents']);
|
||||
|
||||
// $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ], $this->getHeaders()), [
|
||||
// 'queries' => ['title.search("spider")'],
|
||||
// ]);
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'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']);
|
||||
$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']);
|
||||
|
||||
// return [];
|
||||
// }
|
||||
// TODO@kodumbeats test for empty searches and misformatted queries
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => ['releaseYear.equal(1944)'],
|
||||
]);
|
||||
|
||||
/**
|
||||
* @depends testCreateDocument
|
||||
*/
|
||||
// public function testListDocumentsFilters(array $data):array
|
||||
// {
|
||||
// $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ], $this->getHeaders()), [
|
||||
// 'filters' => [
|
||||
// 'actors.firstName=Tom'
|
||||
// ],
|
||||
// ]);
|
||||
$this->assertCount(1, $documents['body']['documents']);
|
||||
$this->assertEquals('Captain America', $documents['body']['documents'][0]['title']);
|
||||
|
||||
// $this->assertCount(2, $documents['body']['documents']);
|
||||
// $this->assertEquals('Spider-Man: Far From Home', $documents['body']['documents'][0]['name']);
|
||||
// $this->assertEquals('Spider-Man: Homecoming', $documents['body']['documents'][1]['name']);
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => ['releaseYear.notEqual(1944)'],
|
||||
]);
|
||||
|
||||
// $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ], $this->getHeaders()), [
|
||||
// 'filters' => [
|
||||
// 'releaseYear=1944'
|
||||
// ],
|
||||
// ]);
|
||||
$this->assertCount(2, $documents['body']['documents']);
|
||||
$this->assertEquals('Spider-Man: Far From Home', $documents['body']['documents'][0]['title']);
|
||||
$this->assertEquals('Spider-Man: Homecoming', $documents['body']['documents'][1]['title']);
|
||||
|
||||
// $this->assertCount(1, $documents['body']['documents']);
|
||||
// $this->assertEquals('Captain America', $documents['body']['documents'][0]['name']);
|
||||
/**
|
||||
* Test for Failure
|
||||
*/
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => ['actors.equal("Tom Holland")'],
|
||||
]);
|
||||
$this->assertEquals(400, $documents['headers']['status-code']);
|
||||
$this->assertEquals('Index not found: actors', $documents['body']['message']);
|
||||
|
||||
// $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
// 'content-type' => 'application/json',
|
||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
||||
// ], $this->getHeaders()), [
|
||||
// 'filters' => [
|
||||
// 'releaseYear!=1944'
|
||||
// ],
|
||||
// ]);
|
||||
|
||||
// $this->assertCount(2, $documents['body']['documents']);
|
||||
// $this->assertEquals('Spider-Man: Far From Home', $documents['body']['documents'][0]['name']);
|
||||
// $this->assertEquals('Spider-Man: Homecoming', $documents['body']['documents'][1]['name']);
|
||||
|
||||
// return [];
|
||||
// }
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateDocument
|
||||
|
|
Loading…
Reference in a new issue