flexisip-account-manager/flexiapi/tests/Feature/AccountApiTest.php
Timothée Jaussoin 30fcf9792f Update wording
Send a confirmation email when the password is set for the first time
Remove the API link from the menu and move it to the footer
Allow different domains to be set in the POST /api/accounts endpoints + related tests
Cleanup the API tests
Update the dependencies
2020-09-14 11:55:07 +02:00

124 lines
3.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Password;
use App\Admin;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class AccountApiTest extends TestCase
{
use RefreshDatabase;
protected $route = '/api/accounts';
protected $method = 'POST';
public function testMandatoryFrom()
{
$password = factory(Password::class)->create();
$response = $this->json($this->method, $this->route);
$response->assertStatus(422);
}
public function testNotAdminForbidden()
{
$password = factory(Password::class)->create();
$response0 = $this->generateFirstResponse($password);
$response1 = $this->generateSecondResponse($password, $response0)
->json($this->method, $this->route);
$response1->assertStatus(403);
}
public function testAdminOk()
{
$admin = factory(Admin::class)->create();
$password = $admin->account->passwords()->first();
$username = 'foobar';
$response0 = $this->generateFirstResponse($password);
$response1 = $this->generateSecondResponse($password, $response0)
->json($this->method, $this->route, [
'username' => $username,
'algorithm' => 'SHA-256',
'password' => '123456',
]);
$response1
->assertStatus(200)
->assertJson([
'id' => 2,
'username' => $username
]);
}
public function testDomain()
{
$admin = factory(Admin::class)->create();
$password = $admin->account->passwords()->first();
$username = 'foobar';
$domain = 'example.com';
$response0 = $this->generateFirstResponse($password);
$response1 = $this->generateSecondResponse($password, $response0)
->json($this->method, $this->route, [
'username' => $username,
'domain' => $domain,
'algorithm' => 'SHA-256',
'password' => '123456',
]);
$response1
->assertStatus(200)
->assertJson([
'id' => 2,
'username' => $username,
'domain' => $domain,
]);
}
public function testUsernameNoDomain()
{
$admin = factory(Admin::class)->create();
$password = $admin->account->passwords()->first();
$username = 'username';
$response0 = $this->generateFirstResponse($password);
$response1 = $this->generateSecondResponse($password, $response0)
->json($this->method, $this->route, [
'username' => $username,
'algorithm' => 'SHA-256',
'password' => '123456',
]);
$response1
->assertStatus(200)
->assertJson([
'id' => 2,
'username' => $username,
'domain' => config('app.sip_domain'),
]);
}
public function testUsernameEmpty()
{
$admin = factory(Admin::class)->create();
$password = $admin->account->passwords()->first();
$username = 'username';
$response0 = $this->generateFirstResponse($password);
$response1 = $this->generateSecondResponse($password, $response0)
->json($this->method, $this->route, [
'username' => '',
'algorithm' => 'SHA-256',
'password' => '2',
]);
$response1->assertStatus(422);
}
}