v5.0.0 update

This commit is contained in:
Mohit Panjwani
2021-11-30 18:58:19 +05:30
parent d332712c22
commit 082d5cacf2
1253 changed files with 88309 additions and 71741 deletions

View File

@ -15,7 +15,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Settings\CompanyController;
use Crater\Http\Controllers\V1\Admin\Settings\CompanyController;
use Crater\Http\Requests\CompanyRequest;
use Crater\Http\Requests\ProfileRequest;
use Crater\Models\User;
@ -16,7 +16,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,

View File

@ -0,0 +1,69 @@
<?php
use Crater\Http\Controllers\V1\Admin\Company\CompaniesController;
use Crater\Http\Requests\CompaniesRequest;
use Crater\Models\Company;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\deleteJson;
use function Pest\Laravel\getJson;
use function Pest\Laravel\postJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::find(1);
$this->withHeaders([
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('store user using a form request', function () {
$this->assertActionUsesFormRequest(
CompaniesController::class,
'store',
CompaniesRequest::class
);
});
test('store company', function () {
$company = Company::factory()->raw();
postJson('/api/v1/companies', $company)
->assertStatus(201);
$company = collect($company)
->only([
'name'
])
->toArray();
$this->assertDatabaseHas('companies', $company);
});
test('delete company', function () {
$company = Company::factory()->create();
deleteJson('/api/v1/companies/delete')
->assertOk();
});
test('transfer ownership', function () {
$company = Company::factory()->create();
$user = User::factory()->create();
postJson('/api/v1/transfer/ownership/'.$user->id)
->assertOk();
});
test('get companies', function () {
getJson('/api/v1/companies')
->assertOk();
});

View File

@ -0,0 +1,74 @@
<?php
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\getJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::find(1);
$this->withHeaders([
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('get all used currencies', function () {
getJson("/api/v1/currencies/used")
->assertOk();
});
test('get supported currencies of currency freak', function () {
$driver = [
'driver' => "currency_freak",
'key' => "9ab5bc6424604778ad61103b628518f8"
];
$queryString = http_build_query($driver, '', '&');
getJson("/api/v1/supported-currencies?".$queryString)
->assertOk();
});
test('get supported currencies of currency layer', function () {
$driver = [
'driver' => "currency_layer",
'key' => "2bb7a25e6f24f42a66fde1f57b5210fd"
];
$queryString = http_build_query($driver, '', '&');
getJson("/api/v1/supported-currencies?".$queryString)
->assertOk();
});
test('get supported currencies of open exchange rate', function () {
$driver = [
'driver' => "open_exchange_rate",
'key' => "c5f404d414d245209923cd4f2d4c3875"
];
$queryString = http_build_query($driver, '', '&');
getJson("/api/v1/supported-currencies?".$queryString)
->assertOk();
});
test('get supported currencies of currency converter', function () {
$driver = [
'driver' => "currency_converter",
'key' => "0a1cef4d5f6fd01cc87a",
'type' => 'FREE'
];
$queryString = http_build_query($driver, '', '&');
getJson("/api/v1/supported-currencies?".$queryString)
->assertOk();
});

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\CustomField\CustomFieldsController;
use Crater\Http\Controllers\V1\Admin\CustomField\CustomFieldsController;
use Crater\Http\Requests\CustomFieldRequest;
use Crater\Models\CustomField;
use Crater\Models\User;
@ -17,7 +17,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -35,10 +35,7 @@ test('create custom field', function () {
$data = CustomField::factory()->raw();
postJson('api/v1/custom-fields', $data)
->assertStatus(200)
->assertJson([
'success' => true,
]);
->assertStatus(201);
$this->assertDatabaseHas('custom_fields', [
'name' => $data['name'],
@ -65,10 +62,7 @@ test('update custom field', function () {
]);
putJson('api/v1/custom-fields/'.$customField->id, $newCustomField)
->assertStatus(200)
->assertJson([
'success' => true,
]);
->assertStatus(200);
$this->assertDatabaseHas('custom_fields', [
'id' => $customField->id,

View File

@ -1,7 +1,8 @@
<?php
use Crater\Http\Controllers\V1\Customer\CustomersController;
use Crater\Http\Controllers\V1\Admin\Customer\CustomersController;
use Crater\Http\Requests\CustomerRequest;
use Crater\Models\Customer;
use Crater\Models\Invoice;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
@ -16,7 +17,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -31,12 +32,10 @@ test('get customers', function () {
});
test('customer stats', function () {
$customer = User::factory()->create([
'role' => 'customer',
]);
$customer = Customer::factory()->create();
$invoice = Invoice::factory()->create([
'user_id' => $customer->id,
'customer_id' => $customer->id,
]);
$response = getJson("api/v1/customers/{$customer->id}/stats");
@ -45,25 +44,24 @@ test('customer stats', function () {
});
test('create customer', function () {
$customer = User::factory()->raw([
'password' => 'secret',
'role' => 'customer',
$customer = Customer::factory()->raw([
'shipping' => [
'name' => 'newName',
'address_street_1' => 'address'
],
'billing' => [
'name' => 'newName',
'address_street_1' => 'address'
]
]);
$response = postJson('api/v1/customers', $customer);
postJson('api/v1/customers', $customer)
->assertOk();
$this->assertDatabaseHas('users', [
$this->assertDatabaseHas('customers', [
'name' => $customer['name'],
'email' => $customer['email'],
'role' => $customer['role'],
'company_id' => $customer['company_id'],
'email' => $customer['email']
]);
$response
->assertOk()
->assertJson([
'success' => true,
]);
});
test('store validates using a form request', function () {
@ -75,48 +73,47 @@ test('store validates using a form request', function () {
});
test('get customer', function () {
$customer = User::factory()->create([
'role' => 'customer',
]);
$customer = Customer::factory()->create();
$response = getJson("api/v1/customers/{$customer->id}");
$this->assertDatabaseHas('users', [
$this->assertDatabaseHas('customers', [
'id' => $customer->id,
'name' => $customer['name'],
'email' => $customer['email'],
'role' => $customer['role'],
'company_id' => $customer['company_id'],
'email' => $customer['email']
]);
$response->assertOk();
});
test('update customer', function () {
$customer = User::factory()->create([
'role' => 'customer',
]);
$customer = Customer::factory()->create();
$customer1 = User::factory()->raw([
'role' => 'customer',
'name' => 'new name',
$customer1 = Customer::factory()->raw([
'shipping' => [
'name' => 'newName',
'address_street_1' => 'address'
],
'billing' => [
'name' => 'newName',
'address_street_1' => 'address'
]
]);
$response = putJson('api/v1/customers/'.$customer->id, $customer1);
$this->assertDatabaseHas('users', [
'id' => $customer->id,
'name' => $customer1['name'],
'email' => $customer1['email'],
'role' => $customer1['role'],
'company_id' => $customer1['company_id'],
]);
$customer1 = collect($customer1)
->only([
'email'
])
->merge([
'creator_id' => Auth::id()
])
->toArray();
$response
->assertOk()
->assertJson([
'success' => true,
]);
$response->assertOk();
$this->assertDatabaseHas('customers', $customer1);
});
test('update validates using a form request', function () {
@ -143,9 +140,7 @@ test('search customers', function () {
});
test('delete multiple customer', function () {
$customers = User::factory()->count(4)->create([
'role' => 'customer',
]);
$customers = Customer::factory()->count(4)->create();
$ids = $customers->pluck('id');

View File

@ -11,7 +11,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,

View File

@ -1,7 +1,7 @@
<?php
use Crater\Http\Controllers\V1\Estimate\EstimatesController;
use Crater\Http\Controllers\V1\Estimate\SendEstimateController;
use Crater\Http\Controllers\V1\Admin\Estimate\EstimatesController;
use Crater\Http\Controllers\V1\Admin\Estimate\SendEstimateController;
use Crater\Http\Requests\DeleteEstimatesRequest;
use Crater\Http\Requests\EstimatesRequest;
use Crater\Http\Requests\SendEstimatesRequest;
@ -23,7 +23,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -39,6 +39,7 @@ test('get estimates', function () {
test('create estimate', function () {
$estimate = Estimate::factory()->raw([
'estimate_number' => 'EST-000006',
'items' => [
EstimateItem::factory()->raw(),
],
@ -57,7 +58,7 @@ test('create estimate', function () {
'discount_val' => $estimate['discount_val'],
'sub_total' => $estimate['sub_total'],
'discount' => $estimate['discount'],
'user_id' => $estimate['user_id'],
'customer_id' => $estimate['customer_id'],
'total' => $estimate['total'],
'notes' => $estimate['notes'],
'tax' => $estimate['tax'],
@ -83,7 +84,9 @@ test('update estimate', function () {
$estimate2 = Estimate::factory()->raw([
'items' => [
EstimateItem::factory()->raw(),
EstimateItem::factory()->raw([
'estimate_id' => $estimate->id
]),
],
'taxes' => [
Tax::factory()->raw([
@ -94,8 +97,6 @@ test('update estimate', function () {
$response = putJson('api/v1/estimates/'.$estimate->id, $estimate2);
$newEstimate = $response->decodeResponseJson()['estimate'];
$this->assertDatabaseHas('estimates', [
'template_name' => $estimate2['template_name'],
'estimate_number' => $estimate2['estimate_number'],
@ -103,18 +104,14 @@ test('update estimate', function () {
'discount_val' => $estimate2['discount_val'],
'sub_total' => $estimate2['sub_total'],
'discount' => $estimate2['discount'],
'user_id' => $estimate2['user_id'],
'customer_id' => $estimate2['customer_id'],
'total' => $estimate2['total'],
'notes' => $estimate2['notes'],
'tax' => $estimate2['tax'],
]);
$this->assertDatabaseHas('taxes', [
'estimate_id' => $newEstimate['id'],
]);
$this->assertDatabaseHas('estimate_items', [
'estimate_id' => $newEstimate['id'],
'estimate_id' => $estimate2['items'][0]['estimate_id'],
]);
$response->assertStatus(200);

View File

@ -0,0 +1,101 @@
<?php
use Crater\Http\Controllers\V1\Admin\ExchangeRate\ExchangeRateProviderController;
use Crater\Http\Requests\ExchangeRateProviderRequest;
use Crater\Models\ExchangeRateProvider;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\deleteJson;
use function Pest\Laravel\getJson;
use function Pest\Laravel\postJson;
use function Pest\Laravel\putJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::find(1);
$this->withHeaders([
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('get exchange rate providers', function () {
getJson('api/v1/exchange-rate-providers?page=1')
->assertOk();
});
test('store user using a form request', function () {
$this->assertActionUsesFormRequest(
ExchangeRateProviderController::class,
'store',
ExchangeRateProviderRequest::class
);
});
test('store recurring invoice', function () {
$exchangeRateProvider = ExchangeRateProvider::factory()->raw();
postJson('api/v1/exchange-rate-providers', $exchangeRateProvider)
->assertStatus(201);
$exchangeRateProvider = collect($exchangeRateProvider)
->only([
'driver',
'key',
'active',
])
->toArray();
$this->assertDatabaseHas('exchange_rate_providers', $exchangeRateProvider);
});
test('get exchange rate provider', function () {
$exchangeRateProvider = ExchangeRateProvider::factory()->create();
getJson("api/v1/exchange-rate-providers/{$exchangeRateProvider->id}")
->assertOk();
});
test('update user using a form request', function () {
$this->assertActionUsesFormRequest(
ExchangeRateProviderController::class,
'update',
ExchangeRateProviderRequest::class
);
});
test('update exchange rate provider', function () {
$exchangeRateProvider = ExchangeRateProvider::factory()->create();
$newExchangeRateProvider = ExchangeRateProvider::factory()->raw();
putJson("api/v1/exchange-rate-providers/{$exchangeRateProvider->id}", $newExchangeRateProvider)
->assertOk();
$newExchangeRateProvider = collect($newExchangeRateProvider)
->only([
'driver',
'key',
'active',
])
->toArray();
$this->assertDatabaseHas('exchange_rate_providers', $newExchangeRateProvider);
});
test('delete exchange rate provider', function () {
$exchangeRateProvider = ExchangeRateProvider::factory()->create([
'active' => false
]);
deleteJson("api/v1/exchange-rate-providers/{$exchangeRateProvider->id}")
->assertOk();
$this->assertDeleted($exchangeRateProvider);
});

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Expense\ExpenseCategoriesController;
use Crater\Http\Controllers\V1\Admin\Expense\ExpenseCategoriesController;
use Crater\Http\Requests\ExpenseCategoryRequest;
use Crater\Models\ExpenseCategory;
use Crater\Models\User;
@ -17,7 +17,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -36,7 +36,7 @@ test('create category', function () {
$response = postJson('api/v1/categories', $category);
$response->assertStatus(200);
$response->assertStatus(201);
$this->assertDatabaseHas('expense_categories', [
'name' => $category['name'],

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Expense\ExpensesController;
use Crater\Http\Controllers\V1\Admin\Expense\ExpensesController;
use Crater\Http\Requests\ExpenseRequest;
use Crater\Models\Expense;
use Crater\Models\User;
@ -16,7 +16,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -31,7 +31,7 @@ test('get expenses', function () {
test('create expense', function () {
$expense = Expense::factory()->raw();
postJson('api/v1/expenses', $expense)->assertOk();
postJson('api/v1/expenses', $expense)->assertStatus(201);
$this->assertDatabaseHas('expenses', [
'notes' => $expense['notes'],

View File

@ -14,7 +14,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Invoice\InvoicesController;
use Crater\Http\Controllers\V1\Admin\Invoice\InvoicesController;
use Crater\Http\Requests\InvoicesRequest;
use Crater\Mail\SendInvoiceMail;
use Crater\Models\Invoice;
@ -20,7 +20,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -50,14 +50,15 @@ test('create invoice', function () {
'invoice_number' => $invoice['invoice_number'],
'sub_total' => $invoice['sub_total'],
'discount' => $invoice['discount'],
'user_id' => $invoice['user_id'],
'customer_id' => $invoice['customer_id'],
'total' => $invoice['total'],
'tax' => $invoice['tax'],
]);
$this->assertDatabaseHas('invoice_items', $invoice['items'][0]);
$this->assertDatabaseHas('taxes', $invoice['taxes'][0]);
$this->assertDatabaseHas('invoice_items', [
'item_id' => $invoice['items'][0]['item_id'],
'name' => $invoice['items'][0]['name']
]);
});
test('create invoice as sent', function () {
@ -77,13 +78,14 @@ test('create invoice as sent', function () {
'total' => $invoice['total'],
'tax' => $invoice['tax'],
'discount' => $invoice['discount'],
'user_id' => $invoice['user_id'],
'customer_id' => $invoice['customer_id'],
'template_name' => $invoice['template_name'],
]);
$this->assertDatabaseHas('invoice_items', $invoice['items'][0]);
$this->assertDatabaseHas('taxes', $invoice['taxes'][0]);
$this->assertDatabaseHas('invoice_items', [
'item_id' => $invoice['items'][0]['item_id'],
'name' => $invoice['items'][0]['name']
]);
});
test('store validates using a form request', function () {
@ -114,13 +116,14 @@ test('update invoice', function () {
'total' => $invoice2['total'],
'tax' => $invoice2['tax'],
'discount' => $invoice2['discount'],
'user_id' => $invoice2['user_id'],
'customer_id' => $invoice2['customer_id'],
'template_name' => $invoice2['template_name'],
]);
$this->assertDatabaseHas('invoice_items', $invoice2['items'][0]);
$this->assertDatabaseHas('taxes', $invoice2['taxes'][0]);
$this->assertDatabaseHas('invoice_items', [
'item_id' => $invoice2['items'][0]['item_id'],
'name' => $invoice2['items'][0]['name']
]);
});
test('update validates using a form request', function () {
@ -252,10 +255,7 @@ test('clone invoice', function () {
$response = postJson("api/v1/invoices/{$invoices->id}/clone");
$response
->assertOk()
->assertJson([
'success' => true,
]);
->assertOk();
});
test('create invoice with negative tax', function () {
@ -277,10 +277,14 @@ test('create invoice with negative tax', function () {
'total' => $invoice['total'],
'tax' => $invoice['tax'],
'discount' => $invoice['discount'],
'user_id' => $invoice['user_id'],
'customer_id' => $invoice['customer_id'],
]);
$this->assertDatabaseHas('invoice_items', $invoice['items'][0]);
$this->assertDatabaseHas('invoice_items', [
'name' => $invoice['items'][0]['name'],
]);
$this->assertDatabaseHas('taxes', $invoice['taxes'][0]);
$this->assertDatabaseHas('taxes', [
'tax_type_id' => $invoice['taxes'][0]['tax_type_id']
]);
});

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Item\ItemsController;
use Crater\Http\Controllers\V1\Admin\Item\ItemsController;
use Crater\Http\Requests\ItemsRequest;
use Crater\Models\Item;
use Crater\Models\Tax;
@ -17,7 +17,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -49,7 +49,7 @@ test('create item', function () {
]);
$this->assertDatabaseHas('taxes', [
'item_id' => $response->getData()->item->id,
'item_id' => $response->getData()->data->id,
]);
$response->assertOk();

View File

@ -11,7 +11,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,

View File

@ -11,8 +11,9 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
['*']
@ -25,7 +26,7 @@ test('next number', function () {
$response = getJson('api/v1/next-number?key='.$key);
$response->assertStatus(200)->assertJson([
'nextNumber' => '000001',
'nextNumber' => 'INV-000001',
]);
$key = 'estimate';
@ -33,7 +34,7 @@ test('next number', function () {
$response = getJson('api/v1/next-number?key='.$key);
$response->assertStatus(200)->assertJson([
'nextNumber' => '000001',
'nextNumber' => 'EST-000001',
]);
$key = 'payment';
@ -41,6 +42,6 @@ test('next number', function () {
$response = getJson('api/v1/next-number?key='.$key);
$response->assertStatus(200)->assertJson([
'nextNumber' => '000001',
'nextNumber' => 'PAY-000001',
]);
});

View File

@ -15,7 +15,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -30,7 +30,7 @@ test('retrieve notes', function () {
test('create note', function () {
$note = Note::factory()->raw();
postJson('/api/v1/notes', $note)->assertStatus(200);
postJson('/api/v1/notes', $note)->assertStatus(201);
$this->assertDatabaseHas('notes', $note);
});
@ -39,10 +39,7 @@ test('retrieve note', function () {
$note = Note::factory()->create();
getJson("/api/v1/notes/{$note->id}")
->assertStatus(200)
->assertJson([
'note' => $note->toArray(),
]);
->assertStatus(200);
});
test('update note', function () {

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Payment\PaymentMethodsController;
use Crater\Http\Controllers\V1\Admin\Payment\PaymentMethodsController;
use Crater\Http\Requests\PaymentMethodRequest;
use Crater\Models\PaymentMethod;
use Crater\Models\User;
@ -17,7 +17,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -34,14 +34,12 @@ test('get payment methods', function () {
test('create payment method', function () {
$data = [
'name' => 'demo name',
'company_id' => User::find(1)->company_id,
'company_id' => User::find(1)->companies()->first()->id,
];
$response = postJson('api/v1/payment-methods', $data);
$response->assertOk();
$method = $response->decodeResponseJson()['paymentMethod'];
$response->assertStatus(201);
$this->assertDatabaseHas('payment_methods', [
'name' => $data['name'],

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Payment\PaymentsController;
use Crater\Http\Controllers\V1\Admin\Payment\PaymentsController;
use Crater\Http\Requests\PaymentRequest;
use Crater\Mail\SendPaymentMail;
use Crater\Models\Invoice;
@ -19,7 +19,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -49,6 +49,7 @@ test('create payment', function () {
$payment = Payment::factory()->raw([
'invoice_id' => $invoice->id,
'payment_number' => "PAY-000001",
'amount' => $invoice->due_amount
]);
$response = postJson('api/v1/payments', $payment);
@ -57,7 +58,7 @@ test('create payment', function () {
$this->assertDatabaseHas('payments', [
'payment_number' => $payment['payment_number'],
'user_id' => $payment['user_id'],
'customer_id' => $payment['customer_id'],
'amount' => $payment['amount'],
'company_id' => $payment['company_id'],
]);
@ -72,22 +73,24 @@ test('store validates using a form request', function () {
});
test('update payment', function () {
$invoice = Invoice::factory()->create();
$payment = Payment::factory()->create([
'payment_date' => '1988-08-18',
'invoice_id' => $invoice->id
]);
$payment2 = Payment::factory()->raw([
'payment_number' => $payment->payment_number,
'invoice_id' => $invoice->id
]);
$response = putJson("api/v1/payments/{$payment->id}", $payment2);
$response->assertOk();
putJson("api/v1/payments/{$payment->id}", $payment2)
->assertOk();
$this->assertDatabaseHas('payments', [
'id' => $payment->id,
'payment_number' => $payment2['payment_number'],
'user_id' => $payment2['user_id'],
'customer_id' => $payment2['customer_id'],
'amount' => $payment2['amount'],
]);
});

View File

@ -0,0 +1,140 @@
<?php
use Carbon\Carbon;
use Crater\Http\Controllers\V1\Admin\RecurringInvoice\RecurringInvoiceController;
use Crater\Http\Requests\RecurringInvoiceRequest;
use Crater\Models\InvoiceItem;
use Crater\Models\RecurringInvoice;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\getJson;
use function Pest\Laravel\postJson;
use function Pest\Laravel\putJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::find(1);
$this->withHeaders([
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('get recurring invoices', function () {
RecurringInvoice::factory()->create();
getJson('api/v1/recurring-invoices?page=1')
->assertOk();
});
test('store user using a form request', function () {
$this->assertActionUsesFormRequest(
RecurringInvoiceController::class,
'store',
RecurringInvoiceRequest::class
);
});
test('store recurring invoice', function () {
$recurringInvoice = RecurringInvoice::factory()->raw();
$recurringInvoice['items'] = [
InvoiceItem::factory()->raw()
];
postJson('api/v1/recurring-invoices', $recurringInvoice)
->assertStatus(201);
$recurringInvoice = collect($recurringInvoice)
->only([
'starts_at',
'send_automatically',
'next_invoice_at',
'frequency',
'limit_by',
'limit_count',
'limit_date'
])
->toArray();
$this->assertDatabaseHas('recurring_invoices', $recurringInvoice);
});
test('get recurring invoice', function () {
$recurringInvoice = RecurringInvoice::factory()->create();
getJson("api/v1/recurring-invoices/{$recurringInvoice->id}")
->assertOk();
});
test('update user using a form request', function () {
$this->assertActionUsesFormRequest(
RecurringInvoiceController::class,
'update',
RecurringInvoiceRequest::class
);
});
test('update recurring invoice', function () {
$recurringInvoice = RecurringInvoice::factory()->create();
$recurringInvoice['items'] = [
InvoiceItem::factory()->raw()
];
$new_recurringInvoice = RecurringInvoice::factory()->raw();
$new_recurringInvoice['items'] = [
InvoiceItem::factory()->raw()
];
putJson("api/v1/recurring-invoices/{$recurringInvoice->id}", $new_recurringInvoice)
->assertOk();
$new_recurringInvoice = collect($new_recurringInvoice)
->only([
'starts_at',
'send_automatically',
'next_invoice_at',
'frequency',
'limit_by',
'limit_count',
'limit_date'
])
->toArray();
$this->assertDatabaseHas('recurring_invoices', $new_recurringInvoice);
});
test('delete multiple recurring invoice', function () {
$recurringInvoices = RecurringInvoice::factory()->count(3)->create();
$data = [
'ids' => $recurringInvoices->pluck('id'),
];
postJson('api/v1/recurring-invoices/delete', $data)
->assertOk()
->assertJson([
'success' => true,
]);
foreach ($recurringInvoices as $recurringInvoice) {
$this->assertDeleted($recurringInvoice);
}
});
test('calculate frequency for recurring invoice', function () {
$data = [
'frequency' => '* * 2 * *',
'starts_at' => Carbon::now()->format('Y-m-d')
];
$queryString = http_build_query($data, '', '&');
getJson("api/v1/recurring-invoice-frequency?".$queryString)
->assertOk();
});

View File

@ -12,7 +12,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,

View File

@ -0,0 +1,25 @@
<?php
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\getJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::find(1);
$this->withHeaders([
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('get all retrospective edits', function () {
getJson('api/v1/config/retrospective-edit-options')
->assertOk();
});

View File

@ -0,0 +1,34 @@
<?php
use Crater\Models\User;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\postJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::find(1);
$this->withHeaders([
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('create super admin role', function () {
$data = [
"email" => "loremipsum@gmail.com",
"name" => "lorem",
"role" => "super admin",
"password" => "lorem@123"
];
postJson('api/v1/users', $data)->assertStatus(201);
$this->assertDatabaseHas('users', Arr::except($data, ['password']));
});

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Settings\TaxTypesController;
use Crater\Http\Controllers\V1\Admin\Settings\TaxTypesController;
use Crater\Http\Requests\TaxTypeRequest;
use Crater\Models\TaxType;
use Crater\Models\User;
@ -18,7 +18,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -53,10 +53,7 @@ test('get tax type', function () {
$response = getJson('api/v1/tax-types/'.$taxType->id);
$response->assertOk()
->assertJson([
'taxType' => $taxType->toArray(),
]);
$response->assertOk();
});
test('update tax type', function () {
@ -66,10 +63,7 @@ test('update tax type', function () {
$response = putJson('api/v1/tax-types/'.$taxType->id, $taxType1);
$response->assertOk()
->assertJson([
'taxType' => $taxType1,
]);
$response->assertOk();
});
test('update validates using a form request', function () {
@ -100,7 +94,7 @@ test('create negative tax type', function () {
]);
postJson('api/v1/tax-types', $taxType)
->assertOk();
->assertStatus(201);
$this->assertDatabaseHas('tax_types', $taxType);
});

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Item\UnitsController;
use Crater\Http\Controllers\V1\Admin\Item\UnitsController;
use Crater\Http\Requests\UnitRequest;
use Crater\Models\Unit;
use Crater\Models\User;
@ -17,7 +17,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -34,12 +34,12 @@ test('get units', function () {
test('create unit', function () {
$data = [
'name' => 'unit name',
'company_id' => User::find(1)->company_id,
'company_id' => User::find(1)->companies()->first()->id,
];
$response = postJson('api/v1/units', $data);
$response->assertOk();
$response->assertStatus(201);
$this->assertDatabaseHas('units', $data);
});

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Users\UsersController;
use Crater\Http\Controllers\V1\Admin\Users\UsersController;
use Crater\Http\Requests\UserRequest;
use Crater\Models\User;
use Laravel\Sanctum\Sanctum;
@ -16,7 +16,7 @@ beforeEach(function () {
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(