Repair: copy legacy joinDate into new user's created_at when creating users from legacy wallz

This commit is contained in:
2026-03-22 09:13:39 +01:00
parent e8b5edf5d2
commit 2608be7420
80 changed files with 3991 additions and 723 deletions

View File

@@ -12,8 +12,10 @@ use App\Policies\ConversationPolicy;
use App\Events\ConversationUpdated;
use App\Events\MessageCreated;
use App\Events\MessageRead;
use App\Services\Messaging\MessagingPresenceService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Storage;
@@ -259,6 +261,133 @@ test('typing endpoints reject non participants', function () {
->assertStatus(403);
});
test('conversation list includes unread summary total', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();
$conv = makeDirectConversation($userA, $userB);
Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userB->id,
'body' => 'Unread one',
]);
Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userB->id,
'body' => 'Unread two',
]);
$response = $this->actingAs($userA)->getJson('/api/messages/conversations');
$response->assertStatus(200)
->assertJsonPath('summary.unread_total', 2);
});
test('conversation updated broadcast includes unread summary total', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();
$conv = makeDirectConversation($userA, $userB);
Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userB->id,
'body' => 'Unread one',
]);
Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userB->id,
'body' => 'Unread two',
]);
$payload = (new ConversationUpdated($userA->id, $conv->fresh(), 'message.created'))->broadcastWith();
expect($payload['reason'])->toBe('message.created')
->and((int) data_get($payload, 'conversation.id'))->toBe($conv->id)
->and((int) data_get($payload, 'conversation.unread_count'))->toBe(2)
->and((int) data_get($payload, 'summary.unread_total'))->toBe(2);
});
test('delta endpoint returns only messages after requested id in ascending order', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();
$conv = makeDirectConversation($userA, $userB);
$first = Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userB->id,
'body' => 'First',
]);
$second = Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userB->id,
'body' => 'Second',
]);
$third = Message::create([
'conversation_id' => $conv->id,
'sender_id' => $userA->id,
'body' => 'Third',
]);
$response = $this->actingAs($userA)->getJson("/api/messages/{$conv->id}/delta?after_message_id={$first->id}");
$response->assertStatus(200)
->assertJsonPath('data.0.id', $second->id)
->assertJsonPath('data.1.id', $third->id);
});
test('presence heartbeat marks user online and viewing a conversation', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();
$conv = makeDirectConversation($userA, $userB);
$this->actingAs($userA)
->postJson('/api/messages/presence/heartbeat', ['conversation_id' => $conv->id])
->assertStatus(200)
->assertJsonFragment(['conversation_id' => $conv->id]);
$presence = app(MessagingPresenceService::class);
expect($presence->isUserOnline($userA->id))->toBeTrue()
->and($presence->isViewingConversation($conv->id, $userA->id))->toBeTrue();
});
test('offline fallback notifications are skipped for online recipients', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();
$conv = makeDirectConversation($userA, $userB);
app(MessagingPresenceService::class)->touch($userB);
$this->actingAs($userA)->postJson("/api/messages/{$conv->id}", [
'body' => 'Presence-aware hello',
])->assertStatus(201);
expect(DB::table('notifications')->count())->toBe(0);
});
test('offline fallback notifications are stored for offline recipients', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();
$conv = makeDirectConversation($userA, $userB);
$this->actingAs($userA)->postJson("/api/messages/{$conv->id}", [
'body' => 'Offline hello',
])->assertStatus(201);
$notification = DB::table('notifications')->first();
expect($notification)->not->toBeNull()
->and((int) $notification->user_id)->toBe($userB->id)
->and((string) $notification->type)->toBe('message');
});
test('report endpoint creates moderation report entry', function () {
$userA = makeMessagingUser();
$userB = makeMessagingUser();

View File

@@ -0,0 +1,122 @@
<?php
declare(strict_types=1);
use App\Models\Artwork;
use App\Models\Category;
use App\Models\ContentType;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use function Pest\Laravel\artisan;
uses(RefreshDatabase::class);
beforeEach(function (): void {
config()->set('vision.vector_gateway.enabled', true);
config()->set('vision.vector_gateway.base_url', 'https://vision.klevze.net');
config()->set('vision.vector_gateway.api_key', 'test-key');
config()->set('vision.vector_gateway.upsert_endpoint', '/vectors/upsert');
config()->set('vision.vector_gateway.search_endpoint', '/vectors/search');
config()->set('vision.image_variant', 'md');
config()->set('cdn.files_url', 'https://files.skinbase.org');
});
it('indexes artworks into the vector gateway with artwork metadata', function (): void {
$contentType = ContentType::query()->create([
'name' => 'Photography',
'slug' => 'photography',
'description' => '',
]);
$category = Category::query()->create([
'content_type_id' => $contentType->id,
'parent_id' => null,
'name' => 'Abstract',
'slug' => 'abstract',
'description' => '',
'is_active' => true,
'sort_order' => 0,
]);
$artwork = Artwork::factory()->create([
'hash' => 'aabbcc112233',
'thumb_ext' => 'webp',
]);
$artwork->categories()->attach($category->id);
Http::fake([
'https://vision.klevze.net/vectors/upsert' => Http::response(['ok' => true], 200),
]);
artisan('artworks:vectors-index', ['--limit' => 1])
->assertSuccessful();
Http::assertSent(function ($request) use ($artwork): bool {
if ($request->url() !== 'https://vision.klevze.net/vectors/upsert') {
return false;
}
$payload = json_decode($request->body(), true);
return $request->hasHeader('X-API-Key', 'test-key')
&& is_array($payload)
&& ($payload['id'] ?? null) === (string) $artwork->id
&& ($payload['url'] ?? null) === 'https://files.skinbase.org/md/aa/bb/aabbcc112233.webp'
&& ($payload['metadata']['content_type'] ?? null) === 'Photography'
&& ($payload['metadata']['category'] ?? null) === 'Abstract';
});
});
it('searches similar artworks through the vector gateway', function (): void {
$contentType = ContentType::query()->create([
'name' => 'Wallpapers',
'slug' => 'wallpapers',
'description' => '',
]);
$category = Category::query()->create([
'content_type_id' => $contentType->id,
'parent_id' => null,
'name' => 'Nature',
'slug' => 'nature',
'description' => '',
'is_active' => true,
'sort_order' => 0,
]);
$source = Artwork::factory()->create([
'title' => 'Source artwork',
'hash' => 'aabbcc112233',
'thumb_ext' => 'webp',
]);
$source->categories()->attach($category->id);
$similar = Artwork::factory()->create([
'title' => 'Nearby artwork',
'hash' => 'ddeeff445566',
'thumb_ext' => 'webp',
]);
$similar->categories()->attach($category->id);
Http::fake([
'https://vision.klevze.net/vectors/search' => Http::response([
'results' => [
['id' => $source->id, 'score' => 1.0],
['id' => $similar->id, 'score' => 0.9876],
],
], 200),
]);
artisan('artworks:vectors-search', [
'artwork_id' => $source->id,
'--limit' => 5,
])
->expectsTable(['ID', 'Score', 'Title', 'Content Type', 'Category'], [[
'id' => $similar->id,
'score' => '0.9876',
'title' => 'Nearby artwork',
'content_type' => 'Wallpapers',
'category' => 'Nature',
]])
->assertSuccessful();
});