renamed income/expense

This commit is contained in:
denisdulici
2019-12-31 15:49:09 +03:00
parent e2189158b9
commit 2428feb73b
235 changed files with 815 additions and 2147 deletions

View File

@@ -0,0 +1,133 @@
<?php
namespace Tests\Feature\Sales;
use App\Jobs\Common\CreateContact;
use App\Models\Auth\User;
use Tests\Feature\FeatureTestCase;
class CustomersTest extends FeatureTestCase
{
public function testItShouldSeeCustomerListPage()
{
$this->loginAs()
->get(route('customers.index'))
->assertStatus(200)
->assertSeeText(trans_choice('general.customers', 2));
}
public function testItShouldSeeCustomerCreatePage()
{
$this->loginAs()
->get(route('customers.create'))
->assertStatus(200)
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.customers', 1)]));
}
public function testItShouldCreateOnlyCustomerWithoutUser()
{
$this->loginAs()
->post(route('customers.store'), $this->getCustomerRequest())
->assertStatus(200);
$this->assertFlashLevel('success');
}
public function testItShouldCreateCustomerWithUser()
{
$customer = $this->getCustomerRequestWithUser();
$this->loginAs()
->post(route('customers.store'), $customer)
->assertStatus(200);
$this->assertFlashLevel('success');
$user = User::where('email', $customer['email'])->first();
$this->assertNotNull($user);
$this->assertEquals($customer['email'], $user->email);
}
public function testItShouldSeeCustomerDetailPage()
{
$customer = $this->dispatch(new CreateContact($this->getCustomerRequest()));
$this->loginAs()
->get(route('customers.show', ['customer' => $customer->id]))
->assertStatus(200)
->assertSee($customer->email);
}
public function testItShouldSeeCustomerUpdatePage()
{
$customer = $this->dispatch(new CreateContact($this->getCustomerRequest()));
$this->loginAs()
->get(route('customers.edit', ['customer' => $customer->id]))
->assertStatus(200)
->assertSee($customer->email)
->assertSee($customer->name);
}
public function testItShouldUpdateCustomer()
{
$request = $this->getCustomerRequest();
$customer = $this->dispatch(new CreateContact($request));
$request['name'] = $this->faker->name;
$this->loginAs()
->patch(route('customers.update', $customer->id), $request)
->assertStatus(200);
$this->assertFlashLevel('success');
}
public function testItShouldDeleteCustomer()
{
$customer = $this->dispatch(new CreateContact($this->getCustomerRequest()));
$this->loginAs()
->delete(route('customers.destroy', $customer->id))
->assertStatus(200);
$this->assertFlashLevel('success');
}
public function testItShouldNotDeleteCustomerIfHasRelations()
{
$this->assertTrue(true);
//TODO : This will write after done invoice and revenues tests.
}
private function getCustomerRequest()
{
return [
'company_id' => $this->company->id,
'type' => 'customer',
'name' => $this->faker->name,
'email' => $this->faker->email,
'tax_number' => $this->faker->randomNumber(9),
'phone' => $this->faker->phoneNumber,
'address' => $this->faker->address,
'website' => 'www.akaunting.com',
'currency_code' => $this->company->currencies()->enabled()->first()->code,
'enabled' => $this->faker->boolean ? 1 : 0
];
}
private function getCustomerRequestWithUser()
{
$password = $this->faker->password;
return $this->getCustomerRequest() + [
'create_user' => 1,
'locale' => 'en-GB',
'password' => $password,
'password_confirmation' => $password
];
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace Tests\Feature\Sales;
use App\Jobs\Sale\CreateInvoice;
use Tests\Feature\FeatureTestCase;
class InvoicesTest extends FeatureTestCase
{
public function testItShouldSeeInvoiceListPage()
{
$this->loginAs()
->get(route('invoices.index'))
->assertStatus(200)
->assertSeeText(trans_choice('general.invoices', 2));
}
public function testItShouldSeeInvoiceCreatePage()
{
$this->loginAs()
->get(route('invoices.create'))
->assertStatus(200)
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.invoices', 1)]));
}
public function testItShouldCreateInvoice()
{
$this->loginAs()
->post(route('invoices.store'), $this->getInvoiceRequest())
->assertStatus(200);
$this->assertFlashLevel('success');
}
public function testItShouldCreateInvoiceWithRecurring()
{
$this->loginAs()
->post(route('invoices.store'), $this->getInvoiceRequest(true))
->assertStatus(200);
$this->assertFlashLevel('success');
}
public function testItShouldSeeInvoiceUpdatePage()
{
$invoice = $this->dispatch(new CreateInvoice($this->getInvoiceRequest()));
$this->loginAs()
->get(route('invoices.edit', ['invoice' => $invoice->id]))
->assertStatus(200)
->assertSee($invoice->contact_name)
->assertSee($invoice->contact_email);
}
public function testItShouldUpdateInvoice()
{
$request = $this->getInvoiceRequest();
$invoice = $this->dispatch(new CreateInvoice($request));
$request['contact_name'] = $this->faker->name;
$this->loginAs()
->patch(route('invoices.update', $invoice->id), $request)
->assertStatus(200);
$this->assertFlashLevel('success');
}
public function testItShouldDeleteInvoice()
{
$invoice = $this->dispatch(new CreateInvoice($this->getInvoiceRequest()));
$this->loginAs()
->delete(route('invoices.destroy', $invoice->id))
->assertStatus(200);
$this->assertFlashLevel('success');
}
private function getInvoiceRequest($recurring = false)
{
$amount = $this->faker->randomFloat(2, 2);
$items = [['name' => $this->faker->text(5), 'item_id' => null, 'quantity' => '1', 'price' => $amount, 'currency' => 'USD']];
$data = [
'company_id' => $this->company->id,
'invoiced_at' => $this->faker->date(),
'due_at' => $this->faker->date(),
'invoice_number' => '1',
'order_number' => '1',
'currency_code' => setting('default.currency', 'USD'),
'currency_rate' => '1',
'items' => $items,
'discount' => '0',
'notes' => $this->faker->text(5),
'category_id' => $this->company->categories()->type('income')->pluck('id')->first(),
'recurring_frequency' => 'no',
'contact_id' => '0',
'contact_name' => $this->faker->name,
'contact_email' =>$this->faker->email,
'contact_tax_number' => null,
'contact_phone' => null,
'contact_address' => $this->faker->address,
'invoice_status_code' => 'draft',
'amount' => $amount,
];
if ($recurring) {
$data['recurring_frequency'] = 'yes';
$data['recurring_interval'] = '1';
$data['recurring_custom_frequency'] = $this->faker->randomElement(['monthly', 'weekly']);
$data['recurring_count'] = '1';
}
return $data;
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Tests\Feature\Sales;
use App\Jobs\Banking\CreateTransaction;
use App\Models\Banking\Transaction;
use Tests\Feature\FeatureTestCase;
class RevenuesTest extends FeatureTestCase
{
public function testItShouldSeeRevenueListPage()
{
$this->loginAs()
->get(route('revenues.index'))
->assertStatus(200)
->assertSeeText(trans_choice('general.revenues', 2));
}
public function testItShouldSeeRevenueCreatePage()
{
$this->loginAs()
->get(route('revenues.create'))
->assertStatus(200)
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.revenues', 1)]));
}
public function testItShouldCreateRevenue()
{
$this->loginAs()
->post(route('revenues.store'), factory(Transaction::class)->raw())
->assertStatus(200);
$this->assertFlashLevel('success');
}
public function testItShouldUpdateRevenue()
{
$request = factory(Transaction::class)->raw();
$revenue = $this->dispatch(new CreateTransaction($request));
$request['name'] = $this->faker->text(15);
$this->loginAs()
->patch(route('revenues.update', $revenue->id), $request)
->assertStatus(200);
$this->assertFlashLevel('success');
}
public function testItShouldDeleteRevenue()
{
$revenue = $this->dispatch(new CreateTransaction(factory(Transaction::class)->raw()));
$this->loginAs()
->delete(route('revenues.destroy', $revenue->id))
->assertStatus(200);
$this->assertFlashLevel('success');
}
}