2019-03-26 06:00:15 +01:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-14 13:11:46 +02:00
|
|
|
*
|
2022-06-21 11:57:17 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-09-14 13:11:46 +02:00
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2019-03-26 06:00:15 +01:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
2024-01-09 11:49:29 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
use App\Models\User;
|
2019-04-24 02:22:02 +02:00
|
|
|
use App\Models\Client;
|
2024-01-09 11:49:29 +01:00
|
|
|
use App\Models\Credit;
|
|
|
|
use App\Models\Account;
|
2019-03-27 05:50:13 +01:00
|
|
|
use App\Models\Company;
|
2024-01-09 11:49:29 +01:00
|
|
|
use App\Models\Currency;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Illuminate\Support\Str;
|
2020-03-01 06:00:54 +01:00
|
|
|
use App\Models\CompanyToken;
|
2024-04-02 02:28:42 +02:00
|
|
|
use App\Models\GroupSetting;
|
2024-01-09 11:49:29 +01:00
|
|
|
use App\Models\ClientContact;
|
2019-03-27 07:22:27 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2024-04-02 02:28:42 +02:00
|
|
|
use Tests\Unit\GroupSettingsTest;
|
2024-01-09 11:49:29 +01:00
|
|
|
use App\DataMapper\ClientSettings;
|
|
|
|
use App\DataMapper\CompanySettings;
|
|
|
|
use App\DataMapper\DefaultSettings;
|
|
|
|
use App\Factory\InvoiceItemFactory;
|
2024-04-02 02:28:42 +02:00
|
|
|
use App\Factory\GroupSettingFactory;
|
2019-03-26 22:17:28 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2019-03-26 06:00:15 +01:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2020-05-14 11:08:49 +02:00
|
|
|
use Illuminate\Validation\ValidationException;
|
2024-01-09 11:49:29 +01:00
|
|
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2019-03-26 06:00:15 +01:00
|
|
|
|
2019-04-20 01:02:49 +02:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Http\Controllers\ClientController
|
|
|
|
*/
|
2019-03-26 06:00:15 +01:00
|
|
|
class ClientTest extends TestCase
|
|
|
|
{
|
2019-03-27 07:22:27 +01:00
|
|
|
use MakesHash;
|
2019-04-24 12:01:40 +02:00
|
|
|
use DatabaseTransactions;
|
2020-05-14 11:08:49 +02:00
|
|
|
use MockAccountData;
|
2019-03-26 06:00:15 +01:00
|
|
|
|
2023-08-09 02:47:50 +02:00
|
|
|
public $faker;
|
|
|
|
|
2024-01-10 00:07:56 +01:00
|
|
|
public $client_id;
|
|
|
|
|
2022-06-21 12:00:57 +02:00
|
|
|
protected function setUp() :void
|
2019-03-26 06:00:15 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2019-03-26 06:00:15 +01:00
|
|
|
Session::start();
|
|
|
|
|
2019-03-26 22:17:28 +01:00
|
|
|
$this->faker = \Faker\Factory::create();
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2019-03-26 22:17:28 +01:00
|
|
|
Model::reguard();
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2020-03-01 06:00:54 +01:00
|
|
|
$this->withoutExceptionHandling();
|
|
|
|
|
2020-03-02 11:22:37 +01:00
|
|
|
Client::reguard();
|
|
|
|
ClientContact::reguard();
|
2020-03-16 11:12:10 +01:00
|
|
|
|
|
|
|
$this->withoutMiddleware(
|
|
|
|
ThrottleRequests::class
|
|
|
|
);
|
2020-05-14 11:08:49 +02:00
|
|
|
|
|
|
|
$this->makeTestData();
|
2019-03-26 06:00:15 +01:00
|
|
|
}
|
|
|
|
|
2024-04-02 02:28:42 +02:00
|
|
|
public function testBulkGroupAssignment()
|
|
|
|
{
|
|
|
|
Client::factory()->count(5)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) {
|
|
|
|
ClientContact::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'client_id' => $c->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'is_primary' => 1,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$gs = GroupSettingFactory::create($this->company->id, $this->user->id);
|
|
|
|
$gs->name = 'testtest';
|
|
|
|
$gs->save();
|
|
|
|
|
|
|
|
$ids = Client::where('company_id', $this->company->id)->get()->pluck('hashed_id')->toArray();
|
|
|
|
$data = [
|
|
|
|
'action' => 'assign_group',
|
|
|
|
'ids' => $ids,
|
|
|
|
'group_settings_id' => $gs->hashed_id,
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/clients/bulk', $data);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
|
|
|
|
Client::query()->whereIn('id', $this->transformKeys($ids))->cursor()->each(function ($c) use ($gs, $arr) {
|
|
|
|
$this->assertEquals($gs->id, $c->group_settings_id);
|
|
|
|
});
|
|
|
|
|
|
|
|
foreach($arr['data'] as $client_response){
|
|
|
|
|
|
|
|
$this->assertEquals($gs->hashed_id, $client_response['group_settings_id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-09 11:49:29 +01:00
|
|
|
public function testClientExchangeRateCalculation()
|
|
|
|
{
|
|
|
|
$settings = ClientSettings::defaults();
|
|
|
|
$settings->currency_id = 12;
|
|
|
|
|
|
|
|
$c = Client::factory()
|
|
|
|
->create([
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'settings' => $settings
|
|
|
|
]);
|
|
|
|
|
|
|
|
$settings = $this->company->settings;
|
|
|
|
$settings->currency_id = '3';
|
|
|
|
|
|
|
|
$this->company->saveSettings($settings, $this->company);
|
|
|
|
|
|
|
|
$client_exchange_rate = round($c->setExchangeRate(),2);
|
|
|
|
|
|
|
|
$aud_currency = Currency::find(12);
|
|
|
|
$eur_currency = Currency::find(3);
|
|
|
|
|
|
|
|
$synthetic_exchange = $aud_currency->exchange_rate / $eur_currency->exchange_rate;
|
|
|
|
|
|
|
|
$this->assertEquals($client_exchange_rate, round($synthetic_exchange,2));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-12-15 23:40:13 +01:00
|
|
|
public function testStoreClientFixes2()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
"contacts" => [
|
|
|
|
[
|
|
|
|
"email" => "tenda@gmail.com",
|
|
|
|
"first_name" => "Tenda",
|
|
|
|
"last_name" => "Bavuma",
|
|
|
|
],
|
|
|
|
],
|
|
|
|
"name" => "Tenda Bavuma",
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->postJson('/api/v1/clients', $data);
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$arr = $response->json();
|
|
|
|
|
|
|
|
$this->assertTrue($arr['data']['contacts'][0]['is_primary']);
|
|
|
|
$this->assertTrue($arr['data']['contacts'][0]['send_email']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-18 06:54:55 +02:00
|
|
|
public function testStoreClientFixes()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
"contacts" => [
|
|
|
|
[
|
2023-11-26 08:41:42 +01:00
|
|
|
"email" => "tenda@gmail.com",
|
|
|
|
"first_name" => "Tenda",
|
|
|
|
"is_primary" => true,
|
|
|
|
"last_name" => "Bavuma",
|
|
|
|
"password" => null,
|
|
|
|
"send_email" => true
|
2023-10-18 06:54:55 +02:00
|
|
|
],
|
2023-11-26 08:41:42 +01:00
|
|
|
],
|
|
|
|
"country_id" => "356",
|
|
|
|
"display_name" => "Tenda Bavuma",
|
|
|
|
"name" => "Tenda Bavuma",
|
|
|
|
"shipping_country_id" => "356",
|
2023-10-18 06:54:55 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->postJson('/api/v1/clients', $data);
|
2023-10-18 06:54:55 +02:00
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
$response->assertStatus(200);
|
2023-10-18 06:54:55 +02:00
|
|
|
}
|
|
|
|
|
2023-02-17 00:17:05 +01:00
|
|
|
public function testClientMergeContactDrop()
|
|
|
|
{
|
|
|
|
|
|
|
|
$c = Client::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id]);
|
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
ClientContact::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'client_id' => $c->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'is_primary' => 1,
|
|
|
|
]);
|
2023-02-17 00:17:05 +01:00
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
ClientContact::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'client_id' => $c->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
2023-02-17 00:17:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
$c1 = Client::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id]);
|
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
ClientContact::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'client_id' => $c1->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'is_primary' => 1,
|
|
|
|
]);
|
|
|
|
|
|
|
|
ClientContact::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'client_id' => $c1->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
ClientContact::factory()->create([
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
'client_id' => $c1->id,
|
|
|
|
'company_id' => $this->company->id,
|
|
|
|
'email' => ''
|
|
|
|
]);
|
2023-02-17 00:17:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(2, $c->contacts->count());
|
|
|
|
$this->assertEquals(3, $c1->contacts->count());
|
|
|
|
|
|
|
|
$c->service()->merge($c1);
|
|
|
|
|
|
|
|
$c = $c->fresh();
|
|
|
|
|
2023-08-06 09:35:19 +02:00
|
|
|
// nlog($c->contacts->pluck('email'));
|
2023-02-17 00:17:05 +01:00
|
|
|
|
|
|
|
$this->assertEquals(4, $c->contacts->count());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-08-22 00:48:52 +02:00
|
|
|
private function buildLineItems($number = 2)
|
2022-08-22 00:24:36 +02:00
|
|
|
{
|
|
|
|
$line_items = [];
|
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
for ($x=0; $x<$number; $x++) {
|
2022-08-22 00:48:52 +02:00
|
|
|
$item = InvoiceItemFactory::create();
|
|
|
|
$item->quantity = 1;
|
|
|
|
$item->cost = 10;
|
2022-08-22 00:24:36 +02:00
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
$line_items[] = $item;
|
2022-08-22 00:48:52 +02:00
|
|
|
}
|
2022-08-22 00:24:36 +02:00
|
|
|
|
|
|
|
return $line_items;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreditBalance()
|
|
|
|
{
|
|
|
|
$this->client->credit_balance = 0;
|
|
|
|
$this->client->save();
|
|
|
|
|
|
|
|
$this->assertEquals(0, $this->client->credit_balance);
|
|
|
|
|
|
|
|
$credit = [
|
|
|
|
'status_id' => 1,
|
|
|
|
'number' => 'dfdfd',
|
|
|
|
'discount' => 0,
|
|
|
|
'is_amount_discount' => 1,
|
|
|
|
'number' => '34343xx43',
|
|
|
|
'public_notes' => 'notes',
|
|
|
|
'is_deleted' => 0,
|
|
|
|
'custom_value1' => 0,
|
|
|
|
'custom_value2' => 0,
|
|
|
|
'custom_value3' => 0,
|
|
|
|
'custom_value4' => 0,
|
|
|
|
'status' => 1,
|
|
|
|
'client_id' => $this->encodePrimaryKey($this->client->id),
|
|
|
|
'line_items' => $this->buildLineItems()
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/credits/', $credit)
|
|
|
|
->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
|
|
|
|
$credit_id = $arr['data']['id'];
|
|
|
|
|
|
|
|
$credit = Credit::find($this->decodePrimaryKey($credit_id));
|
|
|
|
|
|
|
|
$this->assertNotNull($credit);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $credit->balance);
|
|
|
|
|
|
|
|
$credit->service()->markSent()->save();
|
|
|
|
|
|
|
|
$this->assertEquals(20, $credit->balance);
|
|
|
|
$this->assertEquals(20, $credit->client->fresh()->credit_balance);
|
|
|
|
|
2022-08-22 00:48:52 +02:00
|
|
|
//lets now update the credit and increase its balance, this should also increase the credit balance
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'number' => 'dfdfd',
|
|
|
|
'discount' => 0,
|
|
|
|
'is_amount_discount' => 1,
|
|
|
|
'number' => '34343xx43',
|
|
|
|
'public_notes' => 'notes',
|
|
|
|
'is_deleted' => 0,
|
|
|
|
'custom_value1' => 0,
|
|
|
|
'custom_value2' => 0,
|
|
|
|
'custom_value3' => 0,
|
|
|
|
'custom_value4' => 0,
|
|
|
|
'status' => 1,
|
|
|
|
'client_id' => $this->encodePrimaryKey($this->client->id),
|
|
|
|
'line_items' => $this->buildLineItems(3)
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->put('/api/v1/credits/'.$credit->hashed_id, $data)
|
|
|
|
->assertStatus(200);
|
|
|
|
|
|
|
|
$credit = $credit->fresh();
|
|
|
|
|
|
|
|
$this->assertEquals(30, $credit->balance);
|
|
|
|
$this->assertEquals(30, $credit->client->fresh()->credit_balance);
|
2022-08-22 00:24:36 +02:00
|
|
|
}
|
|
|
|
|
2020-07-02 12:55:31 +02:00
|
|
|
public function testStoreClientUsingCountryCode()
|
2019-03-26 12:31:07 +01:00
|
|
|
{
|
2020-07-02 12:55:31 +02:00
|
|
|
$data = [
|
|
|
|
'name' => 'Country Code Name',
|
|
|
|
'country_code' => 'US',
|
|
|
|
'currency_code' => 'USD',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/clients/', $data);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
$client = Client::find($this->decodePrimaryKey($arr['data']['id']));
|
|
|
|
|
|
|
|
$this->assertEquals(840, $client->country_id);
|
|
|
|
$this->assertEquals(1, $client->settings->currency_id);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'name' => 'Country Code Name',
|
|
|
|
'country_code' => 'USA',
|
|
|
|
'currency_code' => 'USD',
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/clients/', $data);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
$client = Client::find($this->decodePrimaryKey($arr['data']['id']));
|
2019-03-26 22:17:28 +01:00
|
|
|
|
2020-07-02 12:55:31 +02:00
|
|
|
$this->assertEquals(840, $client->country_id);
|
|
|
|
$this->assertEquals(1, $client->settings->currency_id);
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2020-07-02 12:55:31 +02:00
|
|
|
$data = [
|
|
|
|
'name' => 'Country Code Name',
|
|
|
|
'country_code' => 'AU',
|
|
|
|
'currency_code' => 'AUD',
|
|
|
|
];
|
2019-03-26 12:31:07 +01:00
|
|
|
|
2020-07-02 12:55:31 +02:00
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/clients/', $data);
|
2019-03-26 12:31:07 +01:00
|
|
|
|
2020-07-02 12:55:31 +02:00
|
|
|
$arr = $response->json();
|
|
|
|
$client = Client::find($this->decodePrimaryKey($arr['data']['id']));
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2020-07-02 12:55:31 +02:00
|
|
|
$this->assertEquals(36, $client->country_id);
|
|
|
|
$this->assertEquals(12, $client->settings->currency_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testClientList()
|
|
|
|
{
|
2019-03-27 05:50:13 +01:00
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->get('/api/v1/clients');
|
2019-03-27 05:50:13 +01:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
2019-03-26 12:31:07 +01:00
|
|
|
}
|
2019-03-26 06:00:15 +01:00
|
|
|
|
2019-03-27 09:38:01 +01:00
|
|
|
/*
|
|
|
|
* @covers ClientController
|
|
|
|
*/
|
|
|
|
public function testClientRestEndPoints()
|
2019-03-26 06:00:15 +01:00
|
|
|
{
|
2020-10-01 12:49:47 +02:00
|
|
|
Client::factory()->count(3)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) {
|
|
|
|
ClientContact::factory()->create([
|
2020-05-14 11:08:49 +02:00
|
|
|
'user_id' => $this->user->id,
|
2019-03-27 07:22:27 +01:00
|
|
|
'client_id' => $c->id,
|
2020-05-14 11:08:49 +02:00
|
|
|
'company_id' => $this->company->id,
|
2020-09-06 11:38:10 +02:00
|
|
|
'is_primary' => 1,
|
2019-03-27 07:22:27 +01:00
|
|
|
]);
|
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
ClientContact::factory()->count(2)->create([
|
2020-05-14 11:08:49 +02:00
|
|
|
'user_id' => $this->user->id,
|
2019-03-27 07:22:27 +01:00
|
|
|
'client_id' => $c->id,
|
2020-09-06 11:38:10 +02:00
|
|
|
'company_id' => $this->company->id,
|
2019-03-27 07:22:27 +01:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2019-03-27 05:50:13 +01:00
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->get('/api/v1/clients/'.$this->encodePrimaryKey($this->client->id));
|
2019-03-27 07:22:27 +01:00
|
|
|
|
2019-04-03 02:09:22 +02:00
|
|
|
$response->assertStatus(200);
|
2019-03-27 07:22:27 +01:00
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->get('/api/v1/clients/'.$this->encodePrimaryKey($this->client->id).'/edit');
|
2019-03-27 05:50:13 +01:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
2019-03-27 09:38:01 +01:00
|
|
|
|
|
|
|
$client_update = [
|
2020-09-06 11:38:10 +02:00
|
|
|
'name' => 'A Funky Name',
|
2019-03-27 09:38:01 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->put('/api/v1/clients/'.$this->encodePrimaryKey($this->client->id), $client_update)
|
2019-04-03 04:34:28 +02:00
|
|
|
->assertStatus(200);
|
2019-03-27 09:38:01 +01:00
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->delete('/api/v1/clients/'.$this->encodePrimaryKey($this->client->id));
|
2019-03-27 09:38:01 +01:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
2019-04-17 08:20:32 +02:00
|
|
|
|
2019-03-27 22:32:50 +01:00
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
2020-05-14 11:08:49 +02:00
|
|
|
'X-API-TOKEN' => $this->token,
|
2019-03-27 22:32:50 +01:00
|
|
|
])->post('/api/v1/clients/', ['name' => 'New Client'])
|
2019-04-03 04:34:28 +02:00
|
|
|
->assertStatus(200);
|
2019-03-27 22:32:50 +01:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
2020-05-14 11:08:49 +02:00
|
|
|
$this->client->is_deleted = true;
|
|
|
|
$this->client->save();
|
2019-12-30 22:59:12 +01:00
|
|
|
|
|
|
|
$client_update = [
|
2020-09-06 11:38:10 +02:00
|
|
|
'name' => 'Double Funk',
|
2019-12-30 22:59:12 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->put('/api/v1/clients/'.$this->encodePrimaryKey($this->client->id), $client_update)
|
2019-12-30 22:59:12 +01:00
|
|
|
->assertStatus(400);
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2019-04-17 08:20:32 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testDefaultTimeZoneFromClientModel()
|
|
|
|
{
|
2020-10-01 12:49:47 +02:00
|
|
|
$account = Account::factory()->create();
|
|
|
|
$company = Company::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'account_id' => $account->id,
|
|
|
|
]);
|
2019-04-24 12:01:40 +02:00
|
|
|
|
|
|
|
$account->default_company_id = $company->id;
|
|
|
|
$account->save();
|
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$user = User::factory()->create([
|
2020-03-24 10:15:30 +01:00
|
|
|
'account_id' => $account->id,
|
2020-05-14 11:08:49 +02:00
|
|
|
'confirmation_code' => $this->createDbHash(config('database.default')),
|
2020-09-06 11:38:10 +02:00
|
|
|
'email' => 'whiz@gmail.com',
|
2019-04-24 12:01:40 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$userPermissions = collect([
|
2022-06-21 11:57:17 +02:00
|
|
|
'view_invoice',
|
|
|
|
'view_client',
|
|
|
|
'edit_client',
|
|
|
|
'edit_invoice',
|
|
|
|
'create_invoice',
|
|
|
|
'create_client',
|
|
|
|
]);
|
2019-04-24 12:01:40 +02:00
|
|
|
|
|
|
|
$userSettings = DefaultSettings::userSettings();
|
|
|
|
|
|
|
|
$user->companies()->attach($company->id, [
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
2020-03-09 10:38:15 +01:00
|
|
|
'notifications' => CompanySettings::notificationDefaults(),
|
2019-04-24 12:01:40 +02:00
|
|
|
'permissions' => $userPermissions->toJson(),
|
|
|
|
'settings' => json_encode($userSettings),
|
|
|
|
'is_locked' => 0,
|
|
|
|
]);
|
2019-04-24 02:22:02 +02:00
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
Client::factory()->count(3)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company) {
|
|
|
|
ClientContact::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $c->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'is_primary' => 1,
|
|
|
|
]);
|
2019-04-24 02:22:02 +02:00
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
ClientContact::factory()->count(2)->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'user_id' => $user->id,
|
|
|
|
'client_id' => $c->id,
|
|
|
|
'company_id' => $company->id,
|
|
|
|
]);
|
2020-03-21 06:37:30 +01:00
|
|
|
});
|
2019-04-24 02:22:02 +02:00
|
|
|
|
2020-05-14 11:08:49 +02:00
|
|
|
$this->client = Client::whereUserId($user->id)->whereCompanyId($company->id)->first();
|
2019-04-24 02:22:02 +02:00
|
|
|
|
2020-05-14 11:08:49 +02:00
|
|
|
$this->assertNotNull($this->client);
|
2019-04-24 02:22:02 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
/* Make sure we have a valid settings object*/
|
2020-05-14 11:08:49 +02:00
|
|
|
$this->assertEquals($this->client->getSetting('timezone_id'), 1);
|
2019-04-24 03:49:41 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
/* Make sure we are harvesting valid data */
|
2020-05-14 11:08:49 +02:00
|
|
|
$this->assertEquals($this->client->timezone()->name, 'Pacific/Midway');
|
2019-04-24 02:22:02 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
/* Make sure NULL settings return the correct count (0) instead of throwing an exception*/
|
2020-05-14 11:08:49 +02:00
|
|
|
$this->assertEquals($this->client->contacts->count(), 3);
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2021-08-13 10:45:19 +02:00
|
|
|
public function testClientCreationWithIllegalContactObject()
|
|
|
|
{
|
|
|
|
$account = Account::factory()->create();
|
|
|
|
$company = Company::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'account_id' => $account->id,
|
|
|
|
]);
|
2021-08-13 10:45:19 +02:00
|
|
|
|
|
|
|
$account->default_company_id = $company->id;
|
|
|
|
$account->save();
|
|
|
|
|
|
|
|
$user = User::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'account_id' => $account->id,
|
|
|
|
'confirmation_code' => $this->createDbHash(config('database.default')),
|
|
|
|
'email' => 'whiz@gmail.com',
|
2021-08-13 10:45:19 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
]);
|
2021-08-13 10:45:19 +02:00
|
|
|
|
|
|
|
$user->companies()->attach($company->id, [
|
2022-06-21 11:57:17 +02:00
|
|
|
'account_id' => $account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
|
|
|
'notifications' => CompanySettings::notificationDefaults(),
|
|
|
|
'permissions' => '',
|
|
|
|
'settings' => '',
|
|
|
|
'is_locked' => 0,
|
|
|
|
]);
|
2021-08-13 10:45:19 +02:00
|
|
|
|
|
|
|
$company_token = new CompanyToken;
|
|
|
|
$company_token->user_id = $user->id;
|
|
|
|
$company_token->company_id = $company->id;
|
|
|
|
$company_token->account_id = $account->id;
|
|
|
|
$company_token->name = $user->first_name.' '.$user->last_name;
|
|
|
|
$company_token->token = Str::random(64);
|
2021-11-09 23:11:56 +01:00
|
|
|
$company_token->is_system = true;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-08-13 10:45:19 +02:00
|
|
|
$company_token->save();
|
|
|
|
|
|
|
|
$this->token = $company_token->token;
|
|
|
|
|
|
|
|
$data = [
|
2022-06-21 11:57:17 +02:00
|
|
|
'name' => 'A loyal Client',
|
2022-06-21 11:59:36 +02:00
|
|
|
'contacts' => $this->faker->unique()->safeEmail(),
|
2022-06-21 11:57:17 +02:00
|
|
|
];
|
2021-08-13 10:45:19 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
try {
|
2021-08-13 10:45:19 +02:00
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/clients/', $data);
|
|
|
|
} catch (ValidationException $e) {
|
2021-08-13 10:45:19 +02:00
|
|
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
|
|
|
$this->assertNotNull($message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testCreatingClientAndContacts()
|
|
|
|
{
|
2020-10-01 12:49:47 +02:00
|
|
|
$account = Account::factory()->create();
|
|
|
|
$company = Company::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'account_id' => $account->id,
|
|
|
|
]);
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$account->default_company_id = $company->id;
|
|
|
|
$account->save();
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-10-01 12:49:47 +02:00
|
|
|
$user = User::factory()->create([
|
2022-06-21 11:57:17 +02:00
|
|
|
'account_id' => $account->id,
|
|
|
|
'confirmation_code' => $this->createDbHash(config('database.default')),
|
|
|
|
'email' => 'whiz@gmail.com',
|
2020-05-14 11:08:49 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
]);
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$user->companies()->attach($company->id, [
|
2022-06-21 11:57:17 +02:00
|
|
|
'account_id' => $account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
|
|
|
'notifications' => CompanySettings::notificationDefaults(),
|
|
|
|
'permissions' => '',
|
|
|
|
'settings' => '',
|
|
|
|
'is_locked' => 0,
|
|
|
|
]);
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-04-09 12:48:04 +02:00
|
|
|
$company_token = new CompanyToken;
|
|
|
|
$company_token->user_id = $user->id;
|
|
|
|
$company_token->company_id = $company->id;
|
|
|
|
$company_token->account_id = $account->id;
|
2020-09-06 11:38:10 +02:00
|
|
|
$company_token->name = $user->first_name.' '.$user->last_name;
|
2020-04-09 12:48:04 +02:00
|
|
|
$company_token->token = Str::random(64);
|
2021-11-09 23:11:56 +01:00
|
|
|
$company_token->is_system = true;
|
2020-04-09 12:48:04 +02:00
|
|
|
$company_token->save();
|
|
|
|
|
2020-05-14 11:08:49 +02:00
|
|
|
$this->token = $company_token->token;
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$data = [
|
2022-06-21 11:57:17 +02:00
|
|
|
'name' => 'A loyal Client',
|
|
|
|
'contacts' => [
|
2022-06-21 11:59:36 +02:00
|
|
|
['email' => $this->faker->unique()->safeEmail()],
|
2022-06-21 11:57:17 +02:00
|
|
|
],
|
|
|
|
];
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/clients/', $data)
|
2020-03-01 06:00:54 +01:00
|
|
|
->assertStatus(200);
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
// $arr = $response->json();
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$data = [
|
2022-06-21 11:57:17 +02:00
|
|
|
'name' => 'A loyal Client',
|
|
|
|
'contacts' => [
|
|
|
|
[
|
2022-06-21 11:59:36 +02:00
|
|
|
'email' => $this->faker->unique()->safeEmail(),
|
2022-06-21 11:57:17 +02:00
|
|
|
'password' => '*****',
|
2020-09-06 11:38:10 +02:00
|
|
|
],
|
2022-06-21 11:57:17 +02:00
|
|
|
],
|
|
|
|
];
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/clients/', $data)
|
2020-03-01 06:00:54 +01:00
|
|
|
->assertStatus(200);
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$data = [
|
2022-06-21 11:57:17 +02:00
|
|
|
'name' => 'A loyal Client',
|
|
|
|
'contacts' => [
|
|
|
|
[
|
2022-06-21 11:59:36 +02:00
|
|
|
'email' => $this->faker->unique()->safeEmail(),
|
2022-06-21 11:57:17 +02:00
|
|
|
'password' => '1',
|
2020-09-06 11:38:10 +02:00
|
|
|
],
|
2022-06-21 11:57:17 +02:00
|
|
|
],
|
|
|
|
];
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response = null;
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
try {
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/clients/', $data);
|
2020-03-21 06:37:30 +01:00
|
|
|
} catch (ValidationException $e) {
|
|
|
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
|
|
|
$this->assertNotNull($message);
|
|
|
|
}
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$data = [
|
2022-06-21 11:57:17 +02:00
|
|
|
'name' => 'A loyal Client',
|
|
|
|
'contacts' => [
|
|
|
|
[
|
2022-06-21 11:59:36 +02:00
|
|
|
'email' => $this->faker->unique()->safeEmail(),
|
2022-06-21 11:57:17 +02:00
|
|
|
'password' => '1Qajsj...33',
|
2020-09-06 11:38:10 +02:00
|
|
|
],
|
2022-06-21 11:57:17 +02:00
|
|
|
],
|
|
|
|
];
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response = null;
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
try {
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/clients/', $data);
|
2020-03-21 06:37:30 +01:00
|
|
|
} catch (ValidationException $e) {
|
|
|
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
|
|
|
}
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response->assertStatus(200);
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$data = [
|
2022-06-21 11:57:17 +02:00
|
|
|
'name' => 'A loyal Client',
|
|
|
|
'contacts' => [
|
|
|
|
[
|
2022-06-21 11:59:36 +02:00
|
|
|
'email' => $this->faker->unique()->safeEmail(),
|
2022-06-21 11:57:17 +02:00
|
|
|
'password' => '1Qajsj...33',
|
|
|
|
],
|
|
|
|
[
|
2022-06-21 11:59:36 +02:00
|
|
|
'email' => $this->faker->unique()->safeEmail(),
|
2022-06-21 11:57:17 +02:00
|
|
|
'password' => '1234AAAAAaaaaa',
|
2020-09-06 11:38:10 +02:00
|
|
|
],
|
2022-06-21 11:57:17 +02:00
|
|
|
],
|
|
|
|
];
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response = null;
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
try {
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/clients/', $data);
|
2020-03-21 06:37:30 +01:00
|
|
|
} catch (ValidationException $e) {
|
|
|
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
|
|
|
$this->assertNotNull($message);
|
|
|
|
}
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response->assertStatus(200);
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$arr = $response->json();
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-05-14 11:08:49 +02:00
|
|
|
$this->client_id = $arr['data']['id'];
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->put('/api/v1/clients/'.$this->client_id, $data)->assertStatus(200);
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$arr = $response->json();
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2022-06-21 11:59:36 +02:00
|
|
|
$safe_email = $this->faker->unique()->safeEmail();
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$data = [
|
2022-06-21 11:57:17 +02:00
|
|
|
'name' => 'A loyal Client',
|
|
|
|
'contacts' => [
|
|
|
|
[
|
|
|
|
'email' => $safe_email,
|
|
|
|
'password' => '',
|
2020-09-06 11:38:10 +02:00
|
|
|
],
|
2022-06-21 11:57:17 +02:00
|
|
|
],
|
|
|
|
];
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response = null;
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
try {
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/clients/', $data);
|
2020-03-21 06:37:30 +01:00
|
|
|
} catch (ValidationException $e) {
|
|
|
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
|
|
|
$this->assertNotNull($message);
|
|
|
|
}
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response->assertStatus(200);
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$arr = $response->json();
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-05-14 11:08:49 +02:00
|
|
|
$this->client = Client::find($this->decodePrimaryKey($arr['data']['id']));
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-05-14 11:08:49 +02:00
|
|
|
$contact = $this->client->contacts()->whereEmail($safe_email)->first();
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertEquals(0, strlen($contact->password));
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2022-06-21 11:59:36 +02:00
|
|
|
$safe_email = $this->faker->unique()->safeEmail();
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$data = [
|
2022-06-21 11:57:17 +02:00
|
|
|
'name' => 'A loyal Client',
|
|
|
|
'contacts' => [
|
|
|
|
[
|
|
|
|
'email' => $safe_email,
|
|
|
|
'password' => 'AFancyDancy191$Password',
|
2020-09-06 11:38:10 +02:00
|
|
|
],
|
2022-06-21 11:57:17 +02:00
|
|
|
],
|
|
|
|
];
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response = null;
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
try {
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->post('/api/v1/clients/', $data);
|
2020-03-21 06:37:30 +01:00
|
|
|
} catch (ValidationException $e) {
|
|
|
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
|
|
|
$this->assertNotNull($message);
|
|
|
|
}
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response->assertStatus(200);
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$arr = $response->json();
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-05-14 11:08:49 +02:00
|
|
|
$this->client = Client::find($this->decodePrimaryKey($arr['data']['id']));
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-05-14 11:08:49 +02:00
|
|
|
$contact = $this->client->contacts()->whereEmail($safe_email)->first();
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertGreaterThan(1, strlen($contact->password));
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$password = $contact->password;
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$data = [
|
2022-06-21 11:57:17 +02:00
|
|
|
'name' => 'A Stary eyed client',
|
|
|
|
'contacts' => [
|
|
|
|
[
|
|
|
|
'id' => $contact->hashed_id,
|
|
|
|
'email' => $safe_email,
|
|
|
|
'password' => '*****',
|
2020-09-06 11:38:10 +02:00
|
|
|
],
|
2022-06-21 11:57:17 +02:00
|
|
|
],
|
|
|
|
];
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response = null;
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
try {
|
|
|
|
$response = $this->withHeaders([
|
2022-06-21 11:57:17 +02:00
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->put('/api/v1/clients/'.$this->client->hashed_id, $data);
|
2020-03-21 06:37:30 +01:00
|
|
|
} catch (ValidationException $e) {
|
|
|
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
|
|
|
$this->assertNotNull($message);
|
|
|
|
}
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$response->assertStatus(200);
|
2020-03-02 11:22:37 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$arr = $response->json();
|
2020-10-22 12:14:14 +02:00
|
|
|
|
2020-05-14 11:08:49 +02:00
|
|
|
$this->client = Client::find($this->decodePrimaryKey($arr['data']['id']));
|
|
|
|
$this->client->fresh();
|
2020-03-01 11:18:13 +01:00
|
|
|
|
2020-05-14 11:08:49 +02:00
|
|
|
$contact = $this->client->contacts()->whereEmail($safe_email)->first();
|
2020-03-01 06:00:54 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertEquals($password, $contact->password);
|
|
|
|
}
|
2019-03-26 06:00:15 +01:00
|
|
|
}
|