mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
fix-tests-5.0.2
This commit is contained in:
committed by
Mohit Panjwani
parent
5a7b515a03
commit
fe66b8bdb8
@ -9,8 +9,6 @@ use Crater\Traits\HasCustomFieldsTrait;
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Laravel\Sanctum\HasApiTokens;
|
use Laravel\Sanctum\HasApiTokens;
|
||||||
use Silber\Bouncer\BouncerFacade;
|
use Silber\Bouncer\BouncerFacade;
|
||||||
@ -266,87 +264,6 @@ class User extends Authenticatable implements HasMedia
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function createCustomer($request)
|
|
||||||
{
|
|
||||||
$data = $request->only([
|
|
||||||
'name',
|
|
||||||
'email',
|
|
||||||
'phone',
|
|
||||||
'company_name',
|
|
||||||
'contact_name',
|
|
||||||
'website',
|
|
||||||
'enable_portal',
|
|
||||||
'invoice_prefix',
|
|
||||||
'estimate_prefix',
|
|
||||||
'payment_prefix'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$data['creator_id'] = Auth::id();
|
|
||||||
$data['company_id'] = $request->header('company');
|
|
||||||
$data['role'] = 'customer';
|
|
||||||
$data['password'] = Hash::make($request->password);
|
|
||||||
$customer = User::create($data);
|
|
||||||
|
|
||||||
$customer['currency_id'] = $request->currency_id;
|
|
||||||
$customer->save();
|
|
||||||
|
|
||||||
if ($request->addresses) {
|
|
||||||
foreach ($request->addresses as $address) {
|
|
||||||
$customer->addresses()->create($address);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$customFields = $request->customFields;
|
|
||||||
|
|
||||||
if ($customFields) {
|
|
||||||
$customer->addCustomFields($customFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
$customer = User::with('billingAddress', 'shippingAddress', 'fields')->find($customer->id);
|
|
||||||
|
|
||||||
return $customer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function updateCustomer($request, $customer)
|
|
||||||
{
|
|
||||||
$data = $request->only([
|
|
||||||
'name',
|
|
||||||
'currency_id',
|
|
||||||
'email',
|
|
||||||
'phone',
|
|
||||||
'company_name',
|
|
||||||
'contact_name',
|
|
||||||
'website',
|
|
||||||
'enable_portal',
|
|
||||||
'invoice_prefix',
|
|
||||||
'estimate_prefix',
|
|
||||||
'payment_prefix'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$data['role'] = 'customer';
|
|
||||||
if ($request->has('password')) {
|
|
||||||
$customer->password = Hash::make($request->password);
|
|
||||||
}
|
|
||||||
$customer->update($data);
|
|
||||||
|
|
||||||
$customer->addresses()->delete();
|
|
||||||
if ($request->addresses) {
|
|
||||||
foreach ($request->addresses as $address) {
|
|
||||||
$customer->addresses()->create($address);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$customFields = $request->customFields;
|
|
||||||
|
|
||||||
if ($customFields) {
|
|
||||||
$customer->updateCustomFields($customFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
$customer = User::with('billingAddress', 'shippingAddress', 'fields')->find($customer->id);
|
|
||||||
|
|
||||||
return $customer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setSettings($settings)
|
public function setSettings($settings)
|
||||||
{
|
{
|
||||||
foreach ($settings as $key => $value) {
|
foreach ($settings as $key => $value) {
|
||||||
|
|||||||
@ -52,13 +52,7 @@ test('store recurring invoice', function () {
|
|||||||
|
|
||||||
$recurringInvoice = collect($recurringInvoice)
|
$recurringInvoice = collect($recurringInvoice)
|
||||||
->only([
|
->only([
|
||||||
'starts_at',
|
|
||||||
'send_automatically',
|
|
||||||
'next_invoice_at',
|
|
||||||
'frequency',
|
'frequency',
|
||||||
'limit_by',
|
|
||||||
'limit_count',
|
|
||||||
'limit_date'
|
|
||||||
])
|
])
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
@ -96,13 +90,7 @@ test('update recurring invoice', function () {
|
|||||||
|
|
||||||
$new_recurringInvoice = collect($new_recurringInvoice)
|
$new_recurringInvoice = collect($new_recurringInvoice)
|
||||||
->only([
|
->only([
|
||||||
'starts_at',
|
|
||||||
'send_automatically',
|
|
||||||
'next_invoice_at',
|
|
||||||
'frequency',
|
'frequency',
|
||||||
'limit_by',
|
|
||||||
'limit_count',
|
|
||||||
'limit_date'
|
|
||||||
])
|
])
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Crater\Models\Address;
|
|
||||||
use Crater\Models\User;
|
use Crater\Models\User;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@ -16,73 +14,8 @@ test('user belongs to currency', function () {
|
|||||||
$this->assertTrue($user->currency()->exists());
|
$this->assertTrue($user->currency()->exists());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('user has many addresses', function () {
|
|
||||||
$user = User::factory()->hasAddresses(2)->create();
|
|
||||||
|
|
||||||
$this->assertTrue($user->addresses()->exists());
|
|
||||||
});
|
|
||||||
|
|
||||||
test('user belongs to many companies', function () {
|
test('user belongs to many companies', function () {
|
||||||
$user = User::factory()->hasCompanies(5)->create();
|
$user = User::factory()->hasCompanies(5)->create();
|
||||||
|
|
||||||
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $user->companies);
|
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $user->companies);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('user has one billing address', function () {
|
|
||||||
$user = User::factory()->has(Address::factory()->state([
|
|
||||||
'type' => Address::BILLING_TYPE,
|
|
||||||
]))->create();
|
|
||||||
|
|
||||||
$this->assertTrue($user->billingAddress()->exists());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('user has one shipping address', function () {
|
|
||||||
$user = User::factory()->has(Address::factory()->state([
|
|
||||||
'type' => Address::SHIPPING_TYPE,
|
|
||||||
]))->create();
|
|
||||||
|
|
||||||
$this->assertTrue($user->shippingAddress()->exists());
|
|
||||||
});
|
|
||||||
|
|
||||||
test('create customer', function () {
|
|
||||||
$customer = User::factory()->raw([
|
|
||||||
'role' => 'customer',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$request = new Request();
|
|
||||||
|
|
||||||
$request->replace($customer);
|
|
||||||
|
|
||||||
$response = User::createCustomer($request);
|
|
||||||
|
|
||||||
$this->assertDatabaseHas('users', [
|
|
||||||
'name' => $customer['name'],
|
|
||||||
'email' => $customer['email'],
|
|
||||||
'role' => $customer['role'],
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('update customer', function () {
|
|
||||||
$customer = User::factory()->create([
|
|
||||||
'role' => 'customer',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$customer2 = User::factory()->raw([
|
|
||||||
'role' => 'customer',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$request = new Request();
|
|
||||||
|
|
||||||
$request->replace($customer2);
|
|
||||||
|
|
||||||
$updateCustomer = User::updateCustomer($request, $customer);
|
|
||||||
|
|
||||||
$newCustomer = User::find($customer->id);
|
|
||||||
|
|
||||||
$this->assertDatabaseHas('users', [
|
|
||||||
'id' => $customer->id,
|
|
||||||
'name' => $customer2['name'],
|
|
||||||
'email' => $customer2['email'],
|
|
||||||
'role' => $customer2['role'],
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user