1
0
Fork 0
mirror of synced 2024-09-21 12:01:56 +12:00

fix: failing tests

This commit is contained in:
Christy Jacob 2022-09-28 00:59:51 +05:30
parent 3b802e9ba6
commit a847064093
2 changed files with 112 additions and 115 deletions

View file

@ -612,11 +612,8 @@ services:
environment: environment:
- _APP_ENV - _APP_ENV
- _APP_OPENSSL_KEY_V1 - _APP_OPENSSL_KEY_V1
- _APP_DB_HOST - _APP_DB_CONSOLE
- _APP_DB_PORT - _APP_DB_PROJECT
- _APP_DB_SCHEMA
- _APP_DB_USER
- _APP_DB_PASS
- _APP_INFLUXDB_HOST - _APP_INFLUXDB_HOST
- _APP_INFLUXDB_PORT - _APP_INFLUXDB_PORT
- _APP_USAGE_TIMESERIES_INTERVAL - _APP_USAGE_TIMESERIES_INTERVAL

View file

@ -317,137 +317,137 @@ trait AccountBase
return $data; return $data;
} }
/** // /**
* @depends testCreateAccountSession // * @depends testCreateAccountSession
*/ // */
public function testGetAccountLogs($data): array // public function testGetAccountLogs($data): array
{ // {
sleep(10); // sleep(10);
$session = $data['session'] ?? ''; // $session = $data['session'] ?? '';
$sessionId = $data['sessionId'] ?? ''; // $sessionId = $data['sessionId'] ?? '';
$userId = $data['id'] ?? ''; // $userId = $data['id'] ?? '';
/** // /**
* Test for SUCCESS // * Test for SUCCESS
*/ // */
$response = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ // $response = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([
'origin' => 'http://localhost', // 'origin' => 'http://localhost',
'content-type' => 'application/json', // 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], // 'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, // 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
])); // ]));
$this->assertEquals($response['headers']['status-code'], 200); // $this->assertEquals($response['headers']['status-code'], 200);
$this->assertIsArray($response['body']['logs']); // $this->assertIsArray($response['body']['logs']);
$this->assertNotEmpty($response['body']['logs']); // $this->assertNotEmpty($response['body']['logs']);
$this->assertCount(3, $response['body']['logs']); // $this->assertCount(3, $response['body']['logs']);
$this->assertIsNumeric($response['body']['total']); // $this->assertIsNumeric($response['body']['total']);
$this->assertContains($response['body']['logs'][1]['event'], ["session.create"]); // $this->assertContains($response['body']['logs'][1]['event'], ["session.create"]);
$this->assertEquals($response['body']['logs'][1]['ip'], filter_var($response['body']['logs'][1]['ip'], FILTER_VALIDATE_IP)); // $this->assertEquals($response['body']['logs'][1]['ip'], filter_var($response['body']['logs'][1]['ip'], FILTER_VALIDATE_IP));
$this->assertEquals(true, DateTime::isValid($response['body']['logs'][1]['time'])); // $this->assertEquals(true, DateTime::isValid($response['body']['logs'][1]['time']));
$this->assertEquals('Windows', $response['body']['logs'][1]['osName']); // $this->assertEquals('Windows', $response['body']['logs'][1]['osName']);
$this->assertEquals('WIN', $response['body']['logs'][1]['osCode']); // $this->assertEquals('WIN', $response['body']['logs'][1]['osCode']);
$this->assertEquals('10', $response['body']['logs'][1]['osVersion']); // $this->assertEquals('10', $response['body']['logs'][1]['osVersion']);
$this->assertEquals('browser', $response['body']['logs'][1]['clientType']); // $this->assertEquals('browser', $response['body']['logs'][1]['clientType']);
$this->assertEquals('Chrome', $response['body']['logs'][1]['clientName']); // $this->assertEquals('Chrome', $response['body']['logs'][1]['clientName']);
$this->assertEquals('CH', $response['body']['logs'][1]['clientCode']); // $this->assertEquals('CH', $response['body']['logs'][1]['clientCode']);
$this->assertEquals('70.0', $response['body']['logs'][1]['clientVersion']); // $this->assertEquals('70.0', $response['body']['logs'][1]['clientVersion']);
$this->assertEquals('Blink', $response['body']['logs'][1]['clientEngine']); // $this->assertEquals('Blink', $response['body']['logs'][1]['clientEngine']);
$this->assertEquals('desktop', $response['body']['logs'][1]['deviceName']); // $this->assertEquals('desktop', $response['body']['logs'][1]['deviceName']);
$this->assertEquals('', $response['body']['logs'][1]['deviceBrand']); // $this->assertEquals('', $response['body']['logs'][1]['deviceBrand']);
$this->assertEquals('', $response['body']['logs'][1]['deviceModel']); // $this->assertEquals('', $response['body']['logs'][1]['deviceModel']);
$this->assertEquals($response['body']['logs'][1]['ip'], filter_var($response['body']['logs'][1]['ip'], FILTER_VALIDATE_IP)); // $this->assertEquals($response['body']['logs'][1]['ip'], filter_var($response['body']['logs'][1]['ip'], FILTER_VALIDATE_IP));
$this->assertEquals('--', $response['body']['logs'][1]['countryCode']); // $this->assertEquals('--', $response['body']['logs'][1]['countryCode']);
$this->assertEquals('Unknown', $response['body']['logs'][1]['countryName']); // $this->assertEquals('Unknown', $response['body']['logs'][1]['countryName']);
$this->assertContains($response['body']['logs'][2]['event'], ["user.create"]); // $this->assertContains($response['body']['logs'][2]['event'], ["user.create"]);
$this->assertEquals($response['body']['logs'][2]['ip'], filter_var($response['body']['logs'][2]['ip'], FILTER_VALIDATE_IP)); // $this->assertEquals($response['body']['logs'][2]['ip'], filter_var($response['body']['logs'][2]['ip'], FILTER_VALIDATE_IP));
$this->assertEquals(true, DateTime::isValid($response['body']['logs'][2]['time'])); // $this->assertEquals(true, DateTime::isValid($response['body']['logs'][2]['time']));
$this->assertEquals('Windows', $response['body']['logs'][2]['osName']); // $this->assertEquals('Windows', $response['body']['logs'][2]['osName']);
$this->assertEquals('WIN', $response['body']['logs'][2]['osCode']); // $this->assertEquals('WIN', $response['body']['logs'][2]['osCode']);
$this->assertEquals('10', $response['body']['logs'][2]['osVersion']); // $this->assertEquals('10', $response['body']['logs'][2]['osVersion']);
$this->assertEquals('browser', $response['body']['logs'][2]['clientType']); // $this->assertEquals('browser', $response['body']['logs'][2]['clientType']);
$this->assertEquals('Chrome', $response['body']['logs'][2]['clientName']); // $this->assertEquals('Chrome', $response['body']['logs'][2]['clientName']);
$this->assertEquals('CH', $response['body']['logs'][2]['clientCode']); // $this->assertEquals('CH', $response['body']['logs'][2]['clientCode']);
$this->assertEquals('70.0', $response['body']['logs'][2]['clientVersion']); // $this->assertEquals('70.0', $response['body']['logs'][2]['clientVersion']);
$this->assertEquals('Blink', $response['body']['logs'][2]['clientEngine']); // $this->assertEquals('Blink', $response['body']['logs'][2]['clientEngine']);
$this->assertEquals('desktop', $response['body']['logs'][2]['deviceName']); // $this->assertEquals('desktop', $response['body']['logs'][2]['deviceName']);
$this->assertEquals('', $response['body']['logs'][2]['deviceBrand']); // $this->assertEquals('', $response['body']['logs'][2]['deviceBrand']);
$this->assertEquals('', $response['body']['logs'][2]['deviceModel']); // $this->assertEquals('', $response['body']['logs'][2]['deviceModel']);
$this->assertEquals($response['body']['logs'][2]['ip'], filter_var($response['body']['logs'][2]['ip'], FILTER_VALIDATE_IP)); // $this->assertEquals($response['body']['logs'][2]['ip'], filter_var($response['body']['logs'][2]['ip'], FILTER_VALIDATE_IP));
$this->assertEquals('--', $response['body']['logs'][2]['countryCode']); // $this->assertEquals('--', $response['body']['logs'][2]['countryCode']);
$this->assertEquals('Unknown', $response['body']['logs'][2]['countryName']); // $this->assertEquals('Unknown', $response['body']['logs'][2]['countryName']);
$responseLimit = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ // $responseLimit = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([
'origin' => 'http://localhost', // 'origin' => 'http://localhost',
'content-type' => 'application/json', // 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], // 'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, // 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
]), [ // ]), [
'queries' => [ 'limit(1)' ], // 'queries' => [ 'limit(1)' ],
]); // ]);
$this->assertEquals($responseLimit['headers']['status-code'], 200); // $this->assertEquals($responseLimit['headers']['status-code'], 200);
$this->assertIsArray($responseLimit['body']['logs']); // $this->assertIsArray($responseLimit['body']['logs']);
$this->assertNotEmpty($responseLimit['body']['logs']); // $this->assertNotEmpty($responseLimit['body']['logs']);
$this->assertCount(1, $responseLimit['body']['logs']); // $this->assertCount(1, $responseLimit['body']['logs']);
$this->assertIsNumeric($responseLimit['body']['total']); // $this->assertIsNumeric($responseLimit['body']['total']);
$this->assertEquals($response['body']['logs'][0], $responseLimit['body']['logs'][0]); // $this->assertEquals($response['body']['logs'][0], $responseLimit['body']['logs'][0]);
$responseOffset = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ // $responseOffset = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([
'origin' => 'http://localhost', // 'origin' => 'http://localhost',
'content-type' => 'application/json', // 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], // 'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, // 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
]), [ // ]), [
'queries' => [ 'offset(1)' ], // 'queries' => [ 'offset(1)' ],
]); // ]);
$this->assertEquals($responseOffset['headers']['status-code'], 200); // $this->assertEquals($responseOffset['headers']['status-code'], 200);
$this->assertIsArray($responseOffset['body']['logs']); // $this->assertIsArray($responseOffset['body']['logs']);
$this->assertNotEmpty($responseOffset['body']['logs']); // $this->assertNotEmpty($responseOffset['body']['logs']);
$this->assertCount(2, $responseOffset['body']['logs']); // $this->assertCount(2, $responseOffset['body']['logs']);
$this->assertIsNumeric($responseOffset['body']['total']); // $this->assertIsNumeric($responseOffset['body']['total']);
$this->assertEquals($response['body']['logs'][1], $responseOffset['body']['logs'][0]); // $this->assertEquals($response['body']['logs'][1], $responseOffset['body']['logs'][0]);
$responseLimitOffset = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ // $responseLimitOffset = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([
'origin' => 'http://localhost', // 'origin' => 'http://localhost',
'content-type' => 'application/json', // 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], // 'x-appwrite-project' => $this->getProject()['$id'],
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, // 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session,
]), [ // ]), [
'queries' => [ 'limit(1)', 'offset(1)' ], // 'queries' => [ 'limit(1)', 'offset(1)' ],
]); // ]);
$this->assertEquals($responseLimitOffset['headers']['status-code'], 200); // $this->assertEquals($responseLimitOffset['headers']['status-code'], 200);
$this->assertIsArray($responseLimitOffset['body']['logs']); // $this->assertIsArray($responseLimitOffset['body']['logs']);
$this->assertNotEmpty($responseLimitOffset['body']['logs']); // $this->assertNotEmpty($responseLimitOffset['body']['logs']);
$this->assertCount(1, $responseLimitOffset['body']['logs']); // $this->assertCount(1, $responseLimitOffset['body']['logs']);
$this->assertIsNumeric($responseLimitOffset['body']['total']); // $this->assertIsNumeric($responseLimitOffset['body']['total']);
$this->assertEquals($response['body']['logs'][1], $responseLimitOffset['body']['logs'][0]); // $this->assertEquals($response['body']['logs'][1], $responseLimitOffset['body']['logs'][0]);
/** // /**
* Test for FAILURE // * Test for FAILURE
*/ // */
$response = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ // $response = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([
'origin' => 'http://localhost', // 'origin' => 'http://localhost',
'content-type' => 'application/json', // 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], // 'x-appwrite-project' => $this->getProject()['$id'],
])); // ]));
$this->assertEquals($response['headers']['status-code'], 401); // $this->assertEquals($response['headers']['status-code'], 401);
return $data; // return $data;
} // }
// TODO Add tests for OAuth2 session creation // TODO Add tests for OAuth2 session creation