improve test by removing user creation loop
The CREATE TEAM MEMBERSHIP endpoint requires the email of the user to be added to the team. If the user does not exist in the project, a new user is created with the specified email and added to the team. The first version of the test creates 5 users, and then adds them to the newly created team. This process is more streamlined now, by using the CREATE TEAM MEMBERSHIPS behaviour to create a user on the go and create a membership for them immediately after. I also change the way I add user IDs to the array, by using the shorthand notation instead of the `array_push` function.
This commit is contained in:
parent
451f4bee19
commit
0295c6ec1b
1 changed files with 5 additions and 25 deletions
|
@ -285,32 +285,9 @@ trait TeamsBaseServer
|
||||||
|
|
||||||
public function testTeamDeleteUpdatesUserMembership()
|
public function testTeamDeleteUpdatesUserMembership()
|
||||||
{
|
{
|
||||||
|
// Array to store the IDs of newly created users
|
||||||
$new_users = [];
|
$new_users = [];
|
||||||
|
|
||||||
/**
|
|
||||||
* Create 5 new users and add their IDs to an array
|
|
||||||
*/
|
|
||||||
for ($i = 0; $i < 5; $i++) {
|
|
||||||
$user = $this->client->call(Client::METHOD_POST, '/users', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'userId' => ID::unique(),
|
|
||||||
'email' => 'newuser' . $i . '@localhost.test',
|
|
||||||
'password' => 'password',
|
|
||||||
'name' => 'New User ' . $i,
|
|
||||||
], false);
|
|
||||||
|
|
||||||
$user_body = json_decode($user['body'], true);
|
|
||||||
|
|
||||||
$this->assertEquals(201, $user['headers']['status-code']);
|
|
||||||
$this->assertEquals('newuser' . $i . '@localhost.test', $user_body['email']);
|
|
||||||
$this->assertEquals('New User ' . $i, $user_body['name']);
|
|
||||||
$this->assertEquals($user_body['status'], true);
|
|
||||||
|
|
||||||
array_push($new_users, $user_body['$id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new team
|
* Create a new team
|
||||||
*/
|
*/
|
||||||
|
@ -331,7 +308,8 @@ trait TeamsBaseServer
|
||||||
$this->assertArrayHasKey('prefs', $new_team['body']);
|
$this->assertArrayHasKey('prefs', $new_team['body']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create team memberships for each of the new users
|
* Use the Create Team Membership endpoint
|
||||||
|
* to create 5 new users and add them to the team immediately
|
||||||
*/
|
*/
|
||||||
for ($i = 0; $i < 5; $i++) {
|
for ($i = 0; $i < 5; $i++) {
|
||||||
$new_membership = $this->client->call(Client::METHOD_POST, '/teams/' . $new_team['body']['$id'] . '/memberships', array_merge([
|
$new_membership = $this->client->call(Client::METHOD_POST, '/teams/' . $new_team['body']['$id'] . '/memberships', array_merge([
|
||||||
|
@ -354,6 +332,8 @@ trait TeamsBaseServer
|
||||||
$dateValidator = new DatetimeValidator();
|
$dateValidator = new DatetimeValidator();
|
||||||
$this->assertEquals(true, $dateValidator->isValid($new_membership['body']['joined']));
|
$this->assertEquals(true, $dateValidator->isValid($new_membership['body']['joined']));
|
||||||
$this->assertEquals(true, $new_membership['body']['confirm']);
|
$this->assertEquals(true, $new_membership['body']['confirm']);
|
||||||
|
|
||||||
|
$new_users[] = $new_membership['body']['userId'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue