Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/UserTest.php
Show First 20 Lines • Show All 315 Lines • ▼ Show 20 Lines | public function testCreateAndUpdate(): void | ||||
'email' => 'USER-test@' . \strtoupper($domain), | 'email' => 'USER-test@' . \strtoupper($domain), | ||||
'password' => 'test', | 'password' => 'test', | ||||
]); | ]); | ||||
$result = User::where('email', "user-test@$domain")->first(); | $result = User::where('email', "user-test@$domain")->first(); | ||||
$this->assertSame("user-test@$domain", $result->email); | $this->assertSame("user-test@$domain", $result->email); | ||||
$this->assertSame($user->id, $result->id); | $this->assertSame($user->id, $result->id); | ||||
$this->assertSame(User::STATUS_NEW | User::STATUS_ACTIVE, $result->status); | $this->assertSame(User::STATUS_NEW, $result->status); | ||||
$this->assertSame(0, $user->passwords()->count()); | $this->assertSame(0, $user->passwords()->count()); | ||||
Queue::assertPushed(\App\Jobs\User\CreateJob::class, 1); | Queue::assertPushed(\App\Jobs\User\CreateJob::class, 1); | ||||
Queue::assertPushed(\App\Jobs\PGP\KeyCreateJob::class, 0); | Queue::assertPushed(\App\Jobs\PGP\KeyCreateJob::class, 0); | ||||
Queue::assertPushed( | Queue::assertPushed( | ||||
\App\Jobs\User\CreateJob::class, | \App\Jobs\User\CreateJob::class, | ||||
function ($job) use ($user) { | function ($job) use ($user) { | ||||
$userEmail = TestCase::getObjectProperty($job, 'userEmail'); | $userEmail = TestCase::getObjectProperty($job, 'userEmail'); | ||||
$userId = TestCase::getObjectProperty($job, 'userId'); | $userId = TestCase::getObjectProperty($job, 'userId'); | ||||
return $userEmail === $user->email | return $userEmail === $user->email | ||||
&& $userId === $user->id; | && $userId === $user->id; | ||||
} | } | ||||
); | ); | ||||
Queue::assertPushedWithChain( | |||||
\App\Jobs\User\CreateJob::class, | |||||
[ | |||||
\App\Jobs\User\VerifyJob::class, | |||||
] | |||||
); | |||||
/* | |||||
FIXME: Looks like we can't really do detailed assertions on chained jobs | |||||
Another thing to consider is if we maybe should run these jobs | |||||
independently (not chained) and make sure there's no race-condition | |||||
in status update | |||||
Queue::assertPushed(\App\Jobs\User\VerifyJob::class, 1); | |||||
Queue::assertPushed(\App\Jobs\User\VerifyJob::class, function ($job) use ($user) { | |||||
$userEmail = TestCase::getObjectProperty($job, 'userEmail'); | |||||
$userId = TestCase::getObjectProperty($job, 'userId'); | |||||
return $userEmail === $user->email | |||||
&& $userId === $user->id; | |||||
}); | |||||
*/ | |||||
// Test invoking KeyCreateJob | // Test invoking KeyCreateJob | ||||
$this->deleteTestUser("user-test@$domain"); | $this->deleteTestUser("user-test@$domain"); | ||||
\App\Tenant::find(\config('app.tenant_id'))->setSetting('pgp.enable', 1); | \App\Tenant::find(\config('app.tenant_id'))->setSetting('pgp.enable', 1); | ||||
$user = User::create(['email' => "user-test@$domain", 'password' => 'test']); | $user = User::create(['email' => "user-test@$domain", 'password' => 'test']); | ||||
Queue::assertPushed(\App\Jobs\PGP\KeyCreateJob::class, 1); | Queue::assertPushed(\App\Jobs\PGP\KeyCreateJob::class, 1); | ||||
▲ Show 20 Lines • Show All 597 Lines • ▼ Show 20 Lines | public function testFindByEmail(): void | ||||
$this->assertNull($result); | $this->assertNull($result); | ||||
$ned->setAliases([]); | $ned->setAliases([]); | ||||
// TODO: searching by external email (setting) | // TODO: searching by external email (setting) | ||||
$this->markTestIncomplete(); | $this->markTestIncomplete(); | ||||
} | } | ||||
/** | /** | ||||
* Test User::hasSku() method | * Test User::hasSku() and countEntitlementsBySku() methods | ||||
*/ | */ | ||||
public function testHasSku(): void | public function testHasSku(): void | ||||
{ | { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$this->assertTrue($john->hasSku('mailbox')); | $this->assertTrue($john->hasSku('mailbox')); | ||||
$this->assertTrue($john->hasSku('storage')); | $this->assertTrue($john->hasSku('storage')); | ||||
$this->assertFalse($john->hasSku('beta')); | $this->assertFalse($john->hasSku('beta')); | ||||
$this->assertFalse($john->hasSku('unknown')); | $this->assertFalse($john->hasSku('unknown')); | ||||
$this->assertSame(0, $john->countEntitlementsBySku('unknown')); | |||||
$this->assertSame(0, $john->countEntitlementsBySku('2fa')); | |||||
$this->assertSame(1, $john->countEntitlementsBySku('mailbox')); | |||||
$this->assertSame(5, $john->countEntitlementsBySku('storage')); | |||||
} | } | ||||
/** | /** | ||||
* Test User::name() | * Test User::name() | ||||
*/ | */ | ||||
public function testName(): void | public function testName(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | public function testRestore(): void | ||||
Queue::assertPushed(\App\Jobs\User\UpdateJob::class, 1); | Queue::assertPushed(\App\Jobs\User\UpdateJob::class, 1); | ||||
Queue::assertPushed(\App\Jobs\User\CreateJob::class, 1); | Queue::assertPushed(\App\Jobs\User\CreateJob::class, 1); | ||||
Queue::assertPushed( | Queue::assertPushed( | ||||
\App\Jobs\User\CreateJob::class, | \App\Jobs\User\CreateJob::class, | ||||
function ($job) use ($userA) { | function ($job) use ($userA) { | ||||
return $userA->id === TestCase::getObjectProperty($job, 'userId'); | return $userA->id === TestCase::getObjectProperty($job, 'userId'); | ||||
} | } | ||||
); | ); | ||||
Queue::assertPushedWithChain( | |||||
\App\Jobs\User\CreateJob::class, | |||||
[ | |||||
\App\Jobs\User\VerifyJob::class, | |||||
] | |||||
); | |||||
} | } | ||||
/** | /** | ||||
* Tests for AliasesTrait::setAliases() | * Tests for AliasesTrait::setAliases() | ||||
*/ | */ | ||||
public function testSetAliases(): void | public function testSetAliases(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
▲ Show 20 Lines • Show All 223 Lines • Show Last 20 Lines |