Skip to content

Commit a9f4c20

Browse files
committed
test: expand tests for engagement notifications and organizations
1 parent 68517bd commit a9f4c20

File tree

2 files changed

+135
-4
lines changed

2 files changed

+135
-4
lines changed

tests/Feature/EngagementTest.php

+114-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Enums\IndividualRole;
1010
use App\Enums\LocationType;
1111
use App\Enums\MeetingType;
12+
use App\Enums\OrganizationRole;
1213
use App\Enums\ProjectInitiator;
1314
use App\Enums\SeekingForEngagement;
1415
use App\Enums\TeamRole;
@@ -256,8 +257,8 @@
256257

257258
Notification::assertSentTo(
258259
$userWithNotifications,
259-
function (EngagementAdded $notification) use ($engagement) {
260-
260+
function (EngagementAdded $notification) use ($engagement, $organization) {
261+
expect($notification->toMail()->subject)->toBe(__('New Engagement from :projectable', ['projectable' => $organization->getTranslation('name', locale())]));
261262
$this->assertStringContainsString('A new engagement has been uploaded on The Accessibility Exchange:', $notification->toMail()->render());
262263
expect($notification->toArray()['engagement_id'])->toEqual($notification->engagement->id);
263264

@@ -268,6 +269,52 @@ function (EngagementAdded $notification) use ($engagement) {
268269
Notification::assertNotSentTo($userWithoutNotifications, EngagementAdded::class);
269270
});
270271

272+
test('view notifications for Individual users about new open-call engagements', function () {
273+
$userWithNotifications = User::factory()->create([
274+
'context' => UserContext::Individual->value,
275+
'notification_settings' => ['engagements' => '1'],
276+
]);
277+
$userWithoutNotifications = User::factory()->create([
278+
'context' => UserContext::Individual->value,
279+
'notification_settings' => ['engagements' => '0'],
280+
]);
281+
282+
$user = User::factory()->create(['context' => UserContext::Organization->value]);
283+
$organization = Organization::factory()
284+
->hasAttached($user, ['role' => TeamRole::Administrator->value])
285+
->create();
286+
287+
$project = Project::factory()->for($organization, 'projectable')->create([
288+
'estimate_requested_at' => now(),
289+
'estimate_returned_at' => now(),
290+
'estimate_approved_at' => now(),
291+
'agreement_received_at' => now(),
292+
]);
293+
294+
$engagement = Engagement::factory()->for($project)->create([
295+
'published_at' => null,
296+
]);
297+
298+
$engagement->meetings()->save(Meeting::factory()->create());
299+
300+
$data = UpdateEngagementRequest::factory()->meetingInPerson()->create([
301+
'name' => ['en' => $engagement->name],
302+
'publish' => '1',
303+
]);
304+
305+
actingAs($user)->put(localized_route('engagements.update', $engagement), $data)
306+
->assertSessionHasNoErrors()
307+
->assertRedirect(localized_route('engagements.manage', $engagement));
308+
309+
actingAs($userWithNotifications)->get(localized_route('dashboard.notifications'))
310+
->assertOk()
311+
->assertSee(__('New engagement added'));
312+
313+
actingAs($userWithoutNotifications)->get(localized_route('dashboard.notifications'))
314+
->assertOk()
315+
->assertDontSee(__('New engagement added'));
316+
});
317+
271318
test('notifications are not sent for Individual users when an non-open-call engagement is published', function () {
272319
Notification::fake();
273320

@@ -357,8 +404,8 @@ function (EngagementAdded $notification) use ($engagement) {
357404

358405
Notification::assertSentTo(
359406
$orgWithNotifications,
360-
function (EngagementAdded $notification) use ($engagement) {
361-
407+
function (EngagementAdded $notification) use ($engagement, $organization) {
408+
expect($notification->toMail()->subject)->toBe(__('New Engagement from :projectable', ['projectable' => $organization->getTranslation('name', locale())]));
362409
$this->assertStringContainsString('A new engagement has been uploaded on The Accessibility Exchange:', $notification->toMail()->render());
363410
expect($notification->toArray()['engagement_id'])->toEqual($notification->engagement->id);
364411

@@ -372,6 +419,69 @@ function (EngagementAdded $notification) use ($engagement) {
372419
Notification::assertNotSentTo($organization, EngagementAdded::class);
373420
});
374421

422+
test('view notifications for community org users about new engagements', function () {
423+
$userWithNotifications = User::factory()->create(['context' => UserContext::Organization->value]);
424+
Organization::factory()
425+
->hasAttached($userWithNotifications, ['role' => TeamRole::Administrator->value])
426+
->create([
427+
'notification_settings' => ['engagements' => '1'],
428+
'roles' => [OrganizationRole::ConsultationParticipant->value],
429+
]);
430+
431+
$userWithoutNotifications = User::factory()->create(['context' => UserContext::Organization->value]);
432+
Organization::factory()
433+
->hasAttached($userWithoutNotifications, ['role' => TeamRole::Administrator->value])
434+
->create([
435+
'notification_settings' => ['engagements' => '0'],
436+
'roles' => [OrganizationRole::ConsultationParticipant->value],
437+
]);
438+
439+
$user = User::factory()->create(['context' => UserContext::Organization->value]);
440+
$organization = Organization::factory()
441+
->hasAttached($user, ['role' => TeamRole::Administrator->value])
442+
->create([
443+
'roles' => [
444+
OrganizationRole::ConsultationParticipant->value,
445+
OrganizationRole::CommunityConnector->value,
446+
OrganizationRole::AccessibilityConsultant->value,
447+
],
448+
]);
449+
450+
$project = Project::factory()->for($organization, 'projectable')->create([
451+
'estimate_requested_at' => now(),
452+
'estimate_returned_at' => now(),
453+
'estimate_approved_at' => now(),
454+
'agreement_received_at' => now(),
455+
]);
456+
457+
$engagement = Engagement::factory()->for($project)->create([
458+
'published_at' => null,
459+
]);
460+
461+
$engagement->meetings()->save(Meeting::factory()->create());
462+
463+
$data = UpdateEngagementRequest::factory()->meetingInPerson()->create([
464+
'name' => ['en' => $engagement->name],
465+
'publish' => '1',
466+
]);
467+
468+
actingAs($user)->put(localized_route('engagements.update', $engagement), $data)
469+
->assertSessionHasNoErrors()
470+
->assertRedirect(localized_route('engagements.manage', $engagement));
471+
472+
actingAs($userWithNotifications)->get(localized_route('dashboard.notifications'))
473+
->assertOk()
474+
->assertSee(__('New engagement added'));
475+
476+
actingAs($userWithoutNotifications)->get(localized_route('dashboard.notifications'))
477+
->assertOk()
478+
->assertDontSee(__('New engagement added'));
479+
480+
actingAs($user)->get(localized_route('dashboard.notifications'))
481+
->assertOk()
482+
->assertDontSee(__('New engagement added'));
483+
});
484+
375485
test('users can view engagements', function () {
376486
$user = User::factory()->create();
377487
$engagement = Engagement::factory()->create();

tests/Feature/OrganizationTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -1471,3 +1471,24 @@ function (OrganizationPageNeedsUpdate $notification, $channels) use ($organizati
14711471

14721472
expect($organization->preferredLocale())->toBe('fr');
14731473
});
1474+
1475+
test('organizations can be found via schemaless scope', function () {
1476+
Organization::factory()->create([
1477+
'notification_settings' => ['engagements' => '0'],
1478+
'extra_attributes' => ['disability_and_deaf_constituencies' => '1'],
1479+
]);
1480+
Organization::factory()->create([
1481+
'notification_settings' => ['engagements' => '1'],
1482+
'extra_attributes' => ['cross_disability_and_deaf_constituencies' => '1'],
1483+
]);
1484+
1485+
$withNotifications = Organization::withNotificationSettings('engagements', '1')->get();
1486+
1487+
expect($withNotifications)->toHaveCount(1);
1488+
expect($withNotifications->first()->notification_settings->get('engagements'))->toBe('1');
1489+
1490+
$withExtraAttributes = Organization::withExtraAttributes('disability_and_deaf_constituencies', '1')->get();
1491+
1492+
expect($withExtraAttributes)->toHaveCount(1);
1493+
expect($withExtraAttributes->first()->extra_attributes->get('disability_and_deaf_constituencies'))->toBe('1');
1494+
});

0 commit comments

Comments
 (0)