feat: implement tenant management system with attachment support and bootstrap controller
This commit is contained in:
@@ -15,6 +15,24 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
|
||||
public function test_it_bootstraps_a_tenant_by_domain(): void
|
||||
{
|
||||
$hdrKey = (string) Str::uuid();
|
||||
$ftrKey = (string) Str::uuid();
|
||||
|
||||
$headerAttachment = \App\Domains\Attachable\Models\Attachment::create([
|
||||
'key' => $hdrKey,
|
||||
'path' => 'tenants/' . $hdrKey . '.png',
|
||||
'filename' => 'logo_header.png',
|
||||
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
$footerAttachment = \App\Domains\Attachable\Models\Attachment::create([
|
||||
'key' => $ftrKey,
|
||||
'path' => 'tenants/' . $ftrKey . '.png',
|
||||
'filename' => 'logo_footer.png',
|
||||
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
|
||||
$tenant = Tenant::create([
|
||||
'codigo' => 'acme',
|
||||
'nombre' => 'Acme',
|
||||
@@ -23,8 +41,8 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
'secondary_color' => '#00ff00',
|
||||
'danger_color' => '#0000ff',
|
||||
'header_footer_bg_color' => '#ffffff',
|
||||
'header_logo' => 'logo_header.png',
|
||||
'footer_logo' => 'logo_footer.png',
|
||||
'header_logo_id' => $headerAttachment->id,
|
||||
'footer_logo_id' => $footerAttachment->id,
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/tenants/bootstrap/acme.com');
|
||||
@@ -36,9 +54,19 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
->assertJsonPath('data.primary_color', '#ff0000')
|
||||
->assertJsonPath('data.secondary_color', '#00ff00')
|
||||
->assertJsonPath('data.danger_color', '#0000ff')
|
||||
->assertJsonPath('data.header_footer_bg_color', '#ffffff')
|
||||
->assertJsonPath('data.header_logo', 'logo_header.png')
|
||||
->assertJsonPath('data.footer_logo', 'logo_footer.png');
|
||||
->assertJsonPath('data.header_footer_bg_color', '#ffffff');
|
||||
|
||||
$headerUrl = $response->json('data.header_logo');
|
||||
$footerUrl = $response->json('data.footer_logo');
|
||||
|
||||
$this->assertStringContainsString($headerAttachment->key, $headerUrl);
|
||||
$this->assertStringContainsString($footerAttachment->key, $footerUrl);
|
||||
$this->assertTrue(
|
||||
str_contains($headerUrl, 'Expires=') || str_contains($headerUrl, 'expiration=') || str_contains($headerUrl, 'X-Amz-Expires=')
|
||||
);
|
||||
$this->assertTrue(
|
||||
str_contains($footerUrl, 'Expires=') || str_contains($footerUrl, 'expiration=') || str_contains($footerUrl, 'X-Amz-Expires=')
|
||||
);
|
||||
|
||||
$this->assertArrayNotHasKey('props', $response->json('data'));
|
||||
}
|
||||
@@ -92,11 +120,10 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
->assertJsonPath('data.danger_color', '#333333')
|
||||
->assertJsonPath('data.header_footer_bg_color', '#444444');
|
||||
|
||||
$headerUuid = $firstResponse->json('data.header_logo');
|
||||
$footerUuid = $firstResponse->json('data.footer_logo');
|
||||
$tenant = Tenant::query()->with(['headerLogo', 'footerLogo'])->where('codigo', 'acme')->firstOrFail();
|
||||
|
||||
$this->assertTrue(Str::isUuid($headerUuid));
|
||||
$this->assertTrue(Str::isUuid($footerUuid));
|
||||
$this->assertNotNull($tenant->header_logo_id);
|
||||
$this->assertNotNull($tenant->footer_logo_id);
|
||||
|
||||
$this->assertDatabaseHas('tenants', [
|
||||
'codigo' => 'acme',
|
||||
@@ -104,10 +131,22 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
'secondary_color' => '#222222',
|
||||
'danger_color' => '#333333',
|
||||
'header_footer_bg_color' => '#444444',
|
||||
'header_logo' => $headerUuid,
|
||||
'footer_logo' => $footerUuid,
|
||||
'header_logo_id' => $tenant->header_logo_id,
|
||||
'footer_logo_id' => $tenant->footer_logo_id,
|
||||
]);
|
||||
|
||||
$headerUrl = $firstResponse->json('data.header_logo');
|
||||
$footerUrl = $firstResponse->json('data.footer_logo');
|
||||
|
||||
$this->assertStringContainsString($tenant->headerLogo->key, $headerUrl);
|
||||
$this->assertStringContainsString($tenant->footerLogo->key, $footerUrl);
|
||||
$this->assertTrue(
|
||||
str_contains($headerUrl, 'Expires=') || str_contains($headerUrl, 'expiration=') || str_contains($headerUrl, 'X-Amz-Expires=')
|
||||
);
|
||||
$this->assertTrue(
|
||||
str_contains($footerUrl, 'Expires=') || str_contains($footerUrl, 'expiration=') || str_contains($footerUrl, 'X-Amz-Expires=')
|
||||
);
|
||||
|
||||
$secondResponse = $this->postJson('/api/tenants', [
|
||||
'codigo' => 'globex',
|
||||
'nombre' => 'Globex',
|
||||
@@ -136,6 +175,21 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
$hdrUuid = (string) Str::uuid();
|
||||
$ftrUuid = (string) Str::uuid();
|
||||
|
||||
$hdrAttachment = \App\Domains\Attachable\Models\Attachment::create([
|
||||
'key' => $hdrUuid,
|
||||
'path' => 'tenants/' . $hdrUuid . '.png',
|
||||
'filename' => 'hdr.png',
|
||||
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
$ftrAttachment = \App\Domains\Attachable\Models\Attachment::create([
|
||||
'key' => $ftrUuid,
|
||||
'path' => 'tenants/' . $ftrUuid . '.png',
|
||||
'filename' => 'ftr.png',
|
||||
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
|
||||
$successfulResponse = $this->putJson("/api/tenants/{$tenant->id}", [
|
||||
'codigo' => 'acme',
|
||||
'nombre' => 'Acme Updated',
|
||||
@@ -155,9 +209,19 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
->assertJsonPath('data.primary_color', '#555555')
|
||||
->assertJsonPath('data.secondary_color', '#666666')
|
||||
->assertJsonPath('data.danger_color', '#777777')
|
||||
->assertJsonPath('data.header_footer_bg_color', '#888888')
|
||||
->assertJsonPath('data.header_logo', $hdrUuid)
|
||||
->assertJsonPath('data.footer_logo', $ftrUuid);
|
||||
->assertJsonPath('data.header_footer_bg_color', '#888888');
|
||||
|
||||
$headerUrl = $successfulResponse->json('data.header_logo');
|
||||
$footerUrl = $successfulResponse->json('data.footer_logo');
|
||||
|
||||
$this->assertStringContainsString($hdrUuid, $headerUrl);
|
||||
$this->assertStringContainsString($ftrUuid, $footerUrl);
|
||||
$this->assertTrue(
|
||||
str_contains($headerUrl, 'Expires=') || str_contains($headerUrl, 'expiration=') || str_contains($headerUrl, 'X-Amz-Expires=')
|
||||
);
|
||||
$this->assertTrue(
|
||||
str_contains($footerUrl, 'Expires=') || str_contains($footerUrl, 'expiration=') || str_contains($footerUrl, 'X-Amz-Expires=')
|
||||
);
|
||||
|
||||
$this->assertDatabaseHas('tenants', [
|
||||
'id' => $tenant->id,
|
||||
@@ -165,8 +229,8 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
'secondary_color' => '#666666',
|
||||
'danger_color' => '#777777',
|
||||
'header_footer_bg_color' => '#888888',
|
||||
'header_logo' => $hdrUuid,
|
||||
'footer_logo' => $ftrUuid,
|
||||
'header_logo_id' => $hdrAttachment->id,
|
||||
'footer_logo_id' => $ftrAttachment->id,
|
||||
]);
|
||||
|
||||
$failingResponse = $this->putJson("/api/tenants/{$otherTenant->id}", [
|
||||
@@ -236,14 +300,25 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
|
||||
$response->assertCreated();
|
||||
|
||||
$headerUuid = $response->json('data.header_logo');
|
||||
$footerUuid = $response->json('data.footer_logo');
|
||||
$tenant = Tenant::query()->with(['headerLogo', 'footerLogo'])->where('codigo', 'acme')->firstOrFail();
|
||||
|
||||
$this->assertTrue(Str::isUuid($headerUuid));
|
||||
$this->assertTrue(Str::isUuid($footerUuid));
|
||||
$this->assertNotNull($tenant->header_logo_id);
|
||||
$this->assertNotNull($tenant->footer_logo_id);
|
||||
|
||||
$this->assertDatabaseHas('attachments', ['key' => $headerUuid]);
|
||||
$this->assertDatabaseHas('attachments', ['key' => $footerUuid]);
|
||||
$headerUrl = $response->json('data.header_logo');
|
||||
$footerUrl = $response->json('data.footer_logo');
|
||||
|
||||
$this->assertStringContainsString($tenant->headerLogo->key, $headerUrl);
|
||||
$this->assertStringContainsString($tenant->footerLogo->key, $footerUrl);
|
||||
$this->assertTrue(
|
||||
str_contains($headerUrl, 'Expires=') || str_contains($headerUrl, 'expiration=') || str_contains($headerUrl, 'X-Amz-Expires=')
|
||||
);
|
||||
$this->assertTrue(
|
||||
str_contains($footerUrl, 'Expires=') || str_contains($footerUrl, 'expiration=') || str_contains($footerUrl, 'X-Amz-Expires=')
|
||||
);
|
||||
|
||||
$this->assertDatabaseHas('attachments', ['key' => $tenant->headerLogo->key]);
|
||||
$this->assertDatabaseHas('attachments', ['key' => $tenant->footerLogo->key]);
|
||||
}
|
||||
|
||||
public function test_it_stores_base64_logos_in_tenants_directory(): void
|
||||
@@ -260,8 +335,17 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
|
||||
$response->assertCreated();
|
||||
|
||||
$headerUuid = $response->json('data.header_logo');
|
||||
$this->assertTrue(Str::isUuid($headerUuid));
|
||||
$this->assertDatabaseHas('attachments', ['key' => $headerUuid]);
|
||||
$tenant = Tenant::query()->with('headerLogo')->where('codigo', 'acme')->firstOrFail();
|
||||
|
||||
$this->assertNotNull($tenant->header_logo_id);
|
||||
|
||||
$headerUrl = $response->json('data.header_logo');
|
||||
|
||||
$this->assertStringContainsString($tenant->headerLogo->key, $headerUrl);
|
||||
$this->assertTrue(
|
||||
str_contains($headerUrl, 'Expires=') || str_contains($headerUrl, 'expiration=') || str_contains($headerUrl, 'X-Amz-Expires=')
|
||||
);
|
||||
|
||||
$this->assertDatabaseHas('attachments', ['key' => $tenant->headerLogo->key]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user