Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ jobs:
uses: saucebase-dev/core/.github/workflows/test-module.yml@main
with:
module: chat
# dependencies: saucebase/auth # add space-separated packages if needed
# Every module the template requires, in the order their patches apply.
dependencies: saucebase/auth saucebase/billing saucebase/themes
private_dependencies: saucebase/ai-chat
secrets:
APP_ID: ${{ secrets.APP_ID }}
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
29 changes: 29 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace Modules\Chat\Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
use Modules\Billing\Enums\BillingScheme;
use Modules\Billing\Enums\Currency;
use Modules\Billing\Enums\PlanKind;
use Modules\Billing\Models\Product;
use Saucebase\Core\Settings\GeneralSettings;

/**
* What every install needs, demo or not: the product's plans. Their limits
Expand All @@ -22,7 +24,34 @@ class DatabaseSeeder extends Seeder
'description' => 'For people who work with it every day.', 'features' => ['2,000 messages a month', '100 images a month', 'Web search', 'Answers about your account', 'Chat history', 'Every model your admin offers', 'Email support']],
];

/** The product's name, while the app still has the installer's default. */
public const string NAME = 'AI Chat';

public function run(): void
{
$this->name();
$this->plans();
}

/**
* The installer names an app after its folder ("chat-template" becomes "Chat Template")
* unless given --app-name. Only that default gives way to the product's name, so a name
* the customer chose is never replaced.
*
* ponytail: guesses the default from the folder; an installer hook that pre-fills the
* app name from the template would make this exact.
*/
private function name(): void
{
$settings = app(GeneralSettings::class);

if ($settings->site_name === Str::headline(basename(base_path()))) {
$settings->site_name = self::NAME;
$settings->save();
}
}

private function plans(): void
{
foreach (self::PLANS as $order => $plan) {
$limits = ['ai_chat_messages' => $plan['messages'], 'ai_chat_images' => $plan['images']];
Expand Down
1 change: 1 addition & 0 deletions resources/boost/skills/saucebase-chat-development/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Paths are relative to `modules/chat/` unless they say otherwise. Commands run fr

- The landing page quotes the plans (`stubs/resources/js/vue/components/landing/content.ts`): change the seeder and the copy together.
- The template adds no routes of its own: `/chat` belongs to ai-chat.
- `ChatServiceProvider` sets `ai-chat.sessions` to `sidebar`: the chat list is the app sidebar (no "Chat" item, no second panel). ai-chat's default (`page`) is for apps where the chat is one feature among others.

## Testing

Expand Down
8 changes: 8 additions & 0 deletions src/Providers/ChatServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ class ChatServiceProvider extends ModuleServiceProvider
protected array $providers = [
// YourServiceProvider::class,
];

public function boot(): void
{
parent::boot();

// A chat-first app: the chat list is the app sidebar (no "Chat" item, no second panel).
config(['ai-chat.sessions' => 'sidebar']);
}
}
15 changes: 0 additions & 15 deletions stubs/routes/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ function (Section $section) {
}
);

Navigation::add(
'Documentation',
'https://saucebase-dev.github.io/docs/',
function (Section $section) {
$section->attributes([
'group' => 'secondary',
'slug' => 'documentation',
'icon' => 'documentation',
'external' => true,
'newPage' => true,
'order' => 0,
]);
}
);

Navigation::addWhen(
fn () => Auth::user()?->can('access admin panel') ?? false,
'Admin',
Expand Down
14 changes: 14 additions & 0 deletions tests/Feature/ChatListTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Modules\Chat\Tests\Feature;

use Tests\TestCase;

class ChatListTest extends TestCase
{
public function test_the_chat_list_leads_the_app_sidebar(): void
{
// A chat-first app: the list is the sidebar, with no "Chat" item and no second panel.
$this->assertSame('sidebar', config('ai-chat.sessions'));
}
}
23 changes: 23 additions & 0 deletions tests/Feature/NavigationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Modules\Chat\Tests\Feature;

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class NavigationTest extends TestCase
{
use RefreshDatabase;

public function test_the_sidebar_links_to_github_but_not_the_docs(): void
{
$this->withoutVite();

$response = $this->actingAs(User::factory()->create())->get(route('ai-chat.index'));

$slugs = collect($response->viewData('page')['props']['navigation']['secondary'] ?? [])->pluck('slug');
$this->assertContains('github', $slugs);
$this->assertNotContains('documentation', $slugs);
}
}
45 changes: 45 additions & 0 deletions tests/Feature/SiteNameTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Modules\Chat\Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Modules\Chat\Database\Seeders\DatabaseSeeder;
use Saucebase\Core\Settings\GeneralSettings;
use Tests\TestCase;

class SiteNameTest extends TestCase
{
use RefreshDatabase;

protected function siteName(?string $name = null): string
{
$settings = app(GeneralSettings::class);

if ($name !== null) {
$settings->site_name = $name;
$settings->save();
}

return $settings->refresh()->site_name;
}

public function test_the_installers_folder_name_becomes_the_product_name(): void
{
// `saucebase new chat-template` names the app after its folder: "Chat Template".
$this->siteName(Str::headline(basename(base_path())));

$this->seed(DatabaseSeeder::class);

$this->assertSame('AI Chat', $this->siteName());
}

public function test_a_name_the_customer_chose_is_kept(): void
{
$this->siteName('Acme Assistant');

$this->seed(DatabaseSeeder::class);

$this->assertSame('Acme Assistant', $this->siteName());
}
}
20 changes: 20 additions & 0 deletions tests/e2e/chat.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect, test } from '@e2e/fixtures';

// What the template changes about ai-chat, not how it looks: adopters restyle it freely.
test.describe('Chat template', () => {
test('signing in lands on the chat, with the list in the app sidebar', async ({
page,
credentials,
loginAs,
}) => {
await loginAs(credentials.user);
await page.goto('/dashboard');

await expect(page).toHaveURL(/\/chat$/);
await expect(
page.locator('[data-sidebar="content"]').getByTestId('new-chat'),
).toBeVisible();
// ai-chat's own panel is for apps where the chat is one feature among others.
await expect(page.getByTestId('chat-panel')).toHaveCount(0);
});
});
Loading