You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
193 lines
6.3 KiB
193 lines
6.3 KiB
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Entities\Partners\Customer;
|
|
use App\Entities\Projects\Project;
|
|
use App\Services\InvoiceDrafts\InvoiceDraft;
|
|
use App\Services\InvoiceDrafts\InvoiceDraftCollection;
|
|
use App\Services\InvoiceDrafts\Item;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Invoice Entry Feature Test
|
|
*
|
|
* @author Nafies Luthfi <nafiesl@gmail.com>
|
|
*/
|
|
class InvoiceEntryTest extends TestCase
|
|
{
|
|
/** @test */
|
|
public function user_can_visit_invoice_drafts_page()
|
|
{
|
|
$this->adminUserSigningIn();
|
|
|
|
// Add new draft to collection
|
|
$cart = new InvoiceDraftCollection();
|
|
$draft = $cart->add(new InvoiceDraft());
|
|
|
|
$this->visit(route('invoice-drafts.index'));
|
|
|
|
$this->assertViewHas('draft', $draft);
|
|
}
|
|
|
|
/** @test */
|
|
public function user_can_create_invoice_draft_by_invoice_create_button()
|
|
{
|
|
$this->adminUserSigningIn();
|
|
$this->visit(route('invoice-drafts.index'));
|
|
|
|
$this->press(trans('invoice.create'));
|
|
$cart = new InvoiceDraftCollection();
|
|
$draft = $cart->content()->last();
|
|
$this->seePageIs(route('invoice-drafts.show', $draft->draftKey));
|
|
}
|
|
|
|
/** @test */
|
|
public function user_can_add_item_to_invoice_draft()
|
|
{
|
|
$this->adminUserSigningIn();
|
|
|
|
$cart = new InvoiceDraftCollection();
|
|
$draft = new InvoiceDraft();
|
|
$cart->add($draft);
|
|
|
|
$this->visit(route('invoice-drafts.show', $draft->draftKey));
|
|
|
|
$this->type('Testing deskripsi invoice item', 'new_item_description');
|
|
$this->type(2000, 'new_item_amount');
|
|
$this->press(trans('invoice.add_item'));
|
|
|
|
$this->see(trans('invoice.item_added'));
|
|
|
|
$this->type('Testing deskripsi invoice item', 'new_item_description');
|
|
$this->type(3000, 'new_item_amount');
|
|
$this->press(trans('invoice.add_item'));
|
|
|
|
$this->seePageIs(route('invoice-drafts.show', $draft->draftKey));
|
|
$this->assertEquals(5000, $draft->getTotal());
|
|
$this->see(formatRp(5000));
|
|
}
|
|
|
|
/** @test */
|
|
public function user_can_remove_an_invoice_draft()
|
|
{
|
|
$this->adminUserSigningIn();
|
|
|
|
$cart = new InvoiceDraftCollection();
|
|
$draft = new InvoiceDraft();
|
|
$cart->add($draft);
|
|
|
|
$this->visit(route('invoice-drafts.show', $draft->draftKey));
|
|
$this->press('remove_draft_'.$draft->draftKey);
|
|
|
|
$this->seePageIs(route('invoice-drafts.index'));
|
|
$this->assertTrue($cart->isEmpty());
|
|
}
|
|
|
|
/** @test */
|
|
public function user_can_update_item_attribute()
|
|
{
|
|
$cart = new InvoiceDraftCollection();
|
|
|
|
$draft = $cart->add(new InvoiceDraft());
|
|
|
|
$item1 = new Item(['description' => 'Deskripsi item invoice', 'amount' => 1000]);
|
|
$item2 = new Item(['description' => 'Deskripsi item invoice', 'amount' => 2000]);
|
|
|
|
// Add items to draft
|
|
$cart->addItemToDraft($draft->draftKey, $item1);
|
|
$cart->addItemToDraft($draft->draftKey, $item2);
|
|
|
|
$this->adminUserSigningIn();
|
|
$this->visit(route('invoice-drafts.show', $draft->draftKey));
|
|
|
|
$this->submitForm('update-item-0', [
|
|
'item_key[0]' => 0,
|
|
'description[0]' => 'Testing deskripsi Update',
|
|
'amount[0]' => 100,
|
|
]);
|
|
|
|
$this->submitForm('update-item-1', [
|
|
'item_key[1]' => 1,
|
|
'description[1]' => 'Testing deskripsi Update',
|
|
'amount[1]' => 100,
|
|
]);
|
|
|
|
$this->assertEquals(200, $draft->getTotal());
|
|
|
|
$this->see(formatRp($draft->getTotal()));
|
|
}
|
|
|
|
/** @test */
|
|
public function user_can_update_draft_invoice_detail_and_get_confirm_page()
|
|
{
|
|
$user = $this->adminUserSigningIn();
|
|
$project = factory(Project::class)->create();
|
|
$cart = new InvoiceDraftCollection();
|
|
|
|
$draft = $cart->add(new InvoiceDraft());
|
|
|
|
$item1 = new Item(['description' => 'Deskripsi item invoice', 'amount' => 1000]);
|
|
$item2 = new Item(['description' => 'Deskripsi item invoice', 'amount' => 2000]);
|
|
|
|
// Add items to draft
|
|
$cart->addItemToDraft($draft->draftKey, $item1);
|
|
$cart->addItemToDraft($draft->draftKey, $item2);
|
|
|
|
$this->visit(route('invoice-drafts.show', $draft->draftKey));
|
|
|
|
$this->type($project->id, 'project_id');
|
|
$this->type('catatan', 'notes');
|
|
$this->press(trans('invoice.proccess'));
|
|
|
|
$this->seePageIs(route('invoice-drafts.show', [$draft->draftKey, 'action' => 'confirm']));
|
|
|
|
$this->see(trans('invoice.confirm_instruction'));
|
|
$this->see($project->name);
|
|
$this->see($draft->notes);
|
|
$this->see(formatRp(3000));
|
|
$this->seeElement('input', ['id' => 'save-invoice-draft']);
|
|
}
|
|
|
|
/** @test */
|
|
public function user_can_save_invoice_if_draft_is_completed()
|
|
{
|
|
$cart = new InvoiceDraftCollection();
|
|
|
|
$draft = $cart->add(new InvoiceDraft());
|
|
|
|
$item1 = new Item(['description' => 'Deskripsi item invoice', 'amount' => 1000]);
|
|
$item2 = new Item(['description' => 'Deskripsi item invoice', 'amount' => 2000]);
|
|
|
|
$user = $this->adminUserSigningIn();
|
|
$customer = factory(Customer::class)->create();
|
|
$project = factory(Project::class)->create(['customer_id' => $customer->id]);
|
|
|
|
// Add items to draft
|
|
$cart->addItemToDraft($draft->draftKey, $item1);
|
|
$cart->addItemToDraft($draft->draftKey, $item2);
|
|
|
|
$draftAttributes = [
|
|
'project_id' => $project->id,
|
|
'notes' => 'Catatan',
|
|
];
|
|
$cart->updateDraftAttributes($draft->draftKey, $draftAttributes);
|
|
|
|
$this->visit(route('invoice-drafts.show', [$draft->draftKey, 'action' => 'confirm']));
|
|
|
|
$this->press(trans('invoice.save'));
|
|
|
|
// $this->seePageIs(route('invoices.show', date('ym').'0001'));
|
|
// $this->see(trans('invoice.created', ['invoice_no' => date('ym').'0001']));
|
|
|
|
$this->seeInDatabase('invoices', [
|
|
'number' => date('ym').'001',
|
|
'items' => '[{"description":"Deskripsi item invoice","amount":1000},{"description":"Deskripsi item invoice","amount":2000}]',
|
|
'project_id' => $project->id,
|
|
'amount' => 3000,
|
|
'notes' => 'Catatan',
|
|
'creator_id' => $user->id,
|
|
'status_id' => 1,
|
|
]);
|
|
}
|
|
}
|