diff --git a/src/app/Jobs/DomainCreate.php b/src/app/Jobs/DomainCreate.php index 6962a2d4..419169f9 100644 --- a/src/app/Jobs/DomainCreate.php +++ b/src/app/Jobs/DomainCreate.php @@ -1,53 +1,55 @@ domain = $domain; } /** * Execute the job. * * @return void */ public function handle() { if (!$this->domain->isLdapReady()) { LDAP::createDomain($this->domain); $this->domain->status |= Domain::STATUS_LDAP_READY; $this->domain->save(); + + DomainVerify::dispatch($this->domain); } } } diff --git a/src/app/Observers/DomainObserver.php b/src/app/Observers/DomainObserver.php index af9cc23c..8a91be82 100644 --- a/src/app/Observers/DomainObserver.php +++ b/src/app/Observers/DomainObserver.php @@ -1,106 +1,107 @@ {$domain->getKeyName()} = $allegedly_unique; break; } } $domain->status |= Domain::STATUS_NEW | Domain::STATUS_ACTIVE; } /** * Handle the domain "created" event. * * @param \App\Domain $domain The domain. * * @return void */ public function created(Domain $domain) { - // Create domain record in LDAP, then check if it exists in DNS + // Create domain record in LDAP + // Note: DomainCreate job will dispatch DomainVerify job \App\Jobs\DomainCreate::dispatch($domain); } /** * Handle the domain "deleting" event. * * @param \App\Domain $domain The domain. * * @return void */ public function deleting(Domain $domain) { // Entitlements do not have referential integrity on the entitled object, so this is our // way of doing an onDelete('cascade') without the foreign key. \App\Entitlement::where('entitleable_id', $domain->id) ->where('entitleable_type', Domain::class) ->delete(); } /** * Handle the domain "deleted" event. * * @param \App\Domain $domain The domain. * * @return void */ public function deleted(Domain $domain) { \App\Jobs\DomainDelete::dispatch($domain->id); } /** * Handle the domain "updated" event. * * @param \App\Domain $domain The domain. * * @return void */ public function updated(Domain $domain) { \App\Jobs\DomainUpdate::dispatch($domain->id); } /** * Handle the domain "restored" event. * * @param \App\Domain $domain The domain. * * @return void */ public function restored(Domain $domain) { // } /** * Handle the domain "force deleted" event. * * @param \App\Domain $domain The domain. * * @return void */ public function forceDeleted(Domain $domain) { // } } diff --git a/src/tests/Feature/Jobs/DomainCreateTest.php b/src/tests/Feature/Jobs/DomainCreateTest.php index e9d2c728..5ec03547 100644 --- a/src/tests/Feature/Jobs/DomainCreateTest.php +++ b/src/tests/Feature/Jobs/DomainCreateTest.php @@ -1,52 +1,68 @@ deleteTestDomain('domain-create-test.com'); } public function tearDown(): void { $this->deleteTestDomain('domain-create-test.com'); parent::tearDown(); } /** * Test job handle * * @group ldap */ public function testHandle(): void { $domain = $this->getTestDomain( 'domain-create-test.com', [ 'status' => Domain::STATUS_NEW, 'type' => Domain::TYPE_EXTERNAL, ] ); $this->assertFalse($domain->isLdapReady()); + // Fake the queue, assert that no jobs were pushed... + Queue::fake(); + Queue::assertNothingPushed(); + $job = new DomainCreate($domain); $job->handle(); $this->assertTrue($domain->fresh()->isLdapReady()); + + Queue::assertPushed(\App\Jobs\DomainVerify::class, 1); + + Queue::assertPushed( + \App\Jobs\DomainVerify::class, + function ($job) use ($domain) { + $job_domain = TestCase::getObjectProperty($job, 'domain'); + + return $job_domain->id === $domain->id && + $job_domain->namespace === $domain->namespace; + } + ); } }