forked from ecamp/ecamp3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Claim open invitations when assigning their email to an account
- Loading branch information
1 parent
f79cbfb
commit f7cd85f
Showing
5 changed files
with
216 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,15 @@ | |
|
||
namespace App\Tests\Api\Profiles; | ||
|
||
use _PHPStan_5473b6701\Nette\Neon\Exception; | ||
use App\Entity\Camp; | ||
use App\Entity\CampCollaboration; | ||
use App\Entity\Profile; | ||
use App\Tests\Api\ECampApiTestCase; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory; | ||
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface; | ||
use Symfony\Component\PasswordHasher\PasswordHasherInterface; | ||
|
||
/** | ||
* @internal | ||
|
@@ -91,6 +97,70 @@ public function testPatchProfileDisallowsChangingEmail() { | |
]); | ||
} | ||
|
||
public function testPatchProfileCollectsPersonalInvitation() { | ||
|
||
$client = static::createClientWithCredentials(); | ||
// Disable resetting the database between the two requests | ||
$client->disableReboot(); | ||
|
||
$camp = $this->getEntityManager()->find(Camp::class, static::getFixture('campUnrelated')->getId()); | ||
$camp2 = $this->getEntityManager()->find(Camp::class, static::getFixture('campPrototype')->getId()); | ||
|
||
// create an invitation which will be claimed by the user | ||
$invitation1 = new CampCollaboration(); | ||
$invitation1->camp = $camp; | ||
$invitation1->status = CampCollaboration::STATUS_INVITED; | ||
$invitation1->inviteEmail = '[email protected]'; | ||
$invitation1->inviteKeyHash = '1234123412341234'; | ||
$invitation1->role = CampCollaboration::ROLE_MANAGER; | ||
$this->getEntityManager()->persist($invitation1); | ||
|
||
// create a rejected invitation which will not be claimed by the user | ||
$invitation2 = new CampCollaboration(); | ||
$invitation2->camp = $camp2; | ||
$invitation2->status = CampCollaboration::STATUS_INACTIVE; | ||
$invitation2->inviteEmail = '[email protected]'; | ||
$invitation2->inviteKeyHash = '2341234123412341'; | ||
$invitation2->role = CampCollaboration::ROLE_MANAGER; | ||
$this->getEntityManager()->persist($invitation2); | ||
|
||
// create an unrelated invitation which will not be claimed by the user | ||
$invitation3 = new CampCollaboration(); | ||
$invitation3->camp = $camp; | ||
$invitation3->status = CampCollaboration::STATUS_INVITED; | ||
$invitation3->inviteEmail = '[email protected]'; | ||
$invitation3->inviteKeyHash = '3412341234123412'; | ||
$invitation3->role = CampCollaboration::ROLE_MANAGER; | ||
$this->getEntityManager()->persist($invitation3); | ||
|
||
$this->getEntityManager()->flush(); | ||
|
||
/** @var Profile $profile */ | ||
$profile = static::getFixture('profile1manager'); | ||
|
||
// when | ||
$client->request('PATCH', '/profiles/'.$profile->getId(), ['json' => [ | ||
'nickname' => 'Linux', | ||
], 'headers' => ['Content-Type' => 'application/merge-patch+json']]); | ||
$this->assertResponseStatusCodeSame(200); | ||
|
||
// then | ||
$client->request('GET', '/personal_invitations'); | ||
|
||
// User has one personal invitation waiting for them | ||
$this->assertJsonContains([ | ||
'totalItems' => 1, | ||
'_links' => [ | ||
'items' => [ | ||
['href' => "/personal_invitations/{$invitation1->getId()}"] | ||
], | ||
], | ||
'_embedded' => [ | ||
'items' => [], | ||
], | ||
]); | ||
} | ||
|
||
public function testPatchProfileTrimsFirstname() { | ||
$profile = static::getFixture('profile1manager'); | ||
static::createClientWithCredentials()->request('PATCH', '/profiles/'.$profile->getId(), ['json' => [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Metadata\Post; | ||
use App\Entity\Camp; | ||
use App\Entity\CampCollaboration; | ||
use App\Entity\Profile; | ||
use App\Entity\User; | ||
use App\Tests\Api\ECampApiTestCase; | ||
|
@@ -77,6 +79,81 @@ public function testLoginAfterRegistrationAndActivation() { | |
$this->assertResponseIsSuccessful(); | ||
} | ||
|
||
public function testActivationClaimsOpenInvitations() { | ||
// given | ||
$client = static::createBasicClient(); | ||
// Disable resetting the database between the two requests | ||
$client->disableReboot(); | ||
|
||
$camp = $this->getEntityManager()->find(Camp::class, static::getFixture('camp1')->getId()); | ||
$camp2 = $this->getEntityManager()->find(Camp::class, static::getFixture('camp2')->getId()); | ||
|
||
// create an invitation which will be claimed by the user | ||
$invitation1 = new CampCollaboration(); | ||
$invitation1->camp = $camp; | ||
$invitation1->status = CampCollaboration::STATUS_INVITED; | ||
$invitation1->inviteEmail = '[email protected]'; | ||
$invitation1->inviteKeyHash = '1234123412341234'; | ||
$invitation1->role = CampCollaboration::ROLE_MANAGER; | ||
$this->getEntityManager()->persist($invitation1); | ||
|
||
// create a rejected invitation which will not be claimed by the user | ||
$invitation2 = new CampCollaboration(); | ||
$invitation2->camp = $camp2; | ||
$invitation2->status = CampCollaboration::STATUS_INACTIVE; | ||
$invitation2->inviteEmail = '[email protected]'; | ||
$invitation2->inviteKeyHash = '2341234123412341'; | ||
$invitation2->role = CampCollaboration::ROLE_MANAGER; | ||
$this->getEntityManager()->persist($invitation2); | ||
|
||
// create an unrelated invitation which will not be claimed by the user | ||
$invitation3 = new CampCollaboration(); | ||
$invitation3->camp = $camp; | ||
$invitation3->status = CampCollaboration::STATUS_INVITED; | ||
$invitation3->inviteEmail = '[email protected]'; | ||
$invitation3->inviteKeyHash = '3412341234123412'; | ||
$invitation3->role = CampCollaboration::ROLE_MANAGER; | ||
$this->getEntityManager()->persist($invitation3); | ||
|
||
$this->getEntityManager()->flush(); | ||
|
||
// register user | ||
$result = $client->request('POST', '/users', ['json' => $this->getExampleWritePayload()]); | ||
$this->assertResponseStatusCodeSame(201); | ||
|
||
$userId = $result->toArray()['id']; | ||
$user = $this->getEntityManager()->getRepository(User::class)->find($userId); | ||
|
||
// when | ||
// activate user | ||
$client->request('PATCH', "/users/{$userId}/activate", ['json' => [ | ||
'activationKey' => $user->activationKey, | ||
], 'headers' => ['Content-Type' => 'application/merge-patch+json']]); | ||
$this->assertResponseIsSuccessful(); | ||
|
||
// login | ||
$client->request('POST', '/authentication_token', ['json' => [ | ||
'identifier' => '[email protected]', | ||
'password' => 'learning-by-doing-101', | ||
]]); | ||
|
||
// then | ||
$client->request('GET', '/personal_invitations'); | ||
|
||
// User has one personal invitation waiting for them | ||
$this->assertJsonContains([ | ||
'totalItems' => 1, | ||
'_links' => [ | ||
'items' => [ | ||
['href' => "/personal_invitations/{$invitation1->getId()}"] | ||
], | ||
], | ||
'_embedded' => [ | ||
'items' => [], | ||
], | ||
]); | ||
} | ||
|
||
public function testActivationFailsIfAlreadyActivated() { | ||
$client = static::createBasicClient(); | ||
// Disable resetting the database between the two requests | ||
|