akaunting 3.0 (the last dance)
This commit is contained in:
		| @@ -1,89 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Tests\Feature\Auth; | ||||
|  | ||||
| use App\Jobs\Auth\CreatePermission; | ||||
| use App\Models\Auth\Permission; | ||||
| use Tests\Feature\FeatureTestCase; | ||||
|  | ||||
| class PermissionsTest extends FeatureTestCase | ||||
| { | ||||
|     public function testItShouldSeePermissionListPage() | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('permissions.index')) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSeeText(trans_choice('general.permissions', 2)); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldSeePermissionCreatePage() | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('permissions.create')) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.permissions', 1)])); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldCreatePermission() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post(route('permissions.store'), $request) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseHas('permissions', $request); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldSeePermissionUpdatePage() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $permission = $this->dispatch(new CreatePermission($request)); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->get(route('permissions.edit', $permission->id)) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSee($permission->name); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldUpdatePermission() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $permission = $this->dispatch(new CreatePermission($request)); | ||||
|  | ||||
|         $request['display_name'] = $this->faker->word; | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->patch(route('permissions.update', $permission->id), $request) | ||||
|             ->assertStatus(200) | ||||
| 			->assertSee($request['display_name']); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseHas('permissions', $request); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldDeletePermission() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $permission = $this->dispatch(new CreatePermission($request)); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->delete(route('permissions.destroy', $permission->id)) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseMissing('permissions', $request); | ||||
|     } | ||||
|  | ||||
|     public function getRequest() | ||||
|     { | ||||
|         return Permission::factory()->raw(); | ||||
|     } | ||||
| } | ||||
| @@ -1,96 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Tests\Feature\Auth; | ||||
|  | ||||
| use App\Jobs\Auth\CreateRole; | ||||
| use App\Models\Auth\Role; | ||||
| use Tests\Feature\FeatureTestCase; | ||||
|  | ||||
| class RolesTest extends FeatureTestCase | ||||
| { | ||||
|     public function testItShouldSeeRoleListPage() | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('roles.index')) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSeeText(trans_choice('general.roles', 2)); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldSeeRoleCreatePage() | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('roles.create')) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.roles', 1)])); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldCreateRole() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post(route('roles.store'), $request) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseHas('roles', $this->getAssertRequest($request)); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldSeeRoleUpdatePage() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $role = $this->dispatch(new CreateRole($request)); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->get(route('roles.edit', $role->id)) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSee($role->name); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldUpdateRole() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $role = $this->dispatch(new CreateRole($request)); | ||||
|  | ||||
|         $request['display_name'] = $this->faker->word; | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->patch(route('roles.update', $role->id), $request) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSee($request['display_name']); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseHas('roles', $this->getAssertRequest($request)); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldDeleteRole() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $role = $this->dispatch(new CreateRole($request)); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->delete(route('roles.destroy', $role->id)) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseMissing('roles', $this->getAssertRequest($request)); | ||||
|     } | ||||
|  | ||||
|     public function getRequest() | ||||
|     { | ||||
|         return Role::factory()->permissions()->raw(); | ||||
|     } | ||||
|  | ||||
|     public function getAssertRequest($request) | ||||
|     { | ||||
|         unset($request['permissions']); | ||||
|  | ||||
|         return $request; | ||||
|     } | ||||
| } | ||||
| @@ -12,7 +12,7 @@ class UsersTest extends FeatureTestCase | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('users.index')) | ||||
|             ->assertStatus(200) | ||||
|             ->assertOk() | ||||
|             ->assertSeeText(trans_choice('general.users', 2)); | ||||
|     } | ||||
|  | ||||
| @@ -20,8 +20,8 @@ class UsersTest extends FeatureTestCase | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('users.create')) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.users', 1)])); | ||||
|             ->assertOk() | ||||
|             ->assertSeeText(trans('general.title.invite', ['type' => trans_choice('general.users', 1)])); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldCreateUser() | ||||
| @@ -30,7 +30,7 @@ class UsersTest extends FeatureTestCase | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post(route('users.store'), $request) | ||||
|             ->assertStatus(200); | ||||
|             ->assertOk(); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
| @@ -45,7 +45,7 @@ class UsersTest extends FeatureTestCase | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->get(route('users.edit', $user->id)) | ||||
|             ->assertStatus(200) | ||||
|             ->assertOk() | ||||
|             ->assertSee($user->email); | ||||
|     } | ||||
|  | ||||
| @@ -55,11 +55,11 @@ class UsersTest extends FeatureTestCase | ||||
|  | ||||
|         $user = $this->dispatch(new CreateUser($request)); | ||||
|  | ||||
|         $request['email'] = $this->faker->safeEmail; | ||||
|         $request['email'] = $this->faker->freeEmail; | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->patch(route('users.update', $user->id), $request) | ||||
|             ->assertStatus(200) | ||||
|             ->assertOk() | ||||
| 			->assertSee($request['email']); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
| @@ -75,7 +75,7 @@ class UsersTest extends FeatureTestCase | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->delete(route('users.destroy', $user->id)) | ||||
|             ->assertStatus(200); | ||||
|             ->assertOk(); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
| @@ -85,7 +85,7 @@ class UsersTest extends FeatureTestCase | ||||
|     public function testItShouldSeeLoginPage() | ||||
|     { | ||||
|         $this->get(route('login')) | ||||
|             ->assertStatus(200) | ||||
|             ->assertOk() | ||||
|             ->assertSeeText(trans('auth.login_to')); | ||||
|     } | ||||
|  | ||||
| @@ -96,7 +96,7 @@ class UsersTest extends FeatureTestCase | ||||
|         $user = $this->dispatch(new CreateUser($request)); | ||||
|  | ||||
|         $this->post(route('login'), ['email' => $user->email, 'password' => $user->password]) | ||||
|             ->assertStatus(200); | ||||
|             ->assertOk(); | ||||
|  | ||||
|         $this->isAuthenticated($user->user); | ||||
|     } | ||||
| @@ -108,7 +108,7 @@ class UsersTest extends FeatureTestCase | ||||
|         $user = $this->dispatch(new CreateUser($request)); | ||||
|  | ||||
|         $this->post(route('login'), ['email' => $user->email, 'password' => $this->faker->password()]) | ||||
|             ->assertStatus(200); | ||||
|             ->assertOk(); | ||||
|  | ||||
|         $this->assertGuest(); | ||||
|     } | ||||
|   | ||||
							
								
								
									
										194
									
								
								tests/Feature/Banking/TransactionsTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										194
									
								
								tests/Feature/Banking/TransactionsTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,194 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Tests\Feature\Banking; | ||||
|  | ||||
| use App\Exports\Banking\Transactions as Export; | ||||
| use App\Jobs\Banking\CreateTransaction; | ||||
| use App\Models\Banking\Transaction; | ||||
| use Illuminate\Http\UploadedFile; | ||||
| use Illuminate\Support\Facades\File; | ||||
| use Tests\Feature\FeatureTestCase; | ||||
|  | ||||
| class TransactionsTest extends FeatureTestCase | ||||
| { | ||||
|     public function testItShouldSeeTransactionListPage() | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('transactions.index')) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSeeText(trans_choice('general.transactions', 2)); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldSeeTransactionShowPage() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $transaction = $this->dispatch(new CreateTransaction($request)); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->get(route('transactions.show', $transaction->id)) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSee($transaction->contact->email); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldSeeTransactionCreatePage() | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('transactions.create', ['type' => 'income'])) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.incomes', 1)])); | ||||
|     } | ||||
|  | ||||
|    public function testItShouldCreateTransaction() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post(route('transactions.store'), $request) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseHas('transactions', $request); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldCreateTransactionWithRecurring() | ||||
|     { | ||||
|         $request = $this->getRequest(true); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post(route('recurring-transactions.store'), $request) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseHas('transactions', [ | ||||
|             'type' => 'income-recurring', | ||||
|             'paid_at' => $request['recurring_started_at'], | ||||
|             'amount' => $request['amount'], | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
| 	public function testItShouldSeeTransactionUpdatePage() | ||||
| 	{ | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $transaction = $this->dispatch(new CreateTransaction($request)); | ||||
|  | ||||
| 		$this->loginAs() | ||||
| 			->get(route('transactions.edit', $transaction->id)) | ||||
| 			->assertStatus(200) | ||||
| 			->assertSee($transaction->amount); | ||||
| 	} | ||||
|  | ||||
|     public function testItShouldUpdateTransaction() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $transaction = $this->dispatch(new CreateTransaction($request)); | ||||
|  | ||||
|         $request['amount'] = $this->faker->randomFloat(2, 1, 1000); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->patch(route('transactions.update', $transaction->id), $request) | ||||
|             ->assertStatus(200) | ||||
| 			->assertSee($request['amount']); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseHas('transactions', $request); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldDeleteTransaction() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $transaction = $this->dispatch(new CreateTransaction($request)); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->delete(route('transactions.destroy', $transaction->id)) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertSoftDeleted('transactions', $request); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldExportTransactions() | ||||
|     { | ||||
|         $count = 5; | ||||
|         Transaction::factory()->income()->count($count)->create(); | ||||
|  | ||||
|         \Excel::fake(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->get(route('transactions.export')) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         \Excel::matchByRegex(); | ||||
|  | ||||
|         \Excel::assertDownloaded( | ||||
|             '/' . \Str::filename(trans_choice('general.transactions', 2)) . '-\d{10}\.xlsx/', | ||||
|             function (Export $export) use ($count) { | ||||
|                 // Assert that the correct export is downloaded. | ||||
|                 return $export->collection()->count() === $count; | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldExportSelectedTransactions() | ||||
|     { | ||||
|         $create_count = 5; | ||||
|         $select_count = 3; | ||||
|  | ||||
|         $transactions = Transaction::factory()->income()->count($create_count)->create(); | ||||
|  | ||||
|         \Excel::fake(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post( | ||||
|                 route('bulk-actions.action', ['group' => 'banking', 'type' => 'transactions']), | ||||
|                 ['handle' => 'export', 'selected' => $transactions->take($select_count)->pluck('id')->toArray()] | ||||
|             ) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         \Excel::matchByRegex(); | ||||
|  | ||||
|         \Excel::assertDownloaded( | ||||
|             '/' . \Str::filename(trans_choice('general.transactions', 2)) . '-\d{10}\.xlsx/', | ||||
|             function (Export $export) use ($select_count) { | ||||
|                 return $export->collection()->count() === $select_count; | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldImportTransactions() | ||||
|     { | ||||
|         \Excel::fake(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post( | ||||
|                 route('transactions.import'), | ||||
|                 [ | ||||
|                     'import' => UploadedFile::fake()->createWithContent( | ||||
|                         'transactions.xlsx', | ||||
|                         File::get(public_path('files/import/transactions.xlsx')) | ||||
|                     ), | ||||
|                 ] | ||||
|             ) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         \Excel::assertImported('transactions.xlsx'); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|     } | ||||
|  | ||||
|     public function getRequest($recurring = false) | ||||
|     { | ||||
|         $factory = Transaction::factory(); | ||||
|  | ||||
|         $factory = $recurring ? $factory->income()->recurring() : $factory->income(); | ||||
|  | ||||
|         return $factory->raw(); | ||||
|     } | ||||
| } | ||||
| @@ -2,7 +2,9 @@ | ||||
|  | ||||
| namespace Tests\Feature\Commands; | ||||
|  | ||||
| use App\Jobs\Banking\CreateTransaction; | ||||
| use App\Jobs\Document\CreateDocument; | ||||
| use App\Models\Banking\Transaction; | ||||
| use App\Models\Document\Document; | ||||
| use App\Notifications\Sale\Invoice as InvoiceNotification; | ||||
| use App\Utilities\Date; | ||||
| @@ -20,13 +22,13 @@ class RecurringCheckTest extends FeatureTestCase | ||||
|         $this->recurring_count = 7; | ||||
|     } | ||||
|  | ||||
|     public function testItShouldCreateCorrectNumberOfRecurringInvoices(): void | ||||
|     public function testItShouldCreateCorrectNumberOfRecurringInvoicesByCount(): void | ||||
|     { | ||||
|         Notification::fake(); | ||||
|  | ||||
|         $this->dispatch(new CreateDocument($this->getRequest())); | ||||
|         $this->dispatch(new CreateDocument($this->getInvoiceRequest('count'))); | ||||
|  | ||||
|         Date::setTestNow(Date::now()); | ||||
|         Date::setTestNow(Date::today()); | ||||
|  | ||||
|         $this->artisan('recurring:check'); | ||||
|  | ||||
| @@ -35,13 +37,28 @@ class RecurringCheckTest extends FeatureTestCase | ||||
|         Notification::assertSentToTimes($this->user, InvoiceNotification::class, $this->recurring_count); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldNotCreateAnyRecurringInvoice(): void | ||||
|     public function testItShouldCreateCorrectNumberOfRecurringInvoicesByDate(): void | ||||
|     { | ||||
|         Notification::fake(); | ||||
|  | ||||
|         $this->dispatch(new CreateDocument($this->getRequest())); | ||||
|         $this->dispatch(new CreateDocument($this->getInvoiceRequest('date'))); | ||||
|  | ||||
|         Date::setTestNow(Date::now()->subDays($this->recurring_count + 1)); | ||||
|         Date::setTestNow(Date::today()); | ||||
|  | ||||
|         $this->artisan('recurring:check'); | ||||
|  | ||||
|         $this->assertDatabaseCount('documents', $this->recurring_count + 1); | ||||
|  | ||||
|         Notification::assertSentToTimes($this->user, InvoiceNotification::class, $this->recurring_count); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldNotCreateAnyRecurringInvoiceByCount(): void | ||||
|     { | ||||
|         Notification::fake(); | ||||
|  | ||||
|         $this->dispatch(new CreateDocument($this->getInvoiceRequest('count'))); | ||||
|  | ||||
|         Date::setTestNow(Date::today()->subDays($this->recurring_count)); | ||||
|  | ||||
|         $this->artisan('recurring:check'); | ||||
|  | ||||
| @@ -50,11 +67,94 @@ class RecurringCheckTest extends FeatureTestCase | ||||
|         Notification::assertNotSentTo($this->user, InvoiceNotification::class); | ||||
|     } | ||||
|  | ||||
|     public function getRequest(): array | ||||
|     public function testItShouldNotCreateAnyRecurringInvoiceByDate(): void | ||||
|     { | ||||
|         return Document::factory()->invoice()->items()->recurring()->sent()->raw([ | ||||
|             'issued_at' => Date::now()->subDays($this->recurring_count + 1), | ||||
|             'recurring_count' => '20', | ||||
|         ]); | ||||
|         Notification::fake(); | ||||
|  | ||||
|         $this->dispatch(new CreateDocument($this->getInvoiceRequest('date'))); | ||||
|  | ||||
|         Date::setTestNow(Date::today()->subDays($this->recurring_count)); | ||||
|  | ||||
|         $this->artisan('recurring:check'); | ||||
|  | ||||
|         $this->assertDatabaseCount('documents', 1); | ||||
|  | ||||
|         Notification::assertNotSentTo($this->user, InvoiceNotification::class); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldCreateCorrectNumberOfRecurringExpensesByCount(): void | ||||
|     { | ||||
|         $this->dispatch(new CreateTransaction($this->getExpenseRequest('count'))); | ||||
|  | ||||
|         Date::setTestNow(Date::today()); | ||||
|  | ||||
|         $this->artisan('recurring:check'); | ||||
|  | ||||
|         $this->assertDatabaseCount('transactions', $this->recurring_count + 1); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldCreateCorrectNumberOfRecurringExpensesByDate(): void | ||||
|     { | ||||
|         $this->dispatch(new CreateTransaction($this->getExpenseRequest('date'))); | ||||
|  | ||||
|         Date::setTestNow(Date::today()); | ||||
|  | ||||
|         $this->artisan('recurring:check'); | ||||
|  | ||||
|         $this->assertDatabaseCount('transactions', $this->recurring_count + 1); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldNotCreateAnyRecurringExpenseByCount(): void | ||||
|     { | ||||
|         $this->dispatch(new CreateTransaction($this->getExpenseRequest('count'))); | ||||
|  | ||||
|         Date::setTestNow(Date::today()->subDays($this->recurring_count)); | ||||
|  | ||||
|         $this->artisan('recurring:check'); | ||||
|  | ||||
|         $this->assertDatabaseCount('transactions', 1); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldNotCreateAnyRecurringExpenseByDate(): void | ||||
|     { | ||||
|         $this->dispatch(new CreateTransaction($this->getExpenseRequest('date'))); | ||||
|  | ||||
|         Date::setTestNow(Date::today()->subDays($this->recurring_count)); | ||||
|  | ||||
|         $this->artisan('recurring:check'); | ||||
|  | ||||
|         $this->assertDatabaseCount('transactions', 1); | ||||
|     } | ||||
|  | ||||
|     public function getInvoiceRequest(string $limit_by): array | ||||
|     { | ||||
|         $request = Document::factory()->invoice()->items()->sent()->recurring()->raw(); | ||||
|  | ||||
|         return array_merge($request, $this->getRecurringData($limit_by)); | ||||
|     } | ||||
|  | ||||
|     public function getExpenseRequest(string $limit_by): array | ||||
|     { | ||||
|         $request = Transaction::factory()->expense()->recurring()->raw(); | ||||
|  | ||||
|         return array_merge($request, $this->getRecurringData($limit_by)); | ||||
|     } | ||||
|  | ||||
|     public function getRecurringData(string $limit_by): array | ||||
|     { | ||||
|         $data = [ | ||||
|             'recurring_started_at' => Date::today()->subDays($this->recurring_count - 1), | ||||
|             'recurring_limit' => $limit_by, | ||||
|         ]; | ||||
|  | ||||
|         if ($limit_by == 'count') { | ||||
|             $data['recurring_limit_count'] = 20; | ||||
|         } | ||||
|  | ||||
|         if ($limit_by == 'date') { | ||||
|             $data['recurring_limit_date'] = Date::today()->addDays($this->recurring_count + 5)->toDateTimeString(); | ||||
|         } | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -4,8 +4,9 @@ namespace Tests\Feature\Common; | ||||
|  | ||||
| use App\Models\Common\Widget; | ||||
| use App\Models\Common\Dashboard; | ||||
| use Tests\Feature\FeatureTestCase; | ||||
| use App\Jobs\Common\CreateDashboard; | ||||
| use App\Utilities\Widgets; | ||||
| use Tests\Feature\FeatureTestCase; | ||||
|  | ||||
| class DashboardsTest extends FeatureTestCase | ||||
| { | ||||
| @@ -94,13 +95,12 @@ class DashboardsTest extends FeatureTestCase | ||||
|  | ||||
|     public function testItShouldSeeWidgetCreate() | ||||
|     { | ||||
|         $classes = Widget::factory()->classes; | ||||
|         $class = $classes[rand(0, 9)]; | ||||
|         $class = Widgets::$core_widgets[array_rand(Widgets::$core_widgets)]; | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->get(route('widgets.index')) | ||||
|             ->assertOk() | ||||
|             ->assertSeeText((new $class())->getDefaultName()); | ||||
|             ->assertSeeText((new $class())->getDefaultName(), false); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldSeeWidgetEdit() | ||||
|   | ||||
| @@ -1,67 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Tests\Feature\Common; | ||||
|  | ||||
| use App\Jobs\Auth\NotifyUser; | ||||
| use App\Notifications\Common\ImportCompleted; | ||||
| use Cache; | ||||
| use Date; | ||||
| use Illuminate\Support\Str; | ||||
| use Tests\Feature\FeatureTestCase; | ||||
|  | ||||
| class NotificationsTest extends FeatureTestCase | ||||
| { | ||||
|     public function testItShouldSeeNotificationListPage() | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('notifications.index')) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSeeText(trans_choice('general.items', 2)); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldSeeReadAllAction() | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('notifications.read-all')) | ||||
|             ->assertStatus(302); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldSeeDisableAction() | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->post(route('notifications.disable'), ['path' => 'double-entry', 'id' => 1]) | ||||
|             ->assertOk() | ||||
|             ->assertSeeText(trans('messages.success.disabled', [ | ||||
|                 'type' => Str::lower(trans_choice('general.notifications', 2)) | ||||
|             ])); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldSeeNewApps() | ||||
|     { | ||||
|         $notificatinos = $this->getNewApps(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->get(route('notifications.index')) | ||||
|             ->assertOk() | ||||
|             ->assertSeeText('Double-Entry'); | ||||
|     } | ||||
|  | ||||
|     protected function getNewApps() | ||||
|     { | ||||
|         $new_apps[] = (object) [ | ||||
|             "name" => "Double-Entry", | ||||
|             "alias" => "double-entry", | ||||
|             "message" => "<a href=\"https:\/\/akaunting.com\/apps\/double-entry?utm_source=Notifications&utm_medium=App&utm_campaign=Double-Entry\" target=\"_blank\">Double-Entry<\/a> app is published. You can check it out!", | ||||
|             "path" =>"new-apps", | ||||
|             "started_at" => "2021-06-26 00:00:00", | ||||
|             "ended_at" => "2021-07-11 00:00:00", | ||||
|             "status" => 2, | ||||
|         ]; | ||||
|  | ||||
|         $key = 'apps.notifications'; | ||||
|  | ||||
|         Cache::put($key, ['new-apps' => $new_apps], Date::now()->addHour(6)); | ||||
|     } | ||||
| } | ||||
| @@ -2,10 +2,8 @@ | ||||
|  | ||||
| namespace Tests\Feature; | ||||
|  | ||||
| use App\Models\Auth\User; | ||||
| use App\Models\Common\Contact; | ||||
| use App\Models\Document\Document; | ||||
| use App\Jobs\Common\CreateContact; | ||||
| use App\Jobs\Document\CreateDocument; | ||||
| use App\Jobs\Setting\CreateCurrency; | ||||
| use Illuminate\Support\Facades\File; | ||||
| @@ -52,7 +50,7 @@ class PaymentTestCase extends FeatureTestCase | ||||
|  | ||||
|         $this->updateSetting(); | ||||
|  | ||||
|         $this->createCustomer(); | ||||
|         $this->loginAsCustomer(); | ||||
|  | ||||
|         $this->createInvoice(); | ||||
|  | ||||
| @@ -140,20 +138,11 @@ class PaymentTestCase extends FeatureTestCase | ||||
|         $this->invoice = $this->dispatch(new CreateDocument($this->getInvoiceRequest())); | ||||
|     } | ||||
|  | ||||
|     public function createCustomer() | ||||
|     public function loginAsCustomer() | ||||
|     { | ||||
|         $password = $this->faker->password; | ||||
|         $this->customer = Contact::customer()->first(); | ||||
|  | ||||
|         $request = Contact::factory()->customer()->enabled()->raw() + [ | ||||
|             'create_user' => 'true', | ||||
|             'locale' => 'en-GB', | ||||
|             'password' => $password, | ||||
|             'password_confirmation' => $password, | ||||
|         ]; | ||||
|  | ||||
|         $this->customer = $this->dispatch(new CreateContact($request)); | ||||
|  | ||||
|         $this->customer_user = User::where('email', $request['email'])->first(); | ||||
|         $this->customer_user = $this->customer->user; | ||||
|     } | ||||
|  | ||||
|     public function getInvoiceRequest() | ||||
|   | ||||
| @@ -83,10 +83,12 @@ class BillsTest extends FeatureTestCase | ||||
|         $this->assertDatabaseHas('documents', [ | ||||
|             'document_number' => $request['document_number'] | ||||
|         ]); | ||||
|  | ||||
|         $this->assertDatabaseHas('mediables', [ | ||||
|             'mediable_type' => Document::class, | ||||
|             'tag'           => 'attachment', | ||||
|         ]); | ||||
|  | ||||
|         $this->assertDatabaseHas('media', [ | ||||
|             'disk'           => 'uploads', | ||||
|             'directory'      => '2021/05/15/1/bills', | ||||
| @@ -102,12 +104,13 @@ class BillsTest extends FeatureTestCase | ||||
|         $request = $this->getRequest(true); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post(route('bills.store'), $request) | ||||
|             ->post(route('recurring-bills.store'), $request) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseHas('documents', [ | ||||
|             'type' => Document::BILL_RECURRING_TYPE, | ||||
|             'document_number' => $request['document_number'], | ||||
|         ]); | ||||
|     } | ||||
|   | ||||
| @@ -1,172 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Tests\Feature\Purchases; | ||||
|  | ||||
| use App\Exports\Purchases\Payments as Export; | ||||
| use App\Jobs\Banking\CreateTransaction; | ||||
| use App\Models\Banking\Transaction; | ||||
| use Illuminate\Http\UploadedFile; | ||||
| use Illuminate\Support\Facades\File; | ||||
| use Tests\Feature\FeatureTestCase; | ||||
|  | ||||
| class PaymentsTest extends FeatureTestCase | ||||
| { | ||||
|     public function testItShouldSeePaymentListPage() | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('payments.index')) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSeeText(trans_choice('general.payments', 2)); | ||||
|     } | ||||
|     public function testItShouldSeePaymentShowPage() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $payment = $this->dispatch(new CreateTransaction($request)); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->get(route('payments.show', $payment->id)) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSee($payment->contact->email); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldSeePaymentCreatePage() | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('payments.create')) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.payments', 1)])); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldCreatePayment() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post(route('payments.store'), $request) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseHas('transactions', $request); | ||||
|     } | ||||
|  | ||||
| 	public function testItShouldSeePaymentUpdatePage() | ||||
| 	{ | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $payment = $this->dispatch(new CreateTransaction($request)); | ||||
|  | ||||
| 		$this->loginAs() | ||||
| 			->get(route('payments.edit', $payment->id)) | ||||
| 			->assertStatus(200) | ||||
| 			->assertSee($payment->amount); | ||||
| 	} | ||||
|  | ||||
|     public function testItShouldUpdatePayment() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $payment = $this->dispatch(new CreateTransaction($request)); | ||||
|  | ||||
|         $request['amount'] = $this->faker->randomFloat(2, 1, 1000); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->patch(route('payments.update', $payment->id), $request) | ||||
|             ->assertStatus(200) | ||||
| 			->assertSee($request['amount']); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseHas('transactions', $request); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldDeletePayment() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $payment = $this->dispatch(new CreateTransaction($request)); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->delete(route('payments.destroy', $payment->id)) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertSoftDeleted('transactions', $request); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldExportPayments() | ||||
|     { | ||||
|         $count = 5; | ||||
|         Transaction::factory()->expense()->count($count)->create(); | ||||
|  | ||||
|         \Excel::fake(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->get(route('payments.export')) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         \Excel::matchByRegex(); | ||||
|  | ||||
|         \Excel::assertDownloaded( | ||||
|             '/' . \Str::filename(trans_choice('general.payments', 2)) . '-\d{10}\.xlsx/', | ||||
|             function (Export $export) use ($count) { | ||||
|                 // Assert that the correct export is downloaded. | ||||
|                 return $export->collection()->count() === $count; | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldExportSelectedPayments() | ||||
|     { | ||||
|         $create_count = 5; | ||||
|         $select_count = 3; | ||||
|  | ||||
|         $payments = Transaction::factory()->expense()->count($create_count)->create(); | ||||
|  | ||||
|         \Excel::fake(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post( | ||||
|                 route('bulk-actions.action', ['group' => 'purchases', 'type' => 'payments']), | ||||
|                 ['handle' => 'export', 'selected' => $payments->take($select_count)->pluck('id')->toArray()] | ||||
|             ) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         \Excel::matchByRegex(); | ||||
|  | ||||
|         \Excel::assertDownloaded( | ||||
|             '/' . \Str::filename(trans_choice('general.payments', 2)) . '-\d{10}\.xlsx/', | ||||
|             function (Export $export) use ($select_count) { | ||||
|                 return $export->collection()->count() === $select_count; | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldImportPayments() | ||||
|     { | ||||
|         \Excel::fake(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post( | ||||
|                 route('payments.import'), | ||||
|                 [ | ||||
|                     'import' => UploadedFile::fake()->createWithContent( | ||||
|                         'payments.xlsx', | ||||
|                         File::get(public_path('files/import/payments.xlsx')) | ||||
|                     ), | ||||
|                 ] | ||||
|             ) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         \Excel::assertImported('payments.xlsx'); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|     } | ||||
|  | ||||
|     public function getRequest() | ||||
|     { | ||||
|         return Transaction::factory()->expense()->raw(); | ||||
|     } | ||||
| } | ||||
| @@ -84,7 +84,7 @@ class VendorsTest extends FeatureTestCase | ||||
|  | ||||
|         $vendor = $this->dispatch(new CreateContact($request)); | ||||
|  | ||||
|         $request['email'] = $this->faker->safeEmail; | ||||
|         $request['email'] = $this->faker->freeEmail; | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->patch(route('vendors.update', $vendor->id), $request) | ||||
|   | ||||
| @@ -99,7 +99,7 @@ class CustomersTest extends FeatureTestCase | ||||
|  | ||||
|         $customer = $this->dispatch(new CreateContact($request)); | ||||
|  | ||||
|         $request['email'] = $this->faker->safeEmail; | ||||
|         $request['email'] = $this->faker->freeEmail; | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->patch(route('customers.update', $customer->id), $request) | ||||
|   | ||||
| @@ -83,10 +83,12 @@ class InvoicesTest extends FeatureTestCase | ||||
|         $this->assertDatabaseHas('documents', [ | ||||
|             'document_number' => $request['document_number'] | ||||
|         ]); | ||||
|  | ||||
|         $this->assertDatabaseHas('mediables', [ | ||||
|             'mediable_type' => Document::class, | ||||
|             'tag'           => 'attachment', | ||||
|         ]); | ||||
|  | ||||
|         $this->assertDatabaseHas('media', [ | ||||
|             'disk'           => 'uploads', | ||||
|             'directory'      => '2021/05/15/1/invoices', | ||||
| @@ -113,12 +115,13 @@ class InvoicesTest extends FeatureTestCase | ||||
|         $request = $this->getRequest(true); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post(route('invoices.store'), $request) | ||||
|             ->post(route('recurring-invoices.store'), $request) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseHas('documents', [ | ||||
|             'type' => Document::INVOICE_RECURRING_TYPE, | ||||
|             'document_number' => $request['document_number'], | ||||
|         ]); | ||||
|     } | ||||
|   | ||||
| @@ -1,173 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Tests\Feature\Sales; | ||||
|  | ||||
| use App\Exports\Sales\Revenues as Export; | ||||
| use App\Jobs\Banking\CreateTransaction; | ||||
| use App\Models\Banking\Transaction; | ||||
| use Illuminate\Http\UploadedFile; | ||||
| use Illuminate\Support\Facades\File; | ||||
| use Tests\Feature\FeatureTestCase; | ||||
|  | ||||
| class RevenuesTest extends FeatureTestCase | ||||
| { | ||||
|     public function testItShouldSeeRevenueListPage() | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('revenues.index')) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSeeText(trans_choice('general.revenues', 2)); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldSeeRevenueShowPage() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $revenue = $this->dispatch(new CreateTransaction($request)); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->get(route('revenues.show', $revenue->id)) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSee($revenue->contact->email); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldSeeRevenueCreatePage() | ||||
|     { | ||||
|         $this->loginAs() | ||||
|             ->get(route('revenues.create')) | ||||
|             ->assertStatus(200) | ||||
|             ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.revenues', 1)])); | ||||
|     } | ||||
|  | ||||
|    public function testItShouldCreateRevenue() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post(route('revenues.store'), $request) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseHas('transactions', $request); | ||||
|     } | ||||
|  | ||||
| 	public function testItShouldSeeRevenueUpdatePage() | ||||
| 	{ | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $revenue = $this->dispatch(new CreateTransaction($request)); | ||||
|  | ||||
| 		$this->loginAs() | ||||
| 			->get(route('revenues.edit', $revenue->id)) | ||||
| 			->assertStatus(200) | ||||
| 			->assertSee($revenue->amount); | ||||
| 	} | ||||
|  | ||||
|     public function testItShouldUpdateRevenue() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $revenue = $this->dispatch(new CreateTransaction($request)); | ||||
|  | ||||
|         $request['amount'] = $this->faker->randomFloat(2, 1, 1000); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->patch(route('revenues.update', $revenue->id), $request) | ||||
|             ->assertStatus(200) | ||||
| 			->assertSee($request['amount']); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertDatabaseHas('transactions', $request); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldDeleteRevenue() | ||||
|     { | ||||
|         $request = $this->getRequest(); | ||||
|  | ||||
|         $revenue = $this->dispatch(new CreateTransaction($request)); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->delete(route('revenues.destroy', $revenue->id)) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|  | ||||
|         $this->assertSoftDeleted('transactions', $request); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldExportRevenues() | ||||
|     { | ||||
|         $count = 5; | ||||
|         Transaction::factory()->income()->count($count)->create(); | ||||
|  | ||||
|         \Excel::fake(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->get(route('revenues.export')) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         \Excel::matchByRegex(); | ||||
|  | ||||
|         \Excel::assertDownloaded( | ||||
|             '/' . \Str::filename(trans_choice('general.revenues', 2)) . '-\d{10}\.xlsx/', | ||||
|             function (Export $export) use ($count) { | ||||
|                 // Assert that the correct export is downloaded. | ||||
|                 return $export->collection()->count() === $count; | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldExportSelectedRevenues() | ||||
|     { | ||||
|         $create_count = 5; | ||||
|         $select_count = 3; | ||||
|  | ||||
|         $revenues = Transaction::factory()->income()->count($create_count)->create(); | ||||
|  | ||||
|         \Excel::fake(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post( | ||||
|                 route('bulk-actions.action', ['group' => 'sales', 'type' => 'revenues']), | ||||
|                 ['handle' => 'export', 'selected' => $revenues->take($select_count)->pluck('id')->toArray()] | ||||
|             ) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         \Excel::matchByRegex(); | ||||
|  | ||||
|         \Excel::assertDownloaded( | ||||
|             '/' . \Str::filename(trans_choice('general.revenues', 2)) . '-\d{10}\.xlsx/', | ||||
|             function (Export $export) use ($select_count) { | ||||
|                 return $export->collection()->count() === $select_count; | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     public function testItShouldImportRevenues() | ||||
|     { | ||||
|         \Excel::fake(); | ||||
|  | ||||
|         $this->loginAs() | ||||
|             ->post( | ||||
|                 route('revenues.import'), | ||||
|                 [ | ||||
|                     'import' => UploadedFile::fake()->createWithContent( | ||||
|                         'revenues.xlsx', | ||||
|                         File::get(public_path('files/import/revenues.xlsx')) | ||||
|                     ), | ||||
|                 ] | ||||
|             ) | ||||
|             ->assertStatus(200); | ||||
|  | ||||
|         \Excel::assertImported('revenues.xlsx'); | ||||
|  | ||||
|         $this->assertFlashLevel('success'); | ||||
|     } | ||||
|  | ||||
|     public function getRequest() | ||||
|     { | ||||
|         return Transaction::factory()->income()->raw(); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user