'Full Administrator', 'guard_name' => 'admin']); $admin = User::factory()->create(); $admin->assignRole('Full Administrator'); $customer = Customer::factory()->create(['total' => 500000]); $url = "/api/v1/administrator/customers/{$customer->uuid}/transactions"; $created = $this->actingAs($admin, 'admin') ->postJson($url, ['trans' => 'CK VCB 123', 'amount' => 800000, 'note' => 'Thu tiền mặt']) ->assertCreated() ->json('data'); $this->assertMatchesRegularExpression('/^ADM-\d{8}-[A-Z0-9]{6}$/', $created['public_code']); $this->assertSame('neutral', $created['direction']); $this->assertSame(500000, (int) $customer->fresh()->total); $this->actingAs($admin, 'admin')->getJson($url)->assertJsonCount(1, 'data'); $this->actingAs($admin, 'admin')->deleteJson("{$url}/{$created['id']}")->assertOk(); $this->assertSoftDeleted('transactions', ['id' => $created['id']]); } public function test_transaction_created_without_code_gets_one(): void { $customer = Customer::factory()->create(); $transaction = Transaction::create(['amount' => 1, 'customer_id' => $customer->id, 'type' => 'transfer', 'status' => 1]); $this->assertMatchesRegularExpression('/^TXN-\d{8}-[A-Z0-9]{6}$/', $transaction->public_code); } public function test_cannot_delete_another_customers_transaction(): void { Role::firstOrCreate(['name' => 'Full Administrator', 'guard_name' => 'admin']); $admin = User::factory()->create(); $admin->assignRole('Full Administrator'); $owner = Customer::factory()->create(); $other = Customer::factory()->create(); $transaction = Transaction::create(['amount' => 1, 'customer_id' => $owner->id, 'type' => 'transfer', 'status' => 1]); $this->actingAs($admin, 'admin') ->deleteJson("/api/v1/administrator/customers/{$other->uuid}/transactions/{$transaction->id}") ->assertNotFound(); $this->assertNotSoftDeleted('transactions', ['id' => $transaction->id]); } }