users worden nu beter geresolved
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser;
|
||||
|
||||
use App\Models\Dynamic;
|
||||
use App\Models\Ledger;
|
||||
use App\Models\Mutation;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Laravel\Dusk\Browser;
|
||||
use Tests\DuskTestCase;
|
||||
|
||||
class NotificationTest extends DuskTestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->artisan('migrate:fresh', ['--seed' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic browser test example.
|
||||
*/
|
||||
public function test_it_shows_notifications_on_mutation_activity(): void
|
||||
{
|
||||
$owner = User::factory()->create();
|
||||
$participant = User::factory()->create();
|
||||
$dynamic = Dynamic::factory()->create();
|
||||
$dynamic->chat()->create();
|
||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
||||
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||
|
||||
$this->browse(function (Browser $ownerBrowser, Browser $participantBrowser) use ($owner, $participant, $dynamic, $ledger) {
|
||||
$ownerBrowser->loginAs($owner)
|
||||
->visit(route('dynamics.ledgers.show', [$dynamic, $ledger]))
|
||||
->waitForText($ledger->name)
|
||||
->assertSee($ledger->name)
|
||||
->script([
|
||||
"window.notifications = [];",
|
||||
"window.Notification = function(title, options) { window.notifications.push({title, options}); };",
|
||||
]);
|
||||
|
||||
$participantBrowser->loginAs($participant)
|
||||
->visit(route('dynamics.ledgers.show', [$dynamic, $ledger]))
|
||||
->waitForText('Add Mutation')
|
||||
->type('[data-test="description-input"]', 'A new task suggestion')
|
||||
->type('[data-test="amount-input"]', 10)
|
||||
->press('[data-test="add-mutation-button"]')
|
||||
->waitForText('A new task suggestion');
|
||||
|
||||
$ownerBrowser->pause(1000);
|
||||
$lastNotification = $ownerBrowser->script("return window.notifications.pop();")[0] ?? null;
|
||||
$this->assertNotNull($lastNotification, "Owner did not receive the 'new suggestion' notification.");
|
||||
$this->assertEquals('New Activity', $lastNotification['title']);
|
||||
$this->assertStringContainsString('suggested a new entry', $lastNotification['options']['body']);
|
||||
|
||||
$mutation = Mutation::where('description', 'A new task suggestion')->first();
|
||||
$ownerBrowser->press("#mutation-{$mutation->id}-approve")
|
||||
->waitForText('APPROVED');
|
||||
|
||||
$participantBrowser->script([
|
||||
"window.notifications = [];",
|
||||
"window.Notification = function(title, options) { window.notifications.push({title, options}); };",
|
||||
]);
|
||||
|
||||
$ownerBrowser->pause(1000);
|
||||
|
||||
$participantBrowser->pause(1000);
|
||||
$lastNotification = $participantBrowser->script("return window.notifications.pop();")[0] ?? null;
|
||||
$this->assertNotNull($lastNotification, "Participant did not receive the 'approved' notification.");
|
||||
$this->assertEquals('New Activity', $lastNotification['title']);
|
||||
$this->assertStringContainsString('APPROVED the suggestion', $lastNotification['options']['body']);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -99,5 +99,5 @@ test('only the user with the specified email address can accept the link', funct
|
||||
// Verify system notification is added to Dynamic activity chat
|
||||
$chatMessages = $dynamic->chat->messages;
|
||||
expect($chatMessages)->not->toBeEmpty();
|
||||
expect($chatMessages->last()->content)->toBe("<user:{$invitee->id}> joined the Dynamic as a EDITOR");
|
||||
expect($chatMessages->last()->content)->toBe("<user:{$invitee->uuid}> joined the Dynamic as a EDITOR");
|
||||
});
|
||||
|
||||
@@ -33,12 +33,12 @@ test('owner can create a mutation which is automatically approved and does not s
|
||||
$mutationChatMessages = $mutation->chat->messages;
|
||||
expect($mutationChatMessages)->toHaveCount(1);
|
||||
expect($mutationChatMessages->first()->user_id)->toBeNull();
|
||||
expect($mutationChatMessages->first()->content)->toBe("Entry was created by <user:{$owner->id}>.");
|
||||
expect($mutationChatMessages->first()->content)->toBe("Entry was created by <user:{$owner->uuid}>.");
|
||||
|
||||
$dynamicChatMessages = $dynamic->chat->messages;
|
||||
expect($dynamicChatMessages)->toHaveCount(1);
|
||||
expect($dynamicChatMessages->first()->user_id)->toBeNull();
|
||||
expect($dynamicChatMessages->first()->content)->toBe("<user:{$owner->id}> added entry \"Direct point reward\" for +15 points on \"{$ledger->name}\" ledger.");
|
||||
expect($dynamicChatMessages->first()->content)->toBe("<user:{$owner->uuid}> added entry \"Direct point reward\" for +15 points on \"{$ledger->name}\" ledger.");
|
||||
});
|
||||
|
||||
test('non-owner participant creates a suggestion which defaults to pending and says suggested', function () {
|
||||
@@ -71,12 +71,12 @@ test('non-owner participant creates a suggestion which defaults to pending and s
|
||||
$mutationChatMessages = $mutation->chat->messages;
|
||||
expect($mutationChatMessages)->toHaveCount(1);
|
||||
expect($mutationChatMessages->first()->user_id)->toBeNull();
|
||||
expect($mutationChatMessages->first()->content)->toBe("Suggestion was created by <user:{$participant->id}>.");
|
||||
expect($mutationChatMessages->first()->content)->toBe("Suggestion was created by <user:{$participant->uuid}>.");
|
||||
|
||||
$dynamicChatMessages = $dynamic->chat->messages;
|
||||
expect($dynamicChatMessages)->toHaveCount(1);
|
||||
expect($dynamicChatMessages->first()->user_id)->toBeNull();
|
||||
expect($dynamicChatMessages->first()->content)->toBe("<user:{$participant->id}> suggested \"Suggested point reward\" for +10 points on \"{$ledger->name}\" ledger.");
|
||||
expect($dynamicChatMessages->first()->content)->toBe("<user:{$participant->uuid}> suggested \"Suggested point reward\" for +10 points on \"{$ledger->name}\" ledger.");
|
||||
});
|
||||
|
||||
test('owner can approve a pending suggestion and it is updated and logged', function () {
|
||||
@@ -115,11 +115,11 @@ test('owner can approve a pending suggestion and it is updated and logged', func
|
||||
// Note: one from boot created (empty or via seeder, but in our factory it starts with 0 messages if not manually logged,
|
||||
// actually our model booted hook creates the chat but doesn't log on boot, the update method creates 1 message)
|
||||
expect($mutationChatMessages->last()->user_id)->toBeNull();
|
||||
expect($mutationChatMessages->last()->content)->toBe("Suggestion was APPROVED by <user:{$owner->id}>.");
|
||||
expect($mutationChatMessages->last()->content)->toBe("Suggestion was APPROVED by <user:{$owner->uuid}>.");
|
||||
|
||||
$dynamicChatMessages = $dynamic->chat->messages;
|
||||
expect($dynamicChatMessages->last()->user_id)->toBeNull();
|
||||
expect($dynamicChatMessages->last()->content)->toBe("<user:{$owner->id}> APPROVED the suggestion \"Polished dungeon floors\" for +20 points on \"{$ledger->name}\" ledger.");
|
||||
expect($dynamicChatMessages->last()->content)->toBe("<user:{$owner->uuid}> APPROVED the suggestion \"Polished dungeon floors\" for +20 points on \"{$ledger->name}\" ledger.");
|
||||
});
|
||||
|
||||
test('creating a mutation with 0 points fails validation', function () {
|
||||
|
||||
Reference in New Issue
Block a user