Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/Admin/UsersTest.php
Show First 20 Lines • Show All 276 Lines • ▼ Show 20 Lines | public function testIndex(): void | ||||
$this->assertTrue($json['list'][0]['isDeleted']); | $this->assertTrue($json['list'][0]['isDeleted']); | ||||
} | } | ||||
/** | /** | ||||
* Test reseting 2FA (POST /api/v4/users/<user-id>/reset2FA) | * Test reseting 2FA (POST /api/v4/users/<user-id>/reset2FA) | ||||
*/ | */ | ||||
public function testReset2FA(): void | public function testReset2FA(): void | ||||
{ | { | ||||
Queue::fake(); | |||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
$sku2fa = Sku::withEnvTenantContext()->where(['title' => '2fa'])->first(); | $sku2fa = Sku::withEnvTenantContext()->where(['title' => '2fa'])->first(); | ||||
$user->assignSku($sku2fa); | $user->assignSku($sku2fa); | ||||
SecondFactor::seed('userscontrollertest1@userscontroller.com'); | SecondFactor::seed('userscontrollertest1@userscontroller.com'); | ||||
// Test unauthorized access to admin API | // Test unauthorized access to admin API | ||||
Show All 19 Lines | public function testReset2FA(): void | ||||
$entitlements = $user->fresh()->entitlements()->where('sku_id', $sku2fa->id)->get(); | $entitlements = $user->fresh()->entitlements()->where('sku_id', $sku2fa->id)->get(); | ||||
$this->assertCount(0, $entitlements); | $this->assertCount(0, $entitlements); | ||||
$sf = new SecondFactor($user); | $sf = new SecondFactor($user); | ||||
$this->assertCount(0, $sf->factors()); | $this->assertCount(0, $sf->factors()); | ||||
} | } | ||||
/** | /** | ||||
* Test adding beta SKU (POST /api/v4/users/<user-id>/skus/beta) | |||||
*/ | |||||
public function testAddBetaSku(): void | |||||
{ | |||||
Queue::fake(); | |||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | |||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | |||||
$sku = Sku::withEnvTenantContext()->where(['title' => 'beta'])->first(); | |||||
// Test unauthorized access to admin API | |||||
$response = $this->actingAs($user)->post("/api/v4/users/{$user->id}/skus/beta", []); | |||||
$response->assertStatus(403); | |||||
// For now we allow only the beta sku | |||||
$response = $this->actingAs($admin)->post("/api/v4/users/{$user->id}/skus/mailbox", []); | |||||
$response->assertStatus(404); | |||||
$entitlements = $user->entitlements()->where('sku_id', $sku->id)->get(); | |||||
$this->assertCount(0, $entitlements); | |||||
// Test adding the beta sku | |||||
$response = $this->actingAs($admin)->post("/api/v4/users/{$user->id}/skus/beta", []); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertSame("The subscription added successfully.", $json['message']); | |||||
$this->assertSame(0, $json['sku']['cost']); | |||||
$this->assertSame($sku->id, $json['sku']['id']); | |||||
$this->assertSame($sku->name, $json['sku']['name']); | |||||
$this->assertCount(3, $json); | |||||
$entitlements = $user->entitlements()->where('sku_id', $sku->id)->get(); | |||||
$this->assertCount(1, $entitlements); | |||||
// Test adding the beta sku again, expect an error | |||||
$response = $this->actingAs($admin)->post("/api/v4/users/{$user->id}/skus/beta", []); | |||||
$response->assertStatus(422); | |||||
$json = $response->json(); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertSame("The subscription already exists.", $json['message']); | |||||
$this->assertCount(2, $json); | |||||
$entitlements = $user->entitlements()->where('sku_id', $sku->id)->get(); | |||||
$this->assertCount(1, $entitlements); | |||||
} | |||||
/** | |||||
* Test user creation (POST /api/v4/users) | * Test user creation (POST /api/v4/users) | ||||
*/ | */ | ||||
public function testStore(): void | public function testStore(): void | ||||
{ | { | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
// The end-point does not exist | // The end-point does not exist | ||||
$response = $this->actingAs($admin)->post("/api/v4/users", []); | $response = $this->actingAs($admin)->post("/api/v4/users", []); | ||||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |