init crater

This commit is contained in:
Mohit Panjwani
2019-11-11 12:16:00 +05:30
commit bdf2ba51d6
668 changed files with 158503 additions and 0 deletions

View File

@ -0,0 +1,220 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laraspace\User;
use Laravel\Passport\Passport;
use SettingsSeeder;
class CompanySettingTest extends TestCase
{
use RefreshDatabase;
protected $user;
public function setUp(): void
{
parent::setUp();
$this->seed();
$this->seed(SettingsSeeder::class);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Passport::actingAs(
$user,
['*']
);
}
/** @test */
public function testGetProfile()
{
$response = $this->json('GET', 'api/settings/profile');
$response->assertOk();
}
/** @test */
public function testUpdateProfile()
{
$user = [
'name' => 'John Doe',
'password' => 'admin@123',
'email' => 'admin@crater.in'
];
$response = $this->json('PUT', 'api/settings/profile', $user);
$response->assertOk();
}
/** @test */
public function testGetUpdateCompanyDetails()
{
$response = $this->json('GET', 'api/settings/company');
$response->assertOk();
}
/** @test */
public function testUpdateCompany()
{
$company = [
'name' => 'XYZ',
'country_id' => 2,
'state_id' => 3,
'city_id' => 4,
'address_street_1' => 'test1',
'address_street_2' => 'test2',
'phone' => '1234567890',
'zip' => '112233'
];
$response = $this->json('POST', 'api/settings/company', $company);
$response->assertOk();
$company2 = $response->decodeResponseJson()['user']['company'];
$address2 = $response->decodeResponseJson()['user']['addresses'][0];
$this->assertEquals($company['name'], $company2['name']);
$this->assertEquals($company['country_id'], $address2['country_id']);
$this->assertEquals($company['state_id'], $address2['state_id']);
$this->assertEquals($company['city_id'], $address2['city_id']);
$this->assertEquals($company['address_street_1'], $address2['address_street_1']);
$this->assertEquals($company['address_street_2'], $address2['address_street_2']);
$this->assertEquals($company['phone'], $address2['phone']);
$this->assertEquals($company['zip'], $address2['zip']);
}
/** @test */
public function testGetSettings()
{
$response = $this->json('GET', 'api/settings/general');
$response->assertOk();
}
/** @test */
public function testUpdateSettings()
{
$settings = [
'currency' => 1,
'time_zone' => 'Asia/Kolkata',
'language' => 'en',
'fiscal_year' => '1-12',
'carbon_date_format' => 'Y/m/d',
'moment_date_format' => 'YYYY/MM/DD'
];
$response = $this->json('PUT', 'api/settings/general', $settings);
$response->assertOk();
}
/** @test */
public function testUpdateNotificationEmailSettings()
{
$settings = [
'key' => 'notification_email',
'value' => 'noreply@crater.in'
];
$response = $this->json('PUT', 'api/settings/update-setting', $settings);
$response->assertOk();
}
/** @test */
public function testGetNotificationEmailSettings()
{
$response = $this->json('GET', 'api/settings/get-setting?key=notification_email');
$response->assertOk();
}
/** @test */
public function testUpdateNotificationInvoiceViewedSettings()
{
$settings = [
'key' => 'notify_invoice_viewed',
'value' => 'YES'
];
$response = $this->json('PUT', 'api/settings/update-setting', $settings);
$response->assertOk();
}
/** @test */
public function testGetNotificationInvoiceViewedSettings()
{
$response = $this->json('GET', 'api/settings/get-setting?key=notify_invoice_viewed');
$response->assertOk();
}
/** @test */
public function testUpdateNotificationEstimateViewedSettings()
{
$settings = [
'key' => 'notify_estimate_viewed',
'value' => 'YES'
];
$response = $this->json('PUT', 'api/settings/update-setting', $settings);
$response->assertOk();
}
/** @test */
public function testGetNotificationEstimateViewedSettings()
{
$response = $this->json('GET', 'api/settings/get-setting?key=notify_estimate_viewed');
$response->assertOk();
}
/** @test */
public function testUpdateTaxPerItemSetting()
{
$settings = [
'key' => 'tax_per_item',
'value' => 'YES'
];
$response = $this->json('PUT', 'api/settings/update-setting', $settings);
$response->assertOk();
}
/** @test */
public function testGetTaxPerItemSetting()
{
$response = $this->json('GET', 'api/settings/get-setting?key=tax_per_item');
$response->assertOk();
}
/** @test */
public function testUpdateDiscountPerItemSetting()
{
$settings = [
'key' => 'discount_per_item',
'value' => 'YES'
];
$response = $this->json('PUT', 'api/settings/update-setting', $settings);
$response->assertOk();
}
/** @test */
public function testGetDiscountPerItemSetting()
{
$response = $this->json('GET', 'api/settings/get-setting?key=discount_per_item');
$response->assertOk();
}
}

View File

@ -0,0 +1,181 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laraspace\User;
use Laravel\Passport\Passport;
use SettingsSeeder;
class CustomerTest extends TestCase
{
use RefreshDatabase;
protected $user;
public function setUp(): void
{
parent::setUp();
$this->seed();
$this->seed(SettingsSeeder::class);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Passport::actingAs(
$user,
['*']
);
}
/** @test */
public function testGetCustomers()
{
$response = $this->json('GET', 'api/customers?page=1');
$response->assertOk();
}
/** @test */
public function testCreateCustomer()
{
$customer = factory(User::class)->raw([
'password' => 'secret',
'role' => 'customer'
]);
$response = $this->json('POST', 'api/customers', $customer);
$newCustomer = $response->decodeResponseJson()['customer'];
$this->assertEquals($customer['name'], $newCustomer['name']);
$this->assertEquals($customer['email'], $newCustomer['email']);
$this->assertEquals($customer['role'], $newCustomer['role']);
$this->assertEquals($customer['phone'], $newCustomer['phone']);
$this->assertEquals($customer['company_name'], $newCustomer['company_name']);
$this->assertEquals($customer['contact_name'], $newCustomer['contact_name']);
$this->assertEquals($customer['website'], $newCustomer['website']);
$this->assertEquals($customer['enable_portal'], $newCustomer['enable_portal']);
$response
->assertOk()
->assertJson([
'success' => true
]);
}
/** @test */
public function testCustomerNameRequired()
{
$customer = factory(User::class)->raw([
'name' => '',
'password' => 'secret',
'role' => 'customer'
]);
$response = $this->json('POST', 'api/customers', $customer);
$response->assertStatus(422)->assertJsonValidationErrors(['name']);
}
/** @test */
public function testGetUpdateCustomerData()
{
$customer = factory(User::class)->create(['role' => 'customer']);
$response = $this->json('GET', 'api/customers/'.$customer->id.'/edit');
$newCustomer = $response->decodeResponseJson()['customer'];
$this->assertEquals($customer->name, $newCustomer['name']);
$this->assertEquals($customer->email, $newCustomer['email']);
$this->assertEquals($customer->role, $newCustomer['role']);
$this->assertEquals($customer->phone, $newCustomer['phone']);
$this->assertEquals($customer->company_name, $newCustomer['company_name']);
$this->assertEquals($customer->contact_name, $newCustomer['contact_name']);
$this->assertEquals($customer->website, $newCustomer['website']);
$this->assertEquals($customer->enable_portal, $newCustomer['enable_portal']);
$response->assertOk();
}
/** @test */
public function testUpdateCustomer()
{
$customer = factory(User::class)->create(['role' => 'customer']);
$customer2 = factory(User::class)->raw(['role' => 'customer']);
$response = $this->json('PUT', 'api/customers/'.$customer->id, $customer2);
$newCustomer = $response->decodeResponseJson()['customer'];
$this->assertEquals($customer2['name'], $newCustomer['name']);
$this->assertEquals($customer2['email'], $newCustomer['email']);
$this->assertEquals($customer2['role'], $newCustomer['role']);
$this->assertEquals($customer2['phone'], $newCustomer['phone']);
$this->assertEquals($customer2['company_name'], $newCustomer['company_name']);
$this->assertEquals($customer2['contact_name'], $newCustomer['contact_name']);
$this->assertEquals($customer2['website'], $newCustomer['website']);
$this->assertEquals($customer2['enable_portal'], $newCustomer['enable_portal']);
$response
->assertOk()
->assertJson([
'success' => true
]);
}
/** @test */
public function testDeleteCustomer()
{
$customer = factory(User::class)->create(['role' => 'customer']);
$response = $this->json('DELETE', 'api/customers/'.$customer->id);
$response
->assertOk()
->assertJson([
'success' => true
]);
$deletedCustomer = User::find($customer->id);
$this->assertNull($deletedCustomer);
}
/** @test */
public function testSearchCustomers()
{
$filters = [
'page' => 1,
'limit' => 15,
'search' => 'doe',
'email' => '.com'
];
$queryString = http_build_query($filters, '', '&');
$response = $this->json('GET', 'api/customers?'.$queryString);
$response->assertOk();
}
/** @test */
public function testDeleteMultipleCustomer()
{
$customers = factory(User::class, 3)->create(['role' => 'customer']);
$ids = $customers->pluck('id');
$data = [
'id' => $ids
];
$response = $this->json('POST', 'api/customers/delete', $data);
$response
->assertOk()
->assertJson([
'success' => true
]);
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laraspace\User;
use Laravel\Passport\Passport;
use SettingsSeeder;
class DashboardTest extends TestCase
{
use RefreshDatabase;
protected $user;
public function setUp(): void
{
parent::setUp();
$this->seed();
$this->seed(SettingsSeeder::class);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Passport::actingAs(
$user,
['*']
);
}
/** @test */
public function testDashboard()
{
$response = $this->json('GET', 'api/dashboard');
$response->assertOk();
}
/** @test */
public function testPieChartData()
{
$response = $this->json('GET', 'api/dashboard/expense/chart');
$response->assertOk();
}
}

View File

@ -0,0 +1,626 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laraspace\User;
use Laraspace\Estimate;
use Laraspace\Invoice;
use Laraspace\EstimateItem;
use Laraspace\Tax;
use Laravel\Passport\Passport;
use SettingsSeeder;
class EstimateTest extends TestCase
{
use RefreshDatabase;
protected $user;
public function setUp(): void
{
parent::setUp();
$this->seed();
$this->seed(SettingsSeeder::class);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Passport::actingAs(
$user,
['*']
);
}
/** @test */
public function testGetEstimates()
{
$response = $this->json('GET', 'api/estimates?page=1');
$response->assertOk();
}
/** @test */
public function testGetCreateEstimateData()
{
$response = $this->json('GET', 'api/estimates/create');
$response->assertOk();
}
/** @test */
public function testCreateEstimate()
{
$estimate = factory(Estimate::class)->raw([
'items' => [
factory(EstimateItem::class)->raw()
],
'taxes' => [
factory(Tax::class)->raw()
]
]);
$response = $this->json('POST', 'api/estimates', $estimate);
$newEstimate = $response->decodeResponseJson()['estimate'];
$response->assertOk();
$this->assertEquals($estimate['estimate_number'], $newEstimate['estimate_number']);
$this->assertEquals($estimate['user_id'], $newEstimate['user_id']);
$this->assertEquals($estimate['estimate_template_id'], $newEstimate['estimate_template_id']);
$this->assertEquals($estimate['sub_total'], $newEstimate['sub_total']);
$this->assertEquals($estimate['total'], $newEstimate['total']);
$this->assertEquals($estimate['discount'], $newEstimate['discount']);
$this->assertEquals($estimate['discount_type'], $newEstimate['discount_type']);
$this->assertEquals($estimate['discount_val'], $newEstimate['discount_val']);
$this->assertEquals($estimate['tax'], $newEstimate['tax']);
$this->assertEquals($estimate['notes'], $newEstimate['notes']);
$this->assertEquals($estimate['items'][0]['name'], $newEstimate['items'][0]['name']);
$this->assertEquals($estimate['items'][0]['description'], $newEstimate['items'][0]['description']);
$this->assertEquals($estimate['items'][0]['price'], $newEstimate['items'][0]['price']);
$this->assertEquals($estimate['items'][0]['quantity'], $newEstimate['items'][0]['quantity']);
$this->assertEquals($estimate['items'][0]['discount_type'], $newEstimate['items'][0]['discount_type']);
$this->assertEquals($estimate['items'][0]['discount'], $newEstimate['items'][0]['discount']);
$this->assertEquals($estimate['items'][0]['total'], $newEstimate['items'][0]['total']);
$this->assertEquals($estimate['taxes'][0]['tax_type_id'], $newEstimate['taxes'][0]['tax_type_id']);
$this->assertEquals($estimate['taxes'][0]['percent'], $newEstimate['taxes'][0]['percent']);
$this->assertEquals($estimate['taxes'][0]['amount'], $newEstimate['taxes'][0]['amount']);
$this->assertEquals($estimate['taxes'][0]['name'], $newEstimate['taxes'][0]['name']);
$this->assertEquals($newEstimate['id'], $newEstimate['taxes'][0]['estimate_id']);
}
/** @test */
public function testCreateEstimateEstimateDateRequired()
{
$estimate = factory(Estimate::class)->raw([
'estimate_date' => '',
'items' => [
factory(EstimateItem::class)->raw()
]
]);
$response = $this->json('POST', 'api/estimates', $estimate);
$response->assertStatus(422)->assertJsonValidationErrors(['estimate_date']);
}
/** @test */
public function testCreateEstimateExpiryDateRequired()
{
$estimate = factory(Estimate::class)->raw([
'expiry_date' => '',
'items' => [
factory(EstimateItem::class)->raw()
]
]);
$response = $this->json('POST', 'api/estimates', $estimate);
$response->assertStatus(422)->assertJsonValidationErrors(['expiry_date']);
}
/** @test */
public function testCreateEstimateRequiresEstimateNumber()
{
$estimate = factory(Estimate::class)->raw([
'estimate_number' => '',
'items' => [
factory(EstimateItem::class)->raw()
]
]);
$response = $this->json('POST', 'api/estimates', $estimate);
$response->assertStatus(422)->assertJsonValidationErrors(['estimate_number']);
}
/** @test */
public function testCreateEstimateRequiresUser()
{
$estimate = factory(Estimate::class)->raw([
'user_id' => '',
'items' => [
factory(EstimateItem::class)->raw()
]
]);
$response = $this->json('POST', 'api/estimates', $estimate);
$response->assertStatus(422)->assertJsonValidationErrors(['user_id']);
}
/** @test */
public function testCreateEstimateRequiresDiscount()
{
$estimate = factory(Estimate::class)->raw([
'discount' => '',
'items' => [
factory(EstimateItem::class)->raw()
]
]);
$response = $this->json('POST', 'api/estimates', $estimate);
$response->assertStatus(422)->assertJsonValidationErrors(['discount']);
}
/** @test */
public function testCreateEstimateRequiresTemplate()
{
$estimate = factory(Estimate::class)->raw([
'estimate_template_id' => '',
'items' => [
factory(EstimateItem::class)->raw()
]
]);
$response = $this->json('POST', 'api/estimates', $estimate);
$response->assertStatus(422)->assertJsonValidationErrors(['estimate_template_id']);
}
/** @test */
public function testCreateEstimateRequiresItems()
{
$estimate = factory(Estimate::class)->raw(['items' => []]);
$response = $this->json('POST', 'api/estimates', $estimate);
$response->assertStatus(422)->assertJsonValidationErrors(['items']);
}
/** @test */
public function testCreateEstimateRequiresItemsName()
{
$estimate = factory(Estimate::class)->raw([
'items' => [factory(EstimateItem::class)->raw(['name' => ''])]
]);
$response = $this->json('POST', 'api/estimates', $estimate);
$response->assertStatus(422)->assertJsonValidationErrors(['items.0.name']);
}
/** @test */
public function testCreateEstimateRequiresItemsQuantity()
{
$estimate = factory(Estimate::class)->raw([
'items' => [factory(EstimateItem::class)->raw(['quantity' => null])]
]);
$response = $this->json('POST', 'api/estimates', $estimate);
$response->assertStatus(422)->assertJsonValidationErrors(['items.0.quantity']);
}
/** @test */
public function testCreateEstimateRequiresItemsPrice()
{
$estimate = factory(Estimate::class)->raw([
'items' => [factory(EstimateItem::class)->raw(['price' => null])]
]);
$response = $this->json('POST', 'api/estimates', $estimate);
$response->assertStatus(422)->assertJsonValidationErrors(['items.0.price']);
}
/** @test */
public function testGetEditEstimateData()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$response = $this->json('GET', 'api/estimates/'.$estimate->id.'/edit');
$response->assertOk();
}
/** @test */
public function testUpdateEstimate()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$estimate2 = factory(Estimate::class)->raw([
'items' => [
factory(EstimateItem::class)->raw()
],
'taxes' => [
factory(Tax::class)->raw([
'tax_type_id' => $estimate->taxes[0]->tax_type_id
])
]
]);
$response = $this->json('PUT', 'api/estimates/'.$estimate->id, $estimate2);
$newEstimate = $response->decodeResponseJson()['estimate'];
$response->assertOk();
$this->assertEquals($estimate2['estimate_number'], $newEstimate['estimate_number']);
$this->assertEquals($estimate2['user_id'], $newEstimate['user_id']);
$this->assertEquals($estimate2['estimate_template_id'], $newEstimate['estimate_template_id']);
$this->assertEquals($estimate2['sub_total'], $newEstimate['sub_total']);
$this->assertEquals($estimate2['total'], $newEstimate['total']);
$this->assertEquals($estimate2['discount'], $newEstimate['discount']);
$this->assertEquals($estimate2['discount_type'], $newEstimate['discount_type']);
$this->assertEquals($estimate2['discount_val'], $newEstimate['discount_val']);
$this->assertEquals($estimate2['tax'], $newEstimate['tax']);
$this->assertEquals($estimate2['notes'], $newEstimate['notes']);
$this->assertEquals($estimate2['items'][0]['name'], $newEstimate['items'][0]['name']);
$this->assertEquals($estimate2['items'][0]['description'], $newEstimate['items'][0]['description']);
$this->assertEquals($estimate2['items'][0]['price'], $newEstimate['items'][0]['price']);
$this->assertEquals($estimate2['items'][0]['quantity'], $newEstimate['items'][0]['quantity']);
$this->assertEquals($estimate2['items'][0]['discount_type'], $newEstimate['items'][0]['discount_type']);
$this->assertEquals($estimate2['items'][0]['discount'], $newEstimate['items'][0]['discount']);
$this->assertEquals($estimate2['items'][0]['total'], $newEstimate['items'][0]['total']);
$this->assertEquals($estimate2['taxes'][0]['tax_type_id'], $newEstimate['taxes'][0]['tax_type_id']);
$this->assertEquals($estimate2['taxes'][0]['percent'], $newEstimate['taxes'][0]['percent']);
$this->assertEquals($estimate2['taxes'][0]['amount'], $newEstimate['taxes'][0]['amount']);
$this->assertEquals($estimate2['taxes'][0]['name'], $newEstimate['taxes'][0]['name']);
$this->assertEquals($newEstimate['id'], $newEstimate['taxes'][0]['estimate_id']);
}
/** @test */
public function testUpdateEstimateEstimateDateRequired()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$estimate2 = factory(Estimate::class)->raw([
'estimate_date' => '',
'items' => [
factory(EstimateItem::class)->raw()
]
]);
$response = $this->json('PUT', 'api/estimates/'.$estimate->id, $estimate2);
$response->assertStatus(422)->assertJsonValidationErrors(['estimate_date']);
}
/** @test */
public function testUpdateEstimateExpiryDateRequired()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$estimate2 = factory(Estimate::class)->raw([
'expiry_date' => '',
'items' => [
factory(EstimateItem::class)->raw()
]
]);
$response = $this->json('PUT', 'api/estimates/'.$estimate->id, $estimate2);
$response->assertStatus(422)->assertJsonValidationErrors(['expiry_date']);
}
/** @test */
public function testUpdateEstimateRequiresEstimateNumber()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$estimate2 = factory(Estimate::class)->raw([
'estimate_number' => '',
'items' => [
factory(EstimateItem::class)->raw()
]
]);
$response = $this->json('PUT', 'api/estimates/'.$estimate->id, $estimate2);
$response->assertStatus(422)->assertJsonValidationErrors(['estimate_number']);
}
/** @test */
public function testUpdateEstimateRequiresUser()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$estimate2 = factory(Estimate::class)->raw([
'user_id' => '',
'items' => [
factory(EstimateItem::class)->raw()
]
]);
$response = $this->json('PUT', 'api/estimates/'.$estimate->id, $estimate2);
$response->assertStatus(422)->assertJsonValidationErrors(['user_id']);
}
/** @test */
public function testUpdateEstimateRequiresDiscount()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$estimate2 = factory(Estimate::class)->raw([
'discount' => '',
'items' => [
factory(EstimateItem::class)->raw()
]
]);
$response = $this->json('PUT', 'api/estimates/'.$estimate->id, $estimate2);
$response->assertStatus(422)->assertJsonValidationErrors(['discount']);
}
/** @test */
public function testUpdateEstimateRequiresTemplate()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$estimate2 = factory(Estimate::class)->raw([
'estimate_template_id' => '',
'items' => [
factory(EstimateItem::class)->raw()
]
]);
$response = $this->json('PUT', 'api/estimates/'.$estimate->id, $estimate2);
$response->assertStatus(422)->assertJsonValidationErrors(['estimate_template_id']);
}
/** @test */
public function testUpdateEstimateRequiresItems()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$estimate2 = factory(Estimate::class)->raw(['items' => []]);
$response = $this->json('PUT', 'api/estimates/'.$estimate->id, $estimate2);
$response->assertStatus(422)->assertJsonValidationErrors(['items']);
}
/** @test */
public function testUpdateEstimateRequiresItemsName()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$estimate2 = factory(Estimate::class)->raw([
'items' => [factory(EstimateItem::class)->raw(['name' => ''])]
]);
$response = $this->json('PUT', 'api/estimates/'.$estimate->id, $estimate2);
$response->assertStatus(422)->assertJsonValidationErrors(['items.0.name']);
}
/** @test */
public function testUpdateEstimateRequiresItemsQuantity()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$estimate2 = factory(Estimate::class)->raw([
'items' => [factory(EstimateItem::class)->raw(['quantity' => null])]
]);
$response = $this->json('PUT', 'api/estimates/'.$estimate->id, $estimate2);
$response->assertStatus(422)->assertJsonValidationErrors(['items.0.quantity']);
}
/** @test */
public function testUpdateEstimateRequiresItemsPrice()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$estimate2 = factory(Estimate::class)->raw([
'items' => [factory(EstimateItem::class)->raw(['price' => null])]
]);
$response = $this->json('PUT', 'api/estimates/'.$estimate->id, $estimate2);
$response->assertStatus(422)->assertJsonValidationErrors(['items.0.price']);
}
/** @test */
public function testDeleteEstimate()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$response = $this->json('DELETE', 'api/estimates/'.$estimate->id);
$response
->assertOk()
->assertJson([
'success' => 'Estimate deleted successfully'
]);
$deleted = Estimate::find($estimate->id);
$this->assertNull($deleted);
}
/** @test */
public function testSearchEstimates()
{
$filters = [
'page' => 1,
'limit' => 15,
'search' => 'doe',
'from_date' => '01/09/2019',
'to_date' => '11/09/2019',
'estimate_number' => '000003'
];
$queryString = http_build_query($filters, '', '&');
$response = $this->json('GET', 'api/estimates?'.$queryString);
$response->assertOk();
}
/** @test */
public function testSendEstimateToCustomer()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$data = [
'id' => $estimate->id
];
$response = $this->json('POST', 'api/estimates/send', $data);
$response
->assertOk()
->assertJson([
'success' => true
]);
}
/** @test */
public function testEstimateMarkAsAccepted()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$data = [
'id' => $estimate->id
];
$response = $this->json('POST', 'api/estimates/accept', $data);
$response
->assertOk()
->assertJson([
'success' => true
]);
$estimate2 = Estimate::find($estimate->id);
$this->assertEquals($estimate2->status, Estimate::STATUS_ACCEPTED);
}
/** @test */
public function testEstimateMarkAsRejected()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$data = [
'id' => $estimate->id
];
$response = $this->json('POST', 'api/estimates/reject', $data);
$response
->assertOk()
->assertJson([
'success' => true
]);
$estimate2 = Estimate::find($estimate->id);
$this->assertEquals($estimate2->status, Estimate::STATUS_REJECTED);
}
/** @test */
public function testCreateInvoiceFromEstimate()
{
$estimate = factory(Estimate::class)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$response = $this->json('POST', 'api/estimates/'.$estimate->id.'/convert-to-invoice');
$response->assertOk();
}
/** @test */
public function testDeleteMultipleEstimates()
{
$estimates = factory(Estimate::class, 3)->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$ids = $estimates->pluck('id');
$data = [
'id' => $ids
];
$response = $this->json('POST', 'api/estimates/delete', $data);
$response
->assertOk()
->assertJson([
'success' => true
]);
}
}

View File

@ -0,0 +1,123 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laraspace\User;
use Laraspace\ExpenseCategory;
use Laravel\Passport\Passport;
use SettingsSeeder;
class ExpenseCategoryTest extends TestCase
{
use RefreshDatabase;
protected $user;
public function setUp(): void
{
parent::setUp();
$this->seed();
$this->seed(SettingsSeeder::class);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Passport::actingAs(
$user,
['*']
);
}
/** @test */
public function testGetCategories()
{
$response = $this->json('GET', 'api/categories');
$response->assertOk();
}
/** @test */
public function testCreateCategory()
{
$category = factory(ExpenseCategory::class)->raw();
$response = $this->json('POST', 'api/categories', $category);
$category2 = $response->decodeResponseJson()['category'];
$response->assertOk();
$this->assertEquals($category['name'], $category2['name']);
$this->assertEquals($category['description'], $category2['description']);
}
/** @test */
public function testCreateCategoryRequiresName()
{
$category = factory(ExpenseCategory::class)->raw([
'name' => ''
]);
$response = $this->json('POST', 'api/categories', $category);
$response->assertStatus(422)->assertJsonValidationErrors(['name']);
}
/** @test */
public function testGetEditCategoryData()
{
$category = factory(ExpenseCategory::class)->create();
$response = $this->json('GET', 'api/categories/'.$category->id.'/edit');
$category2 = $response->decodeResponseJson()['category'];
$response->assertOk();
$this->assertEquals($category->toArray(), $category2);
}
/** @test */
public function testUpdateCategory()
{
$category = factory(ExpenseCategory::class)->create();
$category2 = factory(ExpenseCategory::class)->raw();
$response = $this->json('PUT', 'api/categories/'.$category->id, $category2);
$category3 = $response->decodeResponseJson()['category'];
$response->assertOk();
$this->assertEquals($category3['name'], $category2['name']);
$this->assertEquals($category3['description'], $category2['description']);
}
/** @test */
public function testUpdateCategoryRequiresName()
{
$category = factory(ExpenseCategory::class)->create();
$category2 = factory(ExpenseCategory::class)->raw([
'name' => ''
]);
$response = $this->json('PUT', 'api/categories/'.$category->id, $category2);
$response->assertStatus(422)->assertJsonValidationErrors(['name']);
}
/** @test */
public function testDeleteCategory()
{
$category = factory(ExpenseCategory::class)->create();
$response = $this->json('DELETE', 'api/categories/'.$category->id);
$response
->assertOk()
->assertJson([
'success' => true
]);
}
}

View File

@ -0,0 +1,240 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laraspace\User;
use Laraspace\Expense;
use Laraspace\CompanySetting;
use Laraspace\ExpenseCategory;
use Laravel\Passport\Passport;
use SettingsSeeder;
class ExpenseTest extends TestCase
{
use RefreshDatabase;
protected $user;
public function setUp(): void
{
parent::setUp();
$this->seed();
$this->seed(SettingsSeeder::class);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Passport::actingAs(
$user,
['*']
);
}
/** @test */
public function testGetExpenses()
{
$response = $this->json('GET', 'api/expenses?page=1');
$response->assertOk();
}
/** @test */
public function testGetCreateExpenseData()
{
$response = $this->json('GET', 'api/expenses/create');
$response->assertOk();
}
/** @test */
public function testCrateExpense()
{
$expense = factory(Expense::class)->raw();
$response = $this->json('POST', 'api/expenses', $expense);
$expense2 = $response->decodeResponseJson()['expense'];
$response->assertOk();
$this->assertEquals($expense['notes'], $expense2['notes']);
$this->assertEquals($expense['expense_category_id'], $expense2['expense_category_id']);
$this->assertEquals($expense['amount'], $expense2['amount']);
}
/** @test */
public function testCreateExpenseRequiresExpanseDate()
{
$expense = factory(Expense::class)->raw([
'expense_date' => ''
]);
$response = $this->json('POST', 'api/expenses', $expense);
$response->assertStatus(422)->assertJsonValidationErrors(['expense_date']);
}
/** @test */
public function testCreateExpenseRequiresAmount()
{
$expense = factory(Expense::class)->raw([
'amount' => ''
]);
$response = $this->json('POST', 'api/expenses', $expense);
$response->assertStatus(422)->assertJsonValidationErrors(['amount']);
}
/** @test */
public function testCreateExpenseRequiresCategory()
{
$expense = factory(Expense::class)->raw([
'expense_category_id' => ''
]);
$response = $this->json('POST', 'api/expenses', $expense);
$response->assertStatus(422)->assertJsonValidationErrors(['expense_category_id']);
}
/** @test */
public function testGetEditExpenseData()
{
$expense = factory(Expense::class)->create([
'expense_date' => '2019-02-05'
]);
$response = $this->json('GET', 'api/expenses/'.$expense->id.'/edit');
$response->assertOk();
}
/** @test */
public function testUpdateExpense()
{
$expense = factory(Expense::class)->create([
'expense_date' => '2019-02-05'
]);
$expense2 = factory(Expense::class)->raw();
$response = $this->json('PUT', 'api/expenses/'.$expense->id, $expense2);
$expense3 = $response->decodeResponseJson()['expense'];
$response->assertOk();
$this->assertEquals($expense3['notes'], $expense2['notes']);
$this->assertEquals($expense3['expense_category_id'], $expense2['expense_category_id']);
$this->assertEquals($expense3['amount'], $expense2['amount']);
}
/** @test */
public function testUpdateExpenseRequiresExpenseDate()
{
$expense = factory(Expense::class)->create([
'expense_date' => '2019-02-05'
]);
$expense2 = factory(Expense::class)->raw([
'expense_date' => ''
]);
$response = $this->json('PUT', 'api/expenses/'.$expense->id, $expense2);
$response->assertStatus(422)->assertJsonValidationErrors(['expense_date']);
}
/** @test */
public function testUpdateExpenseRequiresAmount()
{
$expense = factory(Expense::class)->create([
'expense_date' => '2019-02-05'
]);
$expense2 = factory(Expense::class)->raw([
'amount' => ''
]);
$response = $this->json('PUT', 'api/expenses/'.$expense->id, $expense2);
$response->assertStatus(422)->assertJsonValidationErrors(['amount']);
}
/** @test */
public function testUpdateExpenseRequiresCategory()
{
$expense = factory(Expense::class)->create([
'expense_date' => '2019-02-05'
]);
$expense2 = factory(Expense::class)->raw([
'expense_category_id' => ''
]);
$response = $this->json('PUT', 'api/expenses/'.$expense->id, $expense2);
$response->assertStatus(422)->assertJsonValidationErrors(['expense_category_id']);
}
/** @test */
public function testDeleteExpenses()
{
$expense = factory(Expense::class)->create([
'expense_date' => '2019-02-05'
]);
$response = $this->json('DELETE', 'api/expenses/'.$expense->id);
$response->assertOk()
->assertJson([
'success' => true
]);
}
/** @test */
public function testSearchExpenses()
{
$filters = [
'page' => 1,
'limit' => 15,
'expense_category_id' => 1,
'search' => 'cate',
'from_date' => '09/09/2016',
'to_date' => '10/09/2016'
];
$queryString = http_build_query($filters, '', '&');
$response = $this->json('GET', 'api/expenses?'.$queryString);
$response->dump();
$response->assertOk();
}
/** @test */
public function testDeleteMultipleExpenses()
{
$expenses = factory(Expense::class, 3)->create([
'expense_date' => '2019-02-05'
]);
$ids = $expenses->pluck('id');
$data = [
'id' => $ids,
'type' => 'expense'
];
$response = $this->json('POST', 'api/expenses/delete', $data);
$response
->assertOk()
->assertJson([
'success' => true
]);
}
}

View File

@ -0,0 +1,664 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laraspace\Tax;
use Laraspace\User;
use Laraspace\Invoice;
use Laraspace\CompanySetting;
use Laraspace\InvoiceItem;
use Laravel\Passport\Passport;
use SettingsSeeder;
class InvoiceTest extends TestCase
{
use RefreshDatabase;
protected $user;
public function setUp(): void
{
parent::setUp();
$this->seed();
$this->seed(SettingsSeeder::class);
$user = User::find(1);
$this->withHeaders([
'company' => 1,
]);
Passport::actingAs(
$user,
['*']
);
}
/** @test */
public function testGetInvoices()
{
$response = $this->json('GET', 'api/invoices?page=1&type=OVERDUE&limit=20');
$response->assertOk();
}
/** @test */
public function testGetCreateInvoiceData()
{
$response = $this->json('GET', 'api/invoices/create');
$response->assertOk();
}
/** @test */
public function testCreateInvoice()
{
$invoice = factory(Invoice::class)->raw([
'items' => [
factory(InvoiceItem::class)->raw([
'taxes' => [
factory(Tax::class)->raw()
]
])
],
'taxes' => [
factory(Tax::class)->raw()
]
]);
$response = $this->json('POST', 'api/invoices', $invoice);
$invoice2 = $response->decodeResponseJson()['invoice'];
$response->assertOk();
$this->assertEquals($invoice['invoice_number'], $invoice2['invoice_number']);
$this->assertEquals($invoice['sub_total'], $invoice2['sub_total']);
$this->assertEquals($invoice['total'], $invoice2['total']);
$this->assertEquals($invoice['tax'], $invoice2['tax']);
$this->assertEquals($invoice['discount'], $invoice2['discount']);
$this->assertEquals($invoice['discount_type'], $invoice2['discount_type']);
$this->assertEquals($invoice['discount_val'], $invoice2['discount_val']);
$this->assertEquals($invoice['notes'], $invoice2['notes']);
$this->assertEquals($invoice['user_id'], $invoice2['user_id']);
$this->assertEquals($invoice['invoice_template_id'], $invoice2['invoice_template_id']);
$this->assertEquals($invoice['items'][0]['name'], $invoice2['items'][0]['name']);
$this->assertEquals($invoice['items'][0]['description'], $invoice2['items'][0]['description']);
$this->assertEquals($invoice['items'][0]['price'], $invoice2['items'][0]['price']);
$this->assertEquals($invoice['items'][0]['quantity'], $invoice2['items'][0]['quantity']);
$this->assertEquals($invoice['items'][0]['discount_type'], $invoice2['items'][0]['discount_type']);
$this->assertEquals($invoice['items'][0]['discount'], $invoice2['items'][0]['discount']);
$this->assertEquals($invoice['items'][0]['total'], $invoice2['items'][0]['total']);
$this->assertEquals($invoice['items'][0]['item_id'], $invoice2['items'][0]['item_id']);
$this->assertEquals($invoice['taxes'][0]['tax_type_id'], $invoice2['taxes'][0]['tax_type_id']);
$this->assertEquals($invoice['taxes'][0]['percent'], $invoice2['taxes'][0]['percent']);
$this->assertEquals($invoice['taxes'][0]['amount'], $invoice2['taxes'][0]['amount']);
$this->assertEquals($invoice2['id'], $invoice2['taxes'][0]['invoice_id']);
}
/** @test */
public function testCreateInvoiceAsSent()
{
$invoice = factory(Invoice::class)->raw([
// 'invoiceSend' => true,
'items' => [
factory(InvoiceItem::class)->raw([
'taxes' => [
factory(Tax::class)->raw()
]
])
],
'taxes' => [
factory(Tax::class)->raw()
]
]);
$response = $this->json('POST', 'api/invoices', $invoice);
$invoice2 = $response->decodeResponseJson()['invoice'];
$response->assertOk();
$this->assertEquals($invoice['invoice_number'], $invoice2['invoice_number']);
$this->assertEquals($invoice['sub_total'], $invoice2['sub_total']);
$this->assertEquals($invoice['total'], $invoice2['total']);
$this->assertEquals($invoice['tax'], $invoice2['tax']);
$this->assertEquals($invoice['discount'], $invoice2['discount']);
$this->assertEquals($invoice['discount_type'], $invoice2['discount_type']);
$this->assertEquals($invoice['discount_val'], $invoice2['discount_val']);
$this->assertEquals($invoice['notes'], $invoice2['notes']);
$this->assertEquals($invoice['user_id'], $invoice2['user_id']);
$this->assertEquals($invoice['invoice_template_id'], $invoice2['invoice_template_id']);
$this->assertEquals($invoice['items'][0]['name'], $invoice2['items'][0]['name']);
$this->assertEquals($invoice['items'][0]['description'], $invoice2['items'][0]['description']);
$this->assertEquals($invoice['items'][0]['price'], $invoice2['items'][0]['price']);
$this->assertEquals($invoice['items'][0]['quantity'], $invoice2['items'][0]['quantity']);
$this->assertEquals($invoice['items'][0]['discount_type'], $invoice2['items'][0]['discount_type']);
$this->assertEquals($invoice['items'][0]['discount'], $invoice2['items'][0]['discount']);
$this->assertEquals($invoice['items'][0]['total'], $invoice2['items'][0]['total']);
$this->assertEquals($invoice['items'][0]['item_id'], $invoice2['items'][0]['item_id']);
$this->assertEquals($invoice['taxes'][0]['tax_type_id'], $invoice2['taxes'][0]['tax_type_id']);
$this->assertEquals($invoice['taxes'][0]['percent'], $invoice2['taxes'][0]['percent']);
$this->assertEquals($invoice['taxes'][0]['amount'], $invoice2['taxes'][0]['amount']);
$this->assertEquals($invoice2['id'], $invoice2['taxes'][0]['invoice_id']);
}
/** @test */
public function testCreateInvoiceRequiresInvoiceDate()
{
$invoice = factory(Invoice::class)->raw([
'invoice_date' => '',
'items' => [
factory(InvoiceItem::class)->raw()
]
]);
$response = $this->json('POST', 'api/invoices', $invoice);
$response->assertStatus(422)->assertJsonValidationErrors(['invoice_date']);
}
/** @test */
public function testCreateInvoiceExpiryDateRequired()
{
$invoice = factory(Invoice::class)->raw([
'due_date' => '',
'items' => [
factory(InvoiceItem::class)->raw()
]
]);
$response = $this->json('POST', 'api/invoices', $invoice);
$response->assertStatus(422)->assertJsonValidationErrors(['due_date']);
}
/** @test */
public function testCreateInvoiceRequiresInvoiceNumber()
{
$invoice = factory(Invoice::class)->raw([
'invoice_number' => '',
'items' => [
factory(InvoiceItem::class)->raw()
]
]);
$response = $this->json('POST', 'api/invoices', $invoice);
$response->assertStatus(422)->assertJsonValidationErrors(['invoice_number']);
}
/** @test */
public function testCreateInvoiceRequiresUser()
{
$invoice = factory(Invoice::class)->raw([
'user_id' => '',
'items' => [
factory(InvoiceItem::class)->raw()
]
]);
$response = $this->json('POST', 'api/invoices', $invoice);
$response->assertStatus(422)->assertJsonValidationErrors(['user_id']);
}
/** @test */
public function testCreateInvoiceRequiresDiscount()
{
$invoice = factory(Invoice::class)->raw([
'discount' => '',
'items' => [
factory(InvoiceItem::class)->raw()
]
]);
$response = $this->json('POST', 'api/invoices', $invoice);
$response->assertStatus(422)->assertJsonValidationErrors(['discount']);
}
/** @test */
public function testCreateInvoiceRequiresTemplate()
{
$invoice = factory(Invoice::class)->raw([
'invoice_template_id' => '',
'items' => [
factory(InvoiceItem::class)->raw()
]
]);
$response = $this->json('POST', 'api/invoices', $invoice);
$response->assertStatus(422)->assertJsonValidationErrors(['invoice_template_id']);
}
/** @test */
public function testCreateInvoiceRequiresItems()
{
$invoice = factory(Invoice::class)->raw(['items' => []]);
$response = $this->json('POST', 'api/invoices', $invoice);
$response->assertStatus(422)->assertJsonValidationErrors(['items']);
}
/** @test */
public function testCreateInvoiceRequiresItemsName()
{
$invoice = factory(Invoice::class)->raw([
'items' => [factory(InvoiceItem::class)->raw(['name' => ''])]
]);
$response = $this->json('POST', 'api/invoices', $invoice);
$response->assertStatus(422)->assertJsonValidationErrors(['items.0.name']);
}
/** @test */
public function testCreateInvoiceRequiresItemsQuantity()
{
$invoice = factory(Invoice::class)->raw([
'items' => [factory(InvoiceItem::class)->raw(['quantity' => null])]
]);
$response = $this->json('POST', 'api/invoices', $invoice);
$response->assertStatus(422)->assertJsonValidationErrors(['items.0.quantity']);
}
/** @test */
public function testCreateInvoiceRequiresItemsPrice()
{
$invoice = factory(Invoice::class)->raw([
'items' => [factory(InvoiceItem::class)->raw(['price' => null])]
]);
$response = $this->json('POST', 'api/invoices', $invoice);
$response->assertStatus(422)->assertJsonValidationErrors(['items.0.price']);
}
/** @test */
public function testGetEditInvoiceData()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$response = $this->json('GET', 'api/invoices/'.$invoice->id.'/edit');
$response->assertOk();
}
/** @test */
public function testUpdateInvoice()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$invoice2 = factory(Invoice::class)->raw([
'items' => [
factory(InvoiceItem::class)->raw([
'taxes' => [
factory(Tax::class)->raw()
]
])
],
'taxes' => [
factory(Tax::class)->raw(['tax_type_id' => $invoice->taxes[0]->tax_type_id])
]
]);
$response = $this->json('PUT', 'api/invoices/'.$invoice->id, $invoice2);
$invoice3 = $response->decodeResponseJson()['invoice'];
$response->assertOk();
$this->assertEquals($invoice3['invoice_number'], $invoice2['invoice_number']);
$this->assertEquals($invoice3['sub_total'], $invoice2['sub_total']);
$this->assertEquals($invoice3['total'], $invoice2['total']);
$this->assertEquals($invoice3['tax'], $invoice2['tax']);
$this->assertEquals($invoice3['discount'], $invoice2['discount']);
$this->assertEquals($invoice3['notes'], $invoice2['notes']);
$this->assertEquals($invoice3['user_id'], $invoice2['user_id']);
$this->assertEquals($invoice3['invoice_template_id'], $invoice2['invoice_template_id']);
$this->assertEquals($invoice3['items'][0]['name'], $invoice2['items'][0]['name']);
$this->assertEquals($invoice3['items'][0]['description'], $invoice2['items'][0]['description']);
$this->assertEquals($invoice3['items'][0]['price'], $invoice2['items'][0]['price']);
$this->assertEquals($invoice3['items'][0]['quantity'], $invoice2['items'][0]['quantity']);
$this->assertEquals($invoice3['items'][0]['discount_type'], $invoice2['items'][0]['discount_type']);
$this->assertEquals($invoice3['items'][0]['discount'], $invoice2['items'][0]['discount']);
$this->assertEquals($invoice3['items'][0]['total'], $invoice2['items'][0]['total']);
$this->assertEquals($invoice3['items'][0]['item_id'], $invoice2['items'][0]['item_id']);
$this->assertEquals($invoice3['taxes'][0]['tax_type_id'], $invoice2['taxes'][0]['tax_type_id']);
$this->assertEquals($invoice3['taxes'][0]['percent'], $invoice2['taxes'][0]['percent']);
$this->assertEquals($invoice3['taxes'][0]['amount'], $invoice2['taxes'][0]['amount']);
$this->assertEquals($invoice->id, $invoice3['taxes'][0]['invoice_id']);
}
/** @test */
public function testUpdateInvoiceRequiresInvoiceDate()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$invoice2 = factory(Invoice::class)->raw([
'invoice_date' => '',
'items' => [
factory(InvoiceItem::class)->raw()
]
]);
$response = $this->json('PUT', 'api/invoices/'.$invoice->id, $invoice2);
$response->assertStatus(422)->assertJsonValidationErrors(['invoice_date']);
}
/** @test */
public function testUpdateInvoiceExpiryDateRequired()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$invoice2 = factory(Invoice::class)->raw([
'due_date' => '',
'items' => [
factory(InvoiceItem::class)->raw()
]
]);
$response = $this->json('PUT', 'api/invoices/'.$invoice->id, $invoice2);
$response->assertStatus(422)->assertJsonValidationErrors(['due_date']);
}
/** @test */
public function testUpdateInvoiceRequiresInvoiceNumber()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$invoice2 = factory(Invoice::class)->raw([
'invoice_number' => '',
'items' => [
factory(InvoiceItem::class)->raw()
]
]);
$response = $this->json('PUT', 'api/invoices/'.$invoice->id, $invoice2);
$response->assertStatus(422)->assertJsonValidationErrors(['invoice_number']);
}
/** @test */
public function testUpdateInvoiceRequiresUser()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$invoice2 = factory(Invoice::class)->raw([
'user_id' => '',
'items' => [
factory(InvoiceItem::class)->raw()
]
]);
$response = $this->json('PUT', 'api/invoices/'.$invoice->id, $invoice2);
$response->assertStatus(422)->assertJsonValidationErrors(['user_id']);
}
/** @test */
public function testUpdateInvoiceRequiresDiscount()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$invoice2 = factory(Invoice::class)->raw([
'discount' => '',
'items' => [
factory(InvoiceItem::class)->raw()
]
]);
$response = $this->json('PUT', 'api/invoices/'.$invoice->id, $invoice2);
$response->assertStatus(422)->assertJsonValidationErrors(['discount']);
}
/** @test */
public function testUpdateInvoiceRequiresTemplate()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$invoice2 = factory(Invoice::class)->raw([
'invoice_template_id' => '',
'items' => [
factory(InvoiceItem::class)->raw()
]
]);
$response = $this->json('PUT', 'api/invoices/'.$invoice->id, $invoice2);
$response->assertStatus(422)->assertJsonValidationErrors(['invoice_template_id']);
}
/** @test */
public function testUpdateInvoiceRequiresItems()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$invoice2 = factory(Invoice::class)->raw(['items' => []]);
$response = $this->json('PUT', 'api/invoices/'.$invoice->id, $invoice2);
$response->assertStatus(422)->assertJsonValidationErrors(['items']);
}
/** @test */
public function testUpdateInvoiceRequiresItemsName()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$invoice2 = factory(Invoice::class)->raw([
'items' => [factory(InvoiceItem::class)->raw(['name' => ''])]
]);
$response = $this->json('PUT', 'api/invoices/'.$invoice->id, $invoice2);
$response->assertStatus(422)->assertJsonValidationErrors(['items.0.name']);
}
/** @test */
public function testUpdateInvoiceRequiresItemsQuantity()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$invoice2 = factory(Invoice::class)->raw([
'items' => [factory(InvoiceItem::class)->raw(['quantity' => null])]
]);
$response = $this->json('PUT', 'api/invoices/'.$invoice->id, $invoice2);
$response->assertStatus(422)->assertJsonValidationErrors(['items.0.quantity']);
}
/** @test */
public function testUpdateInvoiceRequiresItemsPrice()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$invoice2 = factory(Invoice::class)->raw([
'items' => [factory(InvoiceItem::class)->raw(['price' => null])]
]);
$response = $this->json('PUT', 'api/invoices/'.$invoice->id, $invoice2);
$response->assertStatus(422)->assertJsonValidationErrors(['items.0.price']);
}
/** @test */
public function testDeleteInvoice()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$response = $this->json('DELETE', 'api/invoices/'.$invoice->id);
$response
->assertOk()
->assertJson([
'success' => true
]);
$deleted = Invoice::find($invoice->id);
$this->assertNull($deleted);
}
/** @test */
public function testSendInvoiceToCustomer()
{
$invoices = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$data = [
'id' => $invoices->id
];
$response = $this->json('POST', 'api/invoices/send', $data);
$response
->assertOk()
->assertJson([
'success' => true
]);
$invoice2 = Invoice::find($invoices->id);
$this->assertEquals($invoice2->status, Invoice::STATUS_SENT);
}
/** @test */
public function testInvoiceMarkAsPaid()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$data = [
'id' => $invoice->id
];
$response = $this->json('POST', 'api/invoices/mark-as-paid', $data);
$response
->assertOk()
->assertJson([
'success' => true
]);
$invoice2 = Invoice::find($invoice->id);
$this->assertEquals($invoice2->status, Invoice::STATUS_PAID);
}
/** @test */
public function testInvoiceMarkAsSent()
{
$invoice = factory(Invoice::class)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$data = [
'id' => $invoice->id
];
$response = $this->json('POST', 'api/invoices/mark-as-sent', $data);
$response
->assertOk()
->assertJson([
'success' => true
]);
$invoice2 = Invoice::find($invoice->id);
$this->assertEquals($invoice2->status, Invoice::STATUS_SENT);
}
/** @test */
public function testSearchInvoices()
{
$filters = [
'page' => 1,
'limit' => 15,
'search' => 'doe',
'status' => Invoice::STATUS_DRAFT,
'from_date' => '01/09/2019',
'to_date' => '11/09/2019',
'invoice_number' => '000012'
];
$queryString = http_build_query($filters, '', '&');
$response = $this->json('GET', 'api/invoices?'.$queryString);
$response->assertOk();
}
/** @test */
public function testDeleteMultipleInvoices()
{
$invoices = factory(Invoice::class,3)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$ids = $invoices->pluck('id');
$data = [
'id' => $ids,
'type' => 'invoice'
];
$response = $this->json('POST', 'api/invoices/delete', $data);
$response
->assertOk()
->assertJson([
'success' => true
]);
}
}

182
tests/Feature/ItemTest.php Normal file
View File

@ -0,0 +1,182 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laraspace\Item;
use Laraspace\User;
use Laraspace\Tax;
use Laravel\Passport\Passport;
use SettingsSeeder;
class ItemTest extends TestCase
{
use RefreshDatabase;
protected $user;
public function setUp(): void
{
parent::setUp();
$this->seed();
$this->seed(SettingsSeeder::class);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Passport::actingAs(
$user,
['*']
);
}
/** @test */
public function testGetItems()
{
$response = $this->json('GET', 'api/items?page=1');
$response->assertOk();
}
/** @test */
public function testCreateItem()
{
$item = factory(Item::class)->raw([
'taxes' => [
factory(Tax::class)->raw(),
factory(Tax::class)->raw()
]
]);
$response = $this->json('POST', 'api/items', $item);
$response->assertOk();
}
/** @test */
public function testItemNameRequired()
{
$item = factory(Item::class)->raw(['name' => '']);
$response = $this->json('POST', 'api/items', $item);
$response->assertStatus(422)->assertJsonValidationErrors(['name']);
}
/** @test */
public function testItemPriceRequired()
{
$item = factory(Item::class)->raw(['price' => '']);
$response = $this->json('POST', 'api/items', $item);
$response->assertStatus(422)->assertJsonValidationErrors(['price']);
}
/** @test */
public function testGetEditItemData()
{
$item = factory(Item::class)->create();
$response = $this->json('GET', 'api/items/'.$item->id.'/edit');
$response
->assertOk()
->assertJson([
'item' => $item->toArray()
]);
}
/** @test */
public function testUpdateItem()
{
$item = factory(Item::class)->create();
$item2 = factory(Item::class)->raw([
'taxes' => [
factory(Tax::class)->raw(['tax_type_id' => $item->taxes[0]->tax_type_id]),
factory(Tax::class)->raw(['tax_type_id' => $item->taxes[1]->tax_type_id])
]
]);
$response = $this->json('PUT', 'api/items/'.$item->id, $item2);
$item3 = $response->decodeResponseJson()['item'];
$response->assertOk();
}
/** @test */
public function testUpdateItemNameRequired()
{
$item = factory(Item::class)->create();
$item2 = factory(Item::class)->raw(['name' => '']);
$response = $this->json('PUT', 'api/items/'.$item->id, $item2);
$response->assertStatus(422)->assertJsonValidationErrors(['name']);
}
/** @test */
public function testUpdateItemPriceRequired()
{
$item = factory(Item::class)->create();
$item2 = factory(Item::class)->raw(['price' => '']);
$response = $this->json('PUT', 'api/items/'.$item->id, $item2);
$response->assertStatus(422)->assertJsonValidationErrors(['price']);
}
/** @test */
public function testDeleteItem()
{
$item = factory(Item::class)->create();
$response = $this->json('DELETE', 'api/items/'.$item->id);
$response
->assertOk()
->assertJson([
'success' => true
]);
}
/** @test */
public function testSearchItems()
{
$filters = [
'page' => 1,
'limit' => 15,
'search' => 'doe',
'price' => 6,
'unit' => 'kg'
];
$queryString = http_build_query($filters, '', '&');
$response = $this->json('GET', 'api/items?'.$queryString);
$response->assertOk();
}
/** @test */
public function testDeleteMultipleItems()
{
$items = factory(Item::class, 3)->create();
$ids = $items->pluck('id');
$data = [
'id' => $ids,
'type' => 'item'
];
$response = $this->json('POST', 'api/items/delete', $data);
$response
->assertOk()
->assertJson([
'success' => true
]);
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laraspace\Country;
use Laraspace\State;
use Laraspace\City;
use SettingsSeeder;
class LocationTest extends TestCase
{
use RefreshDatabase;
public function setUp(): void
{
parent::setUp();
$this->seed();
$this->seed(SettingsSeeder::class);
}
/** @test */
public function testGetCountries()
{
$response = $this->json('GET', 'api/countries');
$response->assertOk();
}
/** @test */
public function testGetStates()
{
$response = $this->json('GET', 'api/states/1');
$response->assertOk();
}
/** @test */
public function testGetCities()
{
$response = $this->json('GET', 'api/cities/1');
$response->assertOk();
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class LoginTest extends TestCase
{
/** @test */
public function testLogin()
{
$data = array(
'username' => 'admin@crater.in',
'password' => 'admin@123'
);
$response = $this->json('POST', 'api/auth/login', $data);
$response->assertOk();
}
}

View File

@ -0,0 +1,111 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laraspace\Address;
class OnboardingTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
}
/** @test */
public function testGetOnboardingData()
{
$this->seed();
$response = $this->json('GET', 'api/admin/onboarding');
$response->assertOk();
$status = $response->decodeResponseJson()['profile_complete'];
$this->assertEquals($status, 0);
}
/** @test */
public function testUpdateOnboardingProfile()
{
$user = [
'name' => 'Jane Doe',
'password' => 'admin@123',
'email' => 'admin@crater.in'
];
$response = $this->json('POST', 'api/admin/onboarding/profile', $user);
$user2 = $response->decodeResponseJson()['user'];
$response->assertOk();
$this->assertEquals($user['name'], $user2['name']);
$this->assertEquals($user['email'], $user2['email']);
}
/** @test */
public function testGetOnboardingDataAfterProfileUpdate()
{
$response = $this->json('GET', 'api/admin/onboarding');
$response->assertOk();
$status = $response->decodeResponseJson()['profile_complete'];
$this->assertEquals($status, '1');
}
/** @test */
public function testUpdateCompanyDetails()
{
$company = [
'name' => 'XYZ',
'country_id' => 2
];
$response = $this->json('POST', 'api/admin/onboarding/company', $company);
$response->assertOk();
$company2 = $response->decodeResponseJson()['user']['company'];
$address2 = $response->decodeResponseJson()['user']['addresses'][0];
$this->assertEquals($company['name'], $company2['name']);
$this->assertEquals($company['country_id'], $address2['country_id']);
}
/** @test */
public function testGetOnboardingDataAfterCompanyUpdate()
{
$response = $this->json('GET', 'api/admin/onboarding');
$response->assertOk();
$status = $response->decodeResponseJson()['profile_complete'];
$this->assertEquals($status, '2');
}
/** @test */
public function testUpdateCompanySettings()
{
$settings = [
'currency' => 1,
'time_zone' => 'Asia/Kolkata',
'language' => 'en',
'fiscal_year' => '1-12',
'carbon_date_format' => 'Y/m/d',
'moment_date_format' => 'YYYY/MM/DD'
];
$response = $this->json('POST', 'api/admin/onboarding/settings', $settings);
$response->assertOk();
}
/** @test */
public function testGetOnboardingDataAfterSettingsUpdate()
{
$response = $this->json('GET', 'api/admin/onboarding');
$response->assertOk();
$status = $response->decodeResponseJson()['profile_complete'];
$this->assertEquals($status, 'COMPLETED');
}
}

View File

@ -0,0 +1,277 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laraspace\User;
use Laraspace\Invoice;
use Laraspace\Payment;
use Laravel\Passport\Passport;
use SettingsSeeder;
class PaymentTest extends TestCase
{
use RefreshDatabase;
protected $user;
public function setUp(): void
{
parent::setUp();
$this->seed();
$this->seed(SettingsSeeder::class);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Passport::actingAs(
$user,
['*']
);
}
/** @test */
public function testGetPayments()
{
$response = $this->json('GET', 'api/payments?page=1');
$response->assertOk();
}
/** @test */
public function testGetCreatePaymentData()
{
$response = $this->json('GET', 'api/payments/create');
$response->assertOk();
}
/** @test */
public function testCreatePayment()
{
$payment = factory(Payment::class)->raw();
$response = $this->json('POST', 'api/payments', $payment);
$payment2 = $response->decodeResponseJson()['payment'];
$response->assertOk();
$this->assertEquals($payment['payment_number'], $payment2['payment_number']);
$this->assertEquals($payment['user_id'], $payment2['user_id']);
$this->assertEquals($payment['amount'], $payment2['amount']);
}
/** @test */
public function testCreatePaymentRequiresPaymentNumber()
{
$payment = factory(Payment::class)->raw([
'payment_number' => ''
]);
$response = $this->json('POST', 'api/payments', $payment);
$response->assertStatus(422)->assertJsonValidationErrors(['payment_number']);
}
/** @test */
public function testCreatePaymentRequiresAmount()
{
$payment = factory(Payment::class)->raw([
'amount' => ''
]);
$response = $this->json('POST', 'api/payments', $payment);
$response->assertStatus(422)->assertJsonValidationErrors(['amount']);
}
/** @test */
public function testCreatePaymentRequiresUser()
{
$payment = factory(Payment::class)->raw([
'user_id' => ''
]);
$response = $this->json('POST', 'api/payments', $payment);
$response->assertStatus(422)->assertJsonValidationErrors(['user_id']);
}
/** @test */
public function testCreatePaymentRequiresPaymentDate()
{
$payment = factory(Payment::class)->raw([
'payment_date' => ''
]);
$response = $this->json('POST', 'api/payments', $payment);
$response->assertStatus(422)->assertJsonValidationErrors(['payment_date']);
}
/** @test */
public function testGetEditPaymentData()
{
$payment = factory(Payment::class)->create([
'payment_date' => '1988-07-18'
]);
$response = $this->json('GET', 'api/payments/'.$payment->id.'/edit');
$response->assertOk();
}
/** @test */
public function testUpdateEstimate()
{
$payment = factory(Payment::class)->create([
'payment_date' => '1988-07-18'
]);
$payment2 = factory(Payment::class)->raw([
'payment_number' => $payment->payment_number
]);
$response = $this->json('PUT', 'api/payments/'.$payment->id, $payment2);
$payment3 = $response->decodeResponseJson()['payment'];
$response->assertOk();
$this->assertEquals($payment3['payment_number'], $payment2['payment_number']);
$this->assertEquals($payment3['user_id'], $payment2['user_id']);
$this->assertEquals($payment3['amount'], $payment2['amount']);
}
/** @test */
public function testUpdatePaymentRequiresPaymentDate()
{
$payment = factory(Payment::class)->create([
'payment_date' => '1988-07-18'
]);
$payment2 = factory(Payment::class)->raw(['payment_date' => '']);
$response = $this->json('PUT', 'api/payments/'.$payment->id, $payment2);
$response->assertStatus(422)->assertJsonValidationErrors(['payment_date']);
}
/** @test */
public function testUpdatePaymentRequiresPaymentNumber()
{
$payment = factory(Payment::class)->create([
'payment_date' => '1988-07-18'
]);
$payment2 = factory(Payment::class)->raw(['payment_number' => '']);
$response = $this->json('PUT', 'api/payments/'.$payment->id, $payment2);
$response->assertStatus(422)->assertJsonValidationErrors(['payment_number']);
}
/** @test */
public function testUpdatePaymentRequiresAmount()
{
$payment = factory(Payment::class)->create([
'payment_date' => '1988-07-18'
]);
$payment2 = factory(Payment::class)->raw(['amount' => '']);
$response = $this->json('PUT', 'api/payments/'.$payment->id, $payment2);
$response->assertStatus(422)->assertJsonValidationErrors(['amount']);
}
/** @test */
public function testUpdatePaymentRequiresUser()
{
$payment = factory(Payment::class)->create([
'payment_date' => '1988-07-18'
]);
$payment2 = factory(Payment::class)->raw(['user_id' => '']);
$response = $this->json('PUT', 'api/payments/'.$payment->id, $payment2);
$response->assertStatus(422)->assertJsonValidationErrors(['user_id']);
}
/** @test */
public function testDeletePayment()
{
$payment = factory(Payment::class)->create([
'payment_date' => '1988-07-18'
]);
$response = $this->json('DELETE', 'api/payments/'.$payment->id);
$response
->assertOk()
->assertJson([
'success' => true
]);
$payment = Payment::find($payment->id);
$this->assertNull($payment);
}
/** @test */
public function testSearchPayments()
{
$filters = [
'page' => 1,
'limit' => 15,
'search' => 'doe',
'payment_number' => 'PAY-000001',
'payment_mode' => 'OTHER'
];
$queryString = http_build_query($filters, '', '&');
$response = $this->json('GET', 'api/payments?'.$queryString);
$response->assertOk();
}
/** @test */
public function getUnpaidInvoicesOfUser()
{
$user = factory(User::class)->create();
$invoices = factory(Invoice::class, 2)->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
'user_id' => $user->id
]);
$response = $this->json('GET', 'api/invoices/unpaid/'.$user->id);
$response->assertOk();
}
/** @test */
public function testDeleteMultiplePayments()
{
$payments = factory(Payment::class, 3)->create([
'payment_date' => '1988-07-18'
]);
$ids = $payments->pluck('id');
$data = [
'id' => $ids,
'type' => 'payment'
];
$response = $this->json('POST', 'api/payments/delete', $data);
$response
->assertOk()
->assertJson([
'success' => true
]);
}
}

View File

@ -0,0 +1,117 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use Laraspace\User;
use Laraspace\Company;
use Laravel\Passport\Passport;
use SettingsSeeder;
class ReportTest extends TestCase
{
use RefreshDatabase;
protected $user;
public function setUp(): void
{
parent::setUp();
$this->seed();
$this->seed(SettingsSeeder::class);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Passport::actingAs(
$user,
['*']
);
}
/** @test */
public function testGetCustomerSalesReport()
{
$filters = [
'page' => 1,
'limit' => 15,
'from_date' => '01/02/2019',
'to_date' => '10/02/2019',
];
$queryString = http_build_query($filters, '', '&');
$queryString = Company::find(1)->unique_hash . '?' . $queryString;
$response = $this->json('GET', 'reports/sales/customers/'. $queryString);
$response->assertOk();
}
/** @test */
public function testGetItemSalesReport()
{
$filters = [
'page' => 1,
'limit' => 15,
'from_date' => '01/02/2019',
'to_date' => '10/02/2019',
];
$queryString = http_build_query($filters, '', '&');
$queryString = Company::find(1)->unique_hash . '?' . $queryString;
$response = $this->json('GET', 'reports/sales/items/' . $queryString);
$response->assertOk();
}
/** @test */
public function testGetExpensesReport()
{
$filters = [
'page' => 1,
'limit' => 15,
'from_date' => '01/02/2019',
'to_date' => '10/02/2019',
];
$queryString = http_build_query($filters, '', '&');
$queryString = Company::find(1)->unique_hash . '?' . $queryString;
$response = $this->json('GET', 'reports/expenses/' . $queryString);
$response->assertOk();
}
/** @test */
public function testGetTaxSummary()
{
$filters = [
'page' => 1,
'limit' => 15,
'from_date' => '01/02/2019',
'to_date' => '10/02/2019',
];
$queryString = http_build_query($filters, '', '&');
$queryString = Company::find(1)->unique_hash . '?' . $queryString;
$response = $this->json('GET', 'reports/tax-summary/' . $queryString);
$response->assertOk();
}
/** @test */
public function testGetProfitLoss()
{
$filters = [
'page' => 1,
'limit' => 15,
'from_date' => '01/02/2019',
'to_date' => '10/02/2019',
];
$queryString = http_build_query($filters, '', '&');
$queryString = Company::find(1)->unique_hash . '?' . $queryString;
$response = $this->json('GET', 'reports/profit-loss/' . $queryString);
$response->assertOk();
}
}

