(string) Str::uuid(), 'trans' => 'MANTEST' . Str::random(6), 'amount' => $amount, 'customer_id' => $customer->id, 'type' => 'manual', 'status' => $status->value, 'proof_image' => $proof, ]); } public function test_draft_without_proof_can_be_rejected_and_approved_without_touching_pending(): void { Mail::fake(); $customer = Customer::factory()->create(['total' => 0, 'total_pending' => 300_000]); $controller = app(AdminTransactionController::class); $rejected = $this->deposit($customer, 5_000_000, null); $this->assertSame(200, $controller->reject($rejected->uuid)->getStatusCode()); $this->assertSame(TransactionStatus::FAILED->value, (int) $rejected->fresh()->status); $approved = $this->deposit($customer, 1_000_000, null); $this->assertSame(200, $controller->approve(new Request(), $approved->uuid)->getStatusCode()); $customer->refresh(); $this->assertSame(300_000, (int) $customer->total_pending); $this->assertSame(1_000_000, (int) $customer->total); } public function test_signed_proof_image_url_serves_the_file(): void { Storage::fake('local'); $customer = Customer::factory()->create(); $path = UploadedFile::fake()->image('proof.png')->store('deposit-proofs/' . $customer->id, 'local'); $transaction = $this->deposit($customer, 300_000, $path); $this->get($transaction->proof_image_urls[0])->assertOk(); $this->get(strtok($transaction->proof_image_urls[0], '?'))->assertForbidden(); } public function test_deleting_submitted_pending_deposit_releases_pending_amount(): void { $customer = Customer::factory()->create(['total' => 0, 'total_pending' => 300_000]); $transaction = $this->deposit($customer, 300_000, 'deposit-proofs/a.jpg'); $response = app(AdminTransactionController::class)->destroy($transaction->uuid); $this->assertSame(200, $response->getStatusCode()); $this->assertSoftDeleted($transaction); $this->assertSame(0, (int) $customer->fresh()->total_pending); } public function test_deleting_draft_or_completed_deposit_keeps_balances(): void { $customer = Customer::factory()->create(['total' => 2_000_000, 'total_pending' => 300_000]); $controller = app(AdminTransactionController::class); $draft = $this->deposit($customer, 500_000, null); $completed = $this->deposit($customer, 2_000_000, 'deposit-proofs/b.jpg', TransactionStatus::COMPLETED); $this->assertSame(200, $controller->destroy($draft->uuid)->getStatusCode()); $this->assertSame(200, $controller->destroy($completed->uuid)->getStatusCode()); $this->assertSame(404, $controller->destroy($completed->uuid)->getStatusCode()); $customer->refresh(); $this->assertSame(300_000, (int) $customer->total_pending); $this->assertSame(2_000_000, (int) $customer->total); } }