Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/Reseller/InvitationsTest.php
Show All 13 Lines | class InvitationsTest extends TestCase | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
SignupInvitation::truncate(); | SignupInvitation::truncate(); | ||||
\config(['app.tenant_id' => 1]); | |||||
self::useResellerUrl(); | self::useResellerUrl(); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
SignupInvitation::truncate(); | SignupInvitation::truncate(); | ||||
\config(['app.tenant_id' => 1]); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test deleting invitations (DELETE /api/v4/invitations/<id>) | * Test deleting invitations (DELETE /api/v4/invitations/<id>) | ||||
*/ | */ | ||||
public function testDestroy(): void | public function testDestroy(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$reseller = $this->getTestUser('reseller@reseller.com'); | $reseller = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
$reseller2 = $this->getTestUser('reseller@kolabnow.com'); | $reseller2 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$tenant = Tenant::where('title', 'Sample Tenant')->first(); | |||||
\config(['app.tenant_id' => $tenant->id]); | |||||
$inv = SignupInvitation::create(['email' => 'email1@ext.com']); | $inv = SignupInvitation::create(['email' => 'email1@ext.com']); | ||||
$inv->tenant_id = $reseller->tenant_id; | |||||
$inv->save(); | |||||
// Non-admin user | // Non-admin user | ||||
$response = $this->actingAs($user)->delete("api/v4/invitations/{$inv->id}"); | $response = $this->actingAs($user)->delete("api/v4/invitations/{$inv->id}"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Admin user | // Admin user | ||||
$response = $this->actingAs($admin)->delete("api/v4/invitations/{$inv->id}"); | $response = $this->actingAs($admin)->delete("api/v4/invitations/{$inv->id}"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Reseller user, but different tenant | // Reseller user, but different tenant | ||||
$response = $this->actingAs($reseller2)->delete("api/v4/invitations/{$inv->id}"); | $response = $this->actingAs($reseller2)->delete("api/v4/invitations/{$inv->id}"); | ||||
$response->assertStatus(403); | $response->assertStatus(404); | ||||
// Reseller - non-existing invitation identifier | // Reseller - non-existing invitation identifier | ||||
$response = $this->actingAs($reseller)->delete("api/v4/invitations/abd"); | $response = $this->actingAs($reseller)->delete("api/v4/invitations/abd"); | ||||
$response->assertStatus(404); | $response->assertStatus(404); | ||||
// Reseller - existing invitation | // Reseller - existing invitation | ||||
$response = $this->actingAs($reseller)->delete("api/v4/invitations/{$inv->id}"); | $response = $this->actingAs($reseller)->delete("api/v4/invitations/{$inv->id}"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
Show All 9 Lines | class InvitationsTest extends TestCase | ||||
* Test listing invitations (GET /api/v4/invitations) | * Test listing invitations (GET /api/v4/invitations) | ||||
*/ | */ | ||||
public function testIndex(): void | public function testIndex(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$reseller = $this->getTestUser('reseller@reseller.com'); | $reseller = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
$reseller2 = $this->getTestUser('reseller@kolabnow.com'); | $reseller2 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$tenant = Tenant::where('title', 'Sample Tenant')->first(); | $tenant = Tenant::where('title', 'Sample Tenant')->first(); | ||||
\config(['app.tenant_id' => $tenant->id]); | |||||
// Non-admin user | // Non-admin user | ||||
$response = $this->actingAs($user)->get("api/v4/invitations"); | $response = $this->actingAs($user)->get("api/v4/invitations"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Admin user | // Admin user | ||||
$response = $this->actingAs($admin)->get("api/v4/invitations"); | $response = $this->actingAs($admin)->get("api/v4/invitations"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
Show All 23 Lines | public function testIndex(): void | ||||
$i8 = SignupInvitation::create(['email' => 'email8@other.com']); | $i8 = SignupInvitation::create(['email' => 'email8@other.com']); | ||||
$i9 = SignupInvitation::create(['email' => 'email9@other.com']); | $i9 = SignupInvitation::create(['email' => 'email9@other.com']); | ||||
$i10 = SignupInvitation::create(['email' => 'email10@other.com']); | $i10 = SignupInvitation::create(['email' => 'email10@other.com']); | ||||
$i11 = SignupInvitation::create(['email' => 'email11@other.com']); | $i11 = SignupInvitation::create(['email' => 'email11@other.com']); | ||||
$i12 = SignupInvitation::create(['email' => 'email12@test.com']); | $i12 = SignupInvitation::create(['email' => 'email12@test.com']); | ||||
$i13 = SignupInvitation::create(['email' => 'email13@ext.com']); | $i13 = SignupInvitation::create(['email' => 'email13@ext.com']); | ||||
SignupInvitation::query()->update(['created_at' => now()->subDays('1')]); | SignupInvitation::query()->update(['created_at' => now()->subDays('1')]); | ||||
SignupInvitation::where('id', $i1->id) | SignupInvitation::where('id', $i1->id) | ||||
->update(['created_at' => now()->subHours('2'), 'status' => SignupInvitation::STATUS_FAILED]); | ->update(['created_at' => now()->subHours('2'), 'status' => SignupInvitation::STATUS_FAILED]); | ||||
SignupInvitation::where('id', $i2->id) | SignupInvitation::where('id', $i2->id) | ||||
->update(['created_at' => now()->subHours('3'), 'status' => SignupInvitation::STATUS_SENT]); | ->update(['created_at' => now()->subHours('3'), 'status' => SignupInvitation::STATUS_SENT]); | ||||
SignupInvitation::where('id', $i11->id)->update(['created_at' => now()->subDays('3')]); | SignupInvitation::where('id', $i11->id)->update(['created_at' => now()->subDays('3')]); | ||||
SignupInvitation::where('id', $i12->id)->update(['tenant_id' => 1]); | SignupInvitation::where('id', $i12->id)->update(['tenant_id' => \config('app.tenant_id')]); | ||||
SignupInvitation::where('id', $i13->id)->update(['tenant_id' => 1]); | SignupInvitation::where('id', $i13->id)->update(['tenant_id' => \config('app.tenant_id')]); | ||||
$response = $this->actingAs($reseller)->get("api/v4/invitations"); | $response = $this->actingAs($reseller)->get("api/v4/invitations"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame(10, $json['count']); | $this->assertSame(10, $json['count']); | ||||
$this->assertSame(1, $json['page']); | $this->assertSame(1, $json['page']); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | class InvitationsTest extends TestCase | ||||
* Test resending invitations (POST /api/v4/invitations/<id>/resend) | * Test resending invitations (POST /api/v4/invitations/<id>/resend) | ||||
*/ | */ | ||||
public function testResend(): void | public function testResend(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$reseller = $this->getTestUser('reseller@reseller.com'); | $reseller = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
$reseller2 = $this->getTestUser('reseller@kolabnow.com'); | $reseller2 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$tenant = Tenant::where('title', 'Sample Tenant')->first(); | $tenant = Tenant::where('title', 'Sample Tenant')->first(); | ||||
\config(['app.tenant_id' => $tenant->id]); | |||||
$inv = SignupInvitation::create(['email' => 'email1@ext.com']); | $inv = SignupInvitation::create(['email' => 'email1@ext.com']); | ||||
$inv->tenant_id = $reseller->tenant_id; | |||||
$inv->save(); | |||||
SignupInvitation::where('id', $inv->id)->update(['status' => SignupInvitation::STATUS_FAILED]); | SignupInvitation::where('id', $inv->id)->update(['status' => SignupInvitation::STATUS_FAILED]); | ||||
// Non-admin user | // Non-admin user | ||||
$response = $this->actingAs($user)->post("api/v4/invitations/{$inv->id}/resend"); | $response = $this->actingAs($user)->post("api/v4/invitations/{$inv->id}/resend"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Admin user | // Admin user | ||||
$response = $this->actingAs($admin)->post("api/v4/invitations/{$inv->id}/resend"); | $response = $this->actingAs($admin)->post("api/v4/invitations/{$inv->id}/resend"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Reseller user, but different tenant | // Reseller user, but different tenant | ||||
$response = $this->actingAs($reseller2)->post("api/v4/invitations/{$inv->id}/resend"); | $response = $this->actingAs($reseller2)->post("api/v4/invitations/{$inv->id}/resend"); | ||||
$response->assertStatus(403); | $response->assertStatus(404); | ||||
// Reseller - non-existing invitation identifier | // Reseller - non-existing invitation identifier | ||||
$response = $this->actingAs($reseller)->post("api/v4/invitations/abd/resend"); | $response = $this->actingAs($reseller)->post("api/v4/invitations/abd/resend"); | ||||
$response->assertStatus(404); | $response->assertStatus(404); | ||||
// Reseller - existing invitation | // Reseller - existing invitation | ||||
$response = $this->actingAs($reseller)->post("api/v4/invitations/{$inv->id}/resend"); | $response = $this->actingAs($reseller)->post("api/v4/invitations/{$inv->id}/resend"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
Show All 9 Lines | class InvitationsTest extends TestCase | ||||
* Test creating invitations (POST /api/v4/invitations) | * Test creating invitations (POST /api/v4/invitations) | ||||
*/ | */ | ||||
public function testStore(): void | public function testStore(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$reseller = $this->getTestUser('reseller@reseller.com'); | $reseller = $this->getTestUser('reseller@sample-tenant.dev-local'); | ||||
$reseller2 = $this->getTestUser('reseller@kolabnow.com'); | $reseller2 = $this->getTestUser('reseller@' . \config('app.domain')); | ||||
$tenant = Tenant::where('title', 'Sample Tenant')->first(); | $tenant = Tenant::where('title', 'Sample Tenant')->first(); | ||||
\config(['app.tenant_id' => $tenant->id]); | |||||
// Non-admin user | // Non-admin user | ||||
$response = $this->actingAs($user)->post("api/v4/invitations", []); | $response = $this->actingAs($user)->post("api/v4/invitations", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Admin user | // Admin user | ||||
$response = $this->actingAs($admin)->post("api/v4/invitations", []); | $response = $this->actingAs($admin)->post("api/v4/invitations", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |