mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-22 17:32:14 +00:00
backend refactored
This commit is contained in:
@@ -19,267 +19,36 @@ class OasisInvoiceTest extends TestCase
|
||||
{
|
||||
use DatabaseMigrations, Queueable;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_test_invoice_factory()
|
||||
public function __construct()
|
||||
{
|
||||
$invoice = Invoice::factory(Invoice::class)
|
||||
->create();
|
||||
parent::__construct();
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'id' => $invoice->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function user_create_new_invoice_with_storing_new_client()
|
||||
{
|
||||
Notification::fake();
|
||||
Storage::fake('local');
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$avatar = UploadedFile::fake()
|
||||
->image('fake-image.jpg');
|
||||
|
||||
$this->postJson('/api/oasis/invoices', [
|
||||
'invoice_type' => 'regular-invoice',
|
||||
'invoice_number' => '2120001',
|
||||
'variable_number' => '2120001',
|
||||
'client' => 'others',
|
||||
'client_avatar' => $avatar,
|
||||
'client_name' => 'VueFileManager Inc.',
|
||||
'client_email' => 'howdy@hi5ve.digital',
|
||||
'client_phone_number' => '+421 950 123 456',
|
||||
'client_address' => 'Does 12',
|
||||
'client_city' => 'Bratislava',
|
||||
'client_postal_code' => '076 54',
|
||||
'client_country' => 'SK',
|
||||
'client_ico' => 11111111,
|
||||
'client_dic' => 11111111,
|
||||
'client_ic_dph' => 'SK11111111',
|
||||
'items' => [
|
||||
[
|
||||
'description' => 'Test 1',
|
||||
'amount' => 1,
|
||||
'tax_rate' => 20,
|
||||
'price' => 200,
|
||||
],
|
||||
[
|
||||
'description' => 'Test 2',
|
||||
'amount' => 3,
|
||||
'tax_rate' => 20,
|
||||
'price' => 500,
|
||||
],
|
||||
$this->items = [
|
||||
[
|
||||
'description' => 'Test 1',
|
||||
'amount' => 1,
|
||||
'tax_rate' => 20,
|
||||
'price' => 200,
|
||||
],
|
||||
'discount_type' => 'percent',
|
||||
'discount_rate' => 10,
|
||||
'delivery_at' => Carbon::now()->addWeek(),
|
||||
'store_client' => true,
|
||||
'send_invoice' => true,
|
||||
])->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => '2120001',
|
||||
'user_id' => $user->id,
|
||||
'items' => json_encode([
|
||||
[
|
||||
'description' => 'Test 1',
|
||||
'amount' => 1,
|
||||
'tax_rate' => 20,
|
||||
'price' => 200,
|
||||
],
|
||||
[
|
||||
'description' => 'Test 2',
|
||||
'amount' => 3,
|
||||
'tax_rate' => 20,
|
||||
'price' => 500,
|
||||
],
|
||||
]),
|
||||
'client' => json_encode([
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
'name' => 'VueFileManager Inc.',
|
||||
'address' => 'Does 12',
|
||||
'city' => 'Bratislava',
|
||||
'postal_code' => '076 54',
|
||||
'country' => 'SK',
|
||||
'ico' => 11111111,
|
||||
'dic' => 11111111,
|
||||
'ic_dph' => 'SK11111111',
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('clients', [
|
||||
'user_id' => $user->id,
|
||||
'name' => 'VueFileManager Inc.',
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
]);
|
||||
|
||||
Storage::disk('local')
|
||||
->assertExists(Client::first()->getRawOriginal('avatar'));
|
||||
|
||||
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function user_create_new_invoice_without_storing_client()
|
||||
{
|
||||
Notification::fake();
|
||||
Storage::fake('local');
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->postJson('/api/oasis/invoices', [
|
||||
'invoice_type' => 'regular-invoice',
|
||||
'invoice_number' => '2120001',
|
||||
'variable_number' => '2120001',
|
||||
'client' => 'others',
|
||||
'client_name' => 'VueFileManager Inc.',
|
||||
'client_email' => 'howdy@hi5ve.digital',
|
||||
'client_phone_number' => '+421 950 123 456',
|
||||
'client_address' => 'Does 12',
|
||||
'client_city' => 'Bratislava',
|
||||
'client_postal_code' => '076 54',
|
||||
'client_country' => 'SK',
|
||||
'client_ico' => 11111111,
|
||||
'client_dic' => 11111111,
|
||||
'client_ic_dph' => 'SK11111111',
|
||||
'items' => [
|
||||
[
|
||||
'description' => 'Test 1',
|
||||
'amount' => 1,
|
||||
'tax_rate' => 20,
|
||||
'price' => 200,
|
||||
],
|
||||
[
|
||||
'description' => 'Test 2',
|
||||
'amount' => 3,
|
||||
'tax_rate' => 20,
|
||||
'price' => 500,
|
||||
],
|
||||
[
|
||||
'description' => 'Test 2',
|
||||
'amount' => 3,
|
||||
'tax_rate' => 20,
|
||||
'price' => 500,
|
||||
],
|
||||
'discount_type' => 'percent',
|
||||
'discount_rate' => 10,
|
||||
'delivery_at' => Carbon::now()->addWeek(),
|
||||
'store_client' => false,
|
||||
'send_invoice' => true,
|
||||
])->assertStatus(201);
|
||||
];
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => '2120001',
|
||||
'user_id' => $user->id,
|
||||
'items' => json_encode([
|
||||
[
|
||||
'description' => 'Test 1',
|
||||
'amount' => 1,
|
||||
'tax_rate' => 20,
|
||||
'price' => 200,
|
||||
],
|
||||
[
|
||||
'description' => 'Test 2',
|
||||
'amount' => 3,
|
||||
'tax_rate' => 20,
|
||||
'price' => 500,
|
||||
],
|
||||
]),
|
||||
'client' => json_encode([
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
'name' => 'VueFileManager Inc.',
|
||||
'address' => 'Does 12',
|
||||
'city' => 'Bratislava',
|
||||
'postal_code' => '076 54',
|
||||
'country' => 'SK',
|
||||
'ico' => 11111111,
|
||||
'dic' => 11111111,
|
||||
'ic_dph' => 'SK11111111',
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('clients', [
|
||||
'name' => 'VueFileManager Inc.',
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
]);
|
||||
|
||||
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function user_create_new_invoice_with_existing_client()
|
||||
{
|
||||
Notification::fake();
|
||||
Storage::fake('local');
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$client = Client::factory(Client::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'name' => 'VueFileManager Inc.',
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
]);
|
||||
|
||||
$this->postJson('/api/oasis/invoices', [
|
||||
'invoice_type' => 'regular-invoice',
|
||||
'invoice_number' => '2120001',
|
||||
'variable_number' => '2120001',
|
||||
'client' => $client->id,
|
||||
'items' => [
|
||||
[
|
||||
'description' => 'Test 1',
|
||||
'amount' => 1,
|
||||
'tax_rate' => 20,
|
||||
'price' => 200,
|
||||
],
|
||||
[
|
||||
'description' => 'Test 2',
|
||||
'amount' => 3,
|
||||
'tax_rate' => 20,
|
||||
'price' => 500,
|
||||
],
|
||||
],
|
||||
'discount_type' => 'percent',
|
||||
'discount_rate' => 10,
|
||||
'delivery_at' => Carbon::now()->addWeek(),
|
||||
'send_invoice' => true,
|
||||
])->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => '2120001',
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $client->id,
|
||||
'items' => json_encode([
|
||||
[
|
||||
'description' => 'Test 1',
|
||||
'amount' => 1,
|
||||
'tax_rate' => 20,
|
||||
'price' => 200,
|
||||
],
|
||||
[
|
||||
'description' => 'Test 2',
|
||||
'amount' => 3,
|
||||
'tax_rate' => 20,
|
||||
'price' => 500,
|
||||
],
|
||||
]),
|
||||
]);
|
||||
|
||||
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
||||
$this->client = [
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
'name' => 'VueFileManager Inc.',
|
||||
'address' => 'Does 12',
|
||||
'city' => 'Bratislava',
|
||||
'postal_code' => '076 54',
|
||||
'country' => 'SK',
|
||||
'ico' => 11111111,
|
||||
'dic' => 11111111,
|
||||
'ic_dph' => 'SK11111111',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -384,6 +153,276 @@ class OasisInvoiceTest extends TestCase
|
||||
$this->assertEquals('40,00 Kč', invoice_total_tax($invoice, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_test_invoice_factory()
|
||||
{
|
||||
$invoice = Invoice::factory(Invoice::class)
|
||||
->create();
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'id' => $invoice->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function user_create_new_invoice_with_storing_new_client()
|
||||
{
|
||||
Notification::fake();
|
||||
Storage::fake('local');
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$avatar = UploadedFile::fake()
|
||||
->image('fake-image.jpg');
|
||||
|
||||
$this->postJson('/api/oasis/invoices', [
|
||||
'invoice_type' => 'regular-invoice',
|
||||
'invoice_number' => '2120001',
|
||||
'variable_number' => '2120001',
|
||||
'items' => $this->items,
|
||||
'discount_type' => 'percent',
|
||||
'discount_rate' => 10,
|
||||
'delivery_at' => Carbon::now()->addWeek(),
|
||||
'store_client' => true,
|
||||
'send_invoice' => true,
|
||||
|
||||
'client' => 'others',
|
||||
'client_avatar' => $avatar,
|
||||
'client_name' => 'VueFileManager Inc.',
|
||||
'client_email' => 'howdy@hi5ve.digital',
|
||||
'client_phone_number' => '+421 950 123 456',
|
||||
'client_address' => 'Does 12',
|
||||
'client_city' => 'Bratislava',
|
||||
'client_postal_code' => '076 54',
|
||||
'client_country' => 'SK',
|
||||
'client_ico' => 11111111,
|
||||
'client_dic' => 11111111,
|
||||
'client_ic_dph' => 'SK11111111',
|
||||
])->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => '2120001',
|
||||
'user_id' => $user->id,
|
||||
'items' => json_encode($this->items),
|
||||
'client' => json_encode($this->client),
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('clients', [
|
||||
'user_id' => $user->id,
|
||||
'name' => 'VueFileManager Inc.',
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
]);
|
||||
|
||||
Storage::disk('local')
|
||||
->assertExists(Client::first()->getRawOriginal('avatar'));
|
||||
|
||||
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function user_create_new_invoice_with_storing_new_client_without_avatar_and_mail()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->postJson('/api/oasis/invoices', [
|
||||
'invoice_type' => 'regular-invoice',
|
||||
'invoice_number' => '2120001',
|
||||
'variable_number' => '2120001',
|
||||
'items' => $this->items,
|
||||
'discount_type' => 'percent',
|
||||
'discount_rate' => 10,
|
||||
'delivery_at' => Carbon::now()->addWeek(),
|
||||
'store_client' => true,
|
||||
'send_invoice' => true,
|
||||
|
||||
'client' => 'others',
|
||||
'client_avatar' => null,
|
||||
'client_name' => 'VueFileManager Inc.',
|
||||
'client_email' => null,
|
||||
'client_phone_number' => '+421 950 123 456',
|
||||
'client_address' => 'Does 12',
|
||||
'client_city' => 'Bratislava',
|
||||
'client_postal_code' => '076 54',
|
||||
'client_country' => 'SK',
|
||||
'client_ico' => 11111111,
|
||||
'client_dic' => 11111111,
|
||||
'client_ic_dph' => 'SK11111111',
|
||||
])->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => '2120001',
|
||||
'user_id' => $user->id,
|
||||
'items' => json_encode($this->items),
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('clients', [
|
||||
'user_id' => $user->id,
|
||||
'name' => 'VueFileManager Inc.',
|
||||
]);
|
||||
|
||||
Notification::assertNothingSent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function user_create_new_invoice_without_storing_client_without_avatar_and_mail()
|
||||
{
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->postJson('/api/oasis/invoices', [
|
||||
'invoice_type' => 'regular-invoice',
|
||||
'invoice_number' => '2120001',
|
||||
'variable_number' => '2120001',
|
||||
'items' => $this->items,
|
||||
'discount_type' => 'percent',
|
||||
'discount_rate' => 10,
|
||||
'delivery_at' => Carbon::now()->addWeek(),
|
||||
'store_client' => false,
|
||||
'send_invoice' => false,
|
||||
|
||||
'client' => 'others',
|
||||
'client_avatar' => null,
|
||||
'client_name' => 'VueFileManager Inc.',
|
||||
'client_email' => 'howdy@hi5ve.digital',
|
||||
'client_phone_number' => '+421 950 123 456',
|
||||
'client_address' => 'Does 12',
|
||||
'client_city' => 'Bratislava',
|
||||
'client_postal_code' => '076 54',
|
||||
'client_country' => 'SK',
|
||||
'client_ico' => 11111111,
|
||||
'client_dic' => 11111111,
|
||||
'client_ic_dph' => 'SK11111111',
|
||||
])->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => '2120001',
|
||||
'user_id' => $user->id,
|
||||
'items' => json_encode($this->items),
|
||||
'client' => json_encode($this->client),
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('clients', [
|
||||
'user_id' => $user->id,
|
||||
'name' => 'VueFileManager Inc.',
|
||||
]);
|
||||
|
||||
Notification::assertNothingSent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function user_create_new_invoice_without_storing_client()
|
||||
{
|
||||
Notification::fake();
|
||||
Storage::fake('local');
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->postJson('/api/oasis/invoices', [
|
||||
'invoice_type' => 'regular-invoice',
|
||||
'invoice_number' => '2120001',
|
||||
'variable_number' => '2120001',
|
||||
'items' => $this->items,
|
||||
'discount_type' => 'percent',
|
||||
'discount_rate' => 10,
|
||||
'delivery_at' => Carbon::now()->addWeek(),
|
||||
'store_client' => false,
|
||||
'send_invoice' => true,
|
||||
|
||||
'client' => 'others',
|
||||
'client_name' => 'VueFileManager Inc.',
|
||||
'client_email' => 'howdy@hi5ve.digital',
|
||||
'client_phone_number' => '+421 950 123 456',
|
||||
'client_address' => 'Does 12',
|
||||
'client_city' => 'Bratislava',
|
||||
'client_postal_code' => '076 54',
|
||||
'client_country' => 'SK',
|
||||
'client_ico' => 11111111,
|
||||
'client_dic' => 11111111,
|
||||
'client_ic_dph' => 'SK11111111',
|
||||
])->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => '2120001',
|
||||
'user_id' => $user->id,
|
||||
'items' => json_encode($this->items),
|
||||
'client' => json_encode($this->client),
|
||||
]);
|
||||
|
||||
$this->assertDatabaseMissing('clients', [
|
||||
'name' => 'VueFileManager Inc.',
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
]);
|
||||
|
||||
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function user_create_new_invoice_with_existing_client()
|
||||
{
|
||||
Notification::fake();
|
||||
Storage::fake('local');
|
||||
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$client = Client::factory(Client::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'name' => 'VueFileManager Inc.',
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
]);
|
||||
|
||||
$this->postJson('/api/oasis/invoices', [
|
||||
'invoice_type' => 'regular-invoice',
|
||||
'invoice_number' => '2120001',
|
||||
'variable_number' => '2120001',
|
||||
'client' => $client->id,
|
||||
'items' => $this->items,
|
||||
'discount_type' => 'percent',
|
||||
'discount_rate' => 10,
|
||||
'delivery_at' => Carbon::now()->addWeek(),
|
||||
'send_invoice' => true,
|
||||
])->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => '2120001',
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $client->id,
|
||||
'items' => json_encode($this->items),
|
||||
]);
|
||||
|
||||
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user