9
9
use App \Enums \IndividualRole ;
10
10
use App \Enums \LocationType ;
11
11
use App \Enums \MeetingType ;
12
+ use App \Enums \OrganizationRole ;
12
13
use App \Enums \ProjectInitiator ;
13
14
use App \Enums \SeekingForEngagement ;
14
15
use App \Enums \TeamRole ;
256
257
257
258
Notification::assertSentTo (
258
259
$ 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 ())]));
261
262
$ this ->assertStringContainsString ('A new engagement has been uploaded on The Accessibility Exchange: ' , $ notification ->toMail ()->render ());
262
263
expect ($ notification ->toArray ()['engagement_id ' ])->toEqual ($ notification ->engagement ->id );
263
264
@@ -268,6 +269,52 @@ function (EngagementAdded $notification) use ($engagement) {
268
269
Notification::assertNotSentTo ($ userWithoutNotifications , EngagementAdded::class);
269
270
});
270
271
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
+
271
318
test ('notifications are not sent for Individual users when an non-open-call engagement is published ' , function () {
272
319
Notification::fake ();
273
320
@@ -357,8 +404,8 @@ function (EngagementAdded $notification) use ($engagement) {
357
404
358
405
Notification::assertSentTo (
359
406
$ 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 ())]));
362
409
$ this ->assertStringContainsString ('A new engagement has been uploaded on The Accessibility Exchange: ' , $ notification ->toMail ()->render ());
363
410
expect ($ notification ->toArray ()['engagement_id ' ])->toEqual ($ notification ->engagement ->id );
364
411
@@ -372,6 +419,69 @@ function (EngagementAdded $notification) use ($engagement) {
372
419
Notification::assertNotSentTo ($ organization , EngagementAdded::class);
373
420
});
374
421
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
+
375
485
test ('users can view engagements ' , function () {
376
486
$ user = User::factory ()->create ();
377
487
$ engagement = Engagement::factory ()->create ();
0 commit comments