feat(portal): lead module, WHMCS sync report/contacts/mapping, service lifecycle email templates
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
3c7710f1de
commit
a443ec3bf6
@@ -65,7 +65,7 @@ class IpAllocationTest extends TestCase
|
||||
$response = $this->actingAs($this->admin, 'admin')
|
||||
->postJson(self::BASE . '/allocation/preview', $this->allocation([$pool->id]))
|
||||
->assertOk()
|
||||
->assertJsonPath('data.subject', 'Thông báo cấp phát 1 địa chỉ IP');
|
||||
->assertJsonPath('data.subject', 'V/v: Thế Giới Số cấp phát 1 địa chỉ IP | Công ty A');
|
||||
|
||||
$this->assertStringContainsString('10.0.0.5', $response->json('data.html'));
|
||||
$this->assertStringContainsString('Colo <b>1U</b>', $response->json('data.html'));
|
||||
@@ -122,7 +122,7 @@ class IpAllocationTest extends TestCase
|
||||
->postJson(self::BASE . '/allocate', $payload)
|
||||
->assertOk();
|
||||
|
||||
Mail::assertQueued(IpAllocationMail::class, fn (IpAllocationMail $mail) => $mail->envelope()->subject === 'Thông báo cấp phát 2 địa chỉ IP');
|
||||
Mail::assertQueued(IpAllocationMail::class, fn (IpAllocationMail $mail) => $mail->envelope()->subject === 'V/v: Thế Giới Số cấp phát 2 địa chỉ IP | Công ty A');
|
||||
$this->assertSame('Dịch vụ IP', $first->fresh()->service_name);
|
||||
$this->assertSame('CLOUD VPS SILVER', $second->fresh()->service_name);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Api\Admin;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Modules\Lead\App\Models\Lead;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LeadApiTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private const BASE = '/api/v1/administrator/leads';
|
||||
|
||||
private function admin(array $permissions): User
|
||||
{
|
||||
$role = Role::create(['name' => 'role-' . uniqid(), 'guard_name' => 'admin']);
|
||||
foreach ($permissions as $name) {
|
||||
$role->givePermissionTo(Permission::firstOrCreate(['name' => $name, 'guard_name' => 'admin']));
|
||||
}
|
||||
$admin = User::factory()->create();
|
||||
$admin->assignRole($role);
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
public function test_crud_flow_and_email_is_normalized_and_unique(): void
|
||||
{
|
||||
$admin = $this->admin(['lead.view', 'lead.create', 'lead.edit', 'lead.destroy']);
|
||||
|
||||
$uuid = $this->actingAs($admin, 'admin')
|
||||
->postJson(self::BASE, ['fullname' => 'Khách A', 'email' => ' Khach.A@Example.com ', 'status' => 'new'])
|
||||
->assertCreated()
|
||||
->assertJsonPath('data.email', 'khach.a@example.com')
|
||||
->json('data.uuid');
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->postJson(self::BASE, ['email' => 'khach.a@example.com'])
|
||||
->assertStatus(422);
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->putJson(self::BASE . "/{$uuid}", ['email' => 'khach.a@example.com', 'status' => 'contacted', 'phone' => '0901234567'])
|
||||
->assertOk()
|
||||
->assertJsonPath('data.status', 'contacted');
|
||||
|
||||
$this->actingAs($admin, 'admin')->getJson(self::BASE . '?filter=0901')->assertOk()->assertJsonPath('data.total', 1);
|
||||
$this->actingAs($admin, 'admin')->getJson(self::BASE . "/{$uuid}")->assertOk()->assertJsonPath('data.phone', '0901234567');
|
||||
|
||||
$this->actingAs($admin, 'admin')->deleteJson(self::BASE . "/{$uuid}")->assertOk();
|
||||
$this->assertSame(0, Lead::count());
|
||||
}
|
||||
|
||||
public function test_permissions_are_enforced(): void
|
||||
{
|
||||
$viewer = $this->admin(['lead.view']);
|
||||
|
||||
$this->actingAs($viewer, 'admin')->getJson(self::BASE)->assertOk();
|
||||
$this->actingAs($viewer, 'admin')->postJson(self::BASE, ['email' => 'x@example.com'])->assertForbidden();
|
||||
$this->actingAs($viewer, 'admin')->deleteJson(self::BASE . '/' . uniqid())->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_bulk_status_and_bulk_delete_only_touch_given_uuids(): void
|
||||
{
|
||||
$admin = $this->admin(['lead.view', 'lead.edit', 'lead.destroy']);
|
||||
$leads = collect(['a', 'b', 'c'])->map(fn ($name) => Lead::create(['email' => "{$name}@example.com"]));
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->postJson(self::BASE . '/bulk-status', ['uuids' => [$leads[0]->uuid, $leads[1]->uuid], 'status' => 'contacted'])
|
||||
->assertOk()
|
||||
->assertJsonPath('data.affected', 2);
|
||||
$this->assertSame(2, Lead::where('status', 'contacted')->count());
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->postJson(self::BASE . '/bulk-status', ['uuids' => [$leads[2]->uuid], 'status' => 'bogus'])
|
||||
->assertStatus(422);
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->postJson(self::BASE . '/bulk-delete', ['uuids' => [$leads[0]->uuid, $leads[2]->uuid]])
|
||||
->assertOk()
|
||||
->assertJsonPath('data.affected', 2);
|
||||
$this->assertSame([$leads[1]->uuid], Lead::pluck('uuid')->all());
|
||||
|
||||
$this->actingAs($this->admin(['lead.view']), 'admin')
|
||||
->postJson(self::BASE . '/bulk-delete', ['uuids' => [$leads[1]->uuid]])
|
||||
->assertForbidden();
|
||||
}
|
||||
}
|
||||
@@ -86,4 +86,22 @@ class MarketingEmailOptOutTest extends TestCase
|
||||
|
||||
Queue::assertNotPushed(SendMailCampaignRecipient::class);
|
||||
}
|
||||
|
||||
public function test_campaign_with_template_uses_edited_message_when_given(): void
|
||||
{
|
||||
Queue::fake();
|
||||
$admin = $this->admin();
|
||||
$customer = Customer::factory()->create(['email_marketing' => 1]);
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->postJson('/api/v1/administrator/mail-campaigns', [
|
||||
'template_id' => $this->template(null)->id,
|
||||
'message' => '<p>Nội dung đã sửa</p>',
|
||||
'recipient_type' => 'selected',
|
||||
'uuids' => [$customer->uuid],
|
||||
])
|
||||
->assertOk();
|
||||
|
||||
$this->assertSame('<p>Nội dung đã sửa</p>', \App\Models\MailCampaign::latest('id')->first()->message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user