. */ namespace Tests\Feature; use App\Account; use App\Space; use Carbon\Carbon; use Tests\TestCase; class ApiSpaceWithMiddlewareTest extends TestCase { protected $method = 'POST'; protected $route = '/api/spaces'; protected $accountRoute = '/api/accounts'; public function testExpiredSpace() { $superAdmin = Account::factory()->superAdmin()->create(); $superAdmin->generateUserApiKey(); $username = 'username'; $space = Space::factory()->secondDomain()->expired()->create(); $admin = Account::factory()->fromSpace($space)->admin()->create(); // Try to create a new user as an admin $admin->generateUserApiKey(); config()->set('app.sip_domain', $space->domain); $this->keyAuthenticated($admin) ->json($this->method, 'http://' . $admin->domain . $this->accountRoute, [ 'username' => 'new', 'algorithm' => 'SHA-256', 'password' => '123456', ])->assertStatus(403); // Unexpire the space and try again config()->set('app.sip_domain', $superAdmin->domain); $space = $this->keyAuthenticated($superAdmin) ->get($this->route . '/' . $admin->domain) ->json(); $space['expire_at'] = Carbon::tomorrow()->toDateTimeString(); $this->keyAuthenticated($superAdmin) ->json('PUT', $this->route . '/' . $admin->domain, $space) ->assertStatus(200); $this->keyAuthenticated($admin) ->json($this->method, $this->accountRoute, [ 'username' => 'new', 'algorithm' => 'SHA-256', 'password' => '123456', ])->assertStatus(200); } }