refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
23
tests/Traits/ApiSignIn.php
Normal file
23
tests/Traits/ApiSignIn.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Traits;
|
||||
|
||||
use App\Models\User\User;
|
||||
use Laravel\Passport\Passport;
|
||||
|
||||
trait ApiSignIn
|
||||
{
|
||||
/**
|
||||
* Create a user and sign in as that user.
|
||||
*
|
||||
* @param null $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function signIn()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
Passport::actingAs($user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
78
tests/Traits/Asserts.php
Normal file
78
tests/Traits/Asserts.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Traits;
|
||||
|
||||
use Illuminate\Testing\TestResponse;
|
||||
|
||||
trait Asserts
|
||||
{
|
||||
/**
|
||||
* Test that the response contains a not found notification.
|
||||
*
|
||||
* @param TestResponse $response
|
||||
*/
|
||||
public function expectNotFound(TestResponse $response)
|
||||
{
|
||||
$response->assertStatus(404);
|
||||
|
||||
$response->assertJson([
|
||||
'error' => [
|
||||
'message' => 'The resource has not been found',
|
||||
'error_code' => 31,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the response contains a not authorized notification.
|
||||
*
|
||||
* @param TestResponse $response
|
||||
*/
|
||||
public function expectNotAuthorized(TestResponse $response)
|
||||
{
|
||||
$response->assertStatus(401);
|
||||
|
||||
$response->assertJson([
|
||||
'error' => [
|
||||
'message' => 'Not authorized',
|
||||
'error_code' => 42,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the response contains a data error notification.
|
||||
*
|
||||
* @param TestResponse $response
|
||||
* @param string|array $message
|
||||
*/
|
||||
public function expectDataError(TestResponse $response, $message = '')
|
||||
{
|
||||
$response->assertStatus(422);
|
||||
|
||||
$response->assertJson([
|
||||
'error' => [
|
||||
'message' => $message,
|
||||
'error_code' => 32,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the response contains an invalid parameter notification.
|
||||
*
|
||||
* @param TestResponse $response
|
||||
* @param string|array $message
|
||||
*/
|
||||
public function expectInvalidParameter(TestResponse $response, $message = '')
|
||||
{
|
||||
$response->assertStatus(422);
|
||||
|
||||
$response->assertJson([
|
||||
'error' => [
|
||||
'message' => $message,
|
||||
'error_code' => 41,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
30
tests/Traits/CreatesApplication.php
Normal file
30
tests/Traits/CreatesApplication.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
|
||||
trait CreatesApplication
|
||||
{
|
||||
/**
|
||||
* Creates the application.
|
||||
*
|
||||
* @return \Illuminate\Foundation\Application
|
||||
*/
|
||||
public function createApplication()
|
||||
{
|
||||
$app = require __DIR__.'/../../bootstrap/app.php';
|
||||
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
|
||||
App::setLocale('en');
|
||||
|
||||
// set the bcrypt hashing rounds (the minimum allowed).
|
||||
// this reduces the amount of cycles needed to manage users.
|
||||
Hash::setRounds(4);
|
||||
|
||||
return $app;
|
||||
}
|
||||
}
|
||||
33
tests/Traits/SignIn.php
Normal file
33
tests/Traits/SignIn.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Traits;
|
||||
|
||||
use App\Models\User\User;
|
||||
use App\Services\User\AcceptPolicy;
|
||||
|
||||
trait SignIn
|
||||
{
|
||||
/**
|
||||
* Create a user and sign in as that user. If a user
|
||||
* object is passed, then sign in as that user.
|
||||
*
|
||||
* @param null $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function signIn($user = null)
|
||||
{
|
||||
if (is_null($user)) {
|
||||
$user = factory(User::class)->create();
|
||||
$user->account->populateDefaultFields();
|
||||
app(AcceptPolicy::class)->execute([
|
||||
'account_id' => $user->account_id,
|
||||
'user_id' => $user->id,
|
||||
'ip_address' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->be($user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user