View File

@ -0,0 +1,138 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laraspace\User;
use Laraspace\TaxType;
use Laravel\Passport\Passport;
use SettingsSeeder;
class TaxTypeTest extends TestCase
{
use RefreshDatabase;
protected $user;
public function setUp(): void
{
parent::setUp();
$this->seed();
$this->seed(SettingsSeeder::class);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Passport::actingAs(
$user,
['*']
);
}
/** @test */
public function testGetTaxTypes()
{
$response = $this->json('GET', 'api/tax-types');
$response->assertOk();
}
/** @test */
public function testCreateTaxType()
{
$taxType = factory(TaxType::class)->raw();
$response = $this->json('POST', 'api/tax-types', $taxType);
$response->assertOk()
->assertJson([
'taxType' => $taxType
]);
}
/** @test */
public function testCreateTaxTypeRequiresName()
{
$taxType = factory(TaxType::class)->raw(['name' => '']);
$response = $this->json('POST', 'api/tax-types', $taxType);
$response->assertStatus(422)->assertJsonValidationErrors(['name']);
}
/** @test */
public function testCreateTaxTypeRequiresPercent()
{
$taxType = factory(TaxType::class)->raw(['percent' => '']);
$response = $this->json('POST', 'api/tax-types', $taxType);
$response->assertStatus(422)->assertJsonValidationErrors(['percent']);
}
/** @test */
public function testGetEditTaxTypeData()
{
$taxType = factory(TaxType::class)->create();
$response = $this->json('GET', 'api/tax-types/'.$taxType->id.'/edit');
$response->assertOk()
->assertJson([
'taxType' => $taxType->toArray()
]);
}
/** @test */
public function testUpdateTaxType()
{
$taxType = factory(TaxType::class)->create();
$taxType2 = factory(TaxType::class)->raw();
$response = $this->json('PUT', 'api/tax-types/'.$taxType->id, $taxType2);
$response->assertOk()
->assertJson([
'taxType' => $taxType2
]);
}
/** @test */
public function testUpdateTaxTypeRequiresName()
{
$taxType = factory(TaxType::class)->create();
$taxType2 = factory(TaxType::class)->raw(['name' => '']);
$response = $this->json('PUT', 'api/tax-types/'.$taxType->id, $taxType2);
$response->assertStatus(422)->assertJsonValidationErrors(['name']);
}
/** @test */
public function testUpdateTaxTypeRequiresPercent()
{
$taxType = factory(TaxType::class)->create();
$taxType2 = factory(TaxType::class)->raw(['percent' => '']);
$response = $this->json('PUT', 'api/tax-types/'.$taxType->id, $taxType2);
$response->assertStatus(422)->assertJsonValidationErrors(['percent']);
}
/** @test */
public function testDeleteTaxType()
{
$taxType = factory(TaxType::class)->create();
$response = $this->json('DELETE', 'api/tax-types/'.$taxType->id);
$response->assertOk()
->assertJson([
'success' => true
]);
$this->assertNull(TaxType::find($taxType->id));
}
}