feat: added server side test
This commit is contained in:
parent
3b74a92ab3
commit
a35a567e0e
|
@ -475,8 +475,8 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId')
|
||||||
->desc('Update Membership Roles')
|
->desc('Update Membership Roles')
|
||||||
->groups(['api', 'teams'])
|
->groups(['api', 'teams'])
|
||||||
->label('event', 'teams.memberships.update')
|
->label('event', 'teams.memberships.update')
|
||||||
->label('scope', 'public')
|
->label('scope', 'teams.write')
|
||||||
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY])
|
->label('sdk.auth', [APP_AUTH_TYPE_SESSION, APP_AUTH_TYPE_KEY, APP_AUTH_TYPE_JWT])
|
||||||
->label('sdk.namespace', 'teams')
|
->label('sdk.namespace', 'teams')
|
||||||
->label('sdk.method', 'updateMembershipRoles')
|
->label('sdk.method', 'updateMembershipRoles')
|
||||||
->label('sdk.description', '/docs/references/teams/update-team-membership-roles.md')
|
->label('sdk.description', '/docs/references/teams/update-team-membership-roles.md')
|
||||||
|
|
|
@ -154,4 +154,25 @@ trait ProjectCustom
|
||||||
|
|
||||||
return self::$project;
|
return self::$project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getNewKey(array $scopes) {
|
||||||
|
|
||||||
|
$projectId = self::$project['$id'];
|
||||||
|
|
||||||
|
$key = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', [
|
||||||
|
'origin' => 'http://localhost',
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
||||||
|
'x-appwrite-project' => 'console',
|
||||||
|
], [
|
||||||
|
'name' => 'Demo Project Key',
|
||||||
|
'scopes' => $scopes,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $key['headers']['status-code']);
|
||||||
|
$this->assertNotEmpty($key['body']);
|
||||||
|
$this->assertNotEmpty($key['body']['secret']);
|
||||||
|
|
||||||
|
return $key['body']['secret'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ trait TeamsBaseServer
|
||||||
$this->assertEquals(true, $response['body']['confirm']);
|
$this->assertEquals(true, $response['body']['confirm']);
|
||||||
|
|
||||||
$userUid = $response['body']['userId'];
|
$userUid = $response['body']['userId'];
|
||||||
|
$membershipUid = $response['body']['$id'];
|
||||||
|
|
||||||
// $response = $this->client->call(Client::METHOD_GET, '/users/'.$userUid, array_merge([
|
// $response = $this->client->call(Client::METHOD_GET, '/users/'.$userUid, array_merge([
|
||||||
// 'content-type' => 'application/json',
|
// 'content-type' => 'application/json',
|
||||||
|
@ -117,6 +118,55 @@ trait TeamsBaseServer
|
||||||
return [
|
return [
|
||||||
'teamUid' => $teamUid,
|
'teamUid' => $teamUid,
|
||||||
'userUid' => $userUid,
|
'userUid' => $userUid,
|
||||||
|
'membershipUid' => $membershipUid
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateTeamMembership
|
||||||
|
*/
|
||||||
|
public function testUpdateMembershipRoles($data)
|
||||||
|
{
|
||||||
|
$teamUid = $data['teamUid'] ?? '';
|
||||||
|
$membershipUid = $data['membershipUid'] ?? '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for SUCCESS
|
||||||
|
*/
|
||||||
|
$roles = ['admin', 'editor', 'uncle'];
|
||||||
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid, array_merge([
|
||||||
|
'origin' => 'http://localhost',
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()), [
|
||||||
|
'roles' => $roles
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
|
$this->assertNotEmpty($response['body']['$id']);
|
||||||
|
$this->assertNotEmpty($response['body']['userId']);
|
||||||
|
$this->assertNotEmpty($response['body']['teamId']);
|
||||||
|
$this->assertCount(count($roles), $response['body']['roles']);
|
||||||
|
$this->assertEquals($roles[0], $response['body']['roles'][0]);
|
||||||
|
$this->assertEquals($roles[1], $response['body']['roles'][1]);
|
||||||
|
$this->assertEquals($roles[2], $response['body']['roles'][2]);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for FAILURE
|
||||||
|
*/
|
||||||
|
$apiKey = $this->getNewKey(['teams.read']);
|
||||||
|
$roles = ['admin', 'editor', 'uncle'];
|
||||||
|
$response = $this->client->call(Client::METHOD_PATCH, '/teams/'.$teamUid.'/memberships/'.$membershipUid, [
|
||||||
|
'origin' => 'http://localhost',
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
'x-appwrite-key' => $apiKey
|
||||||
|
], [
|
||||||
|
'roles' => $roles
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(401, $response['headers']['status-code']);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue