feat: notify configured recipients when something is booked
This commit is contained in:
1 parent
be37fc81f6
commit
d287cb2600
23 files changed
+1014
-1
No files matched your search
@@ -8,6 +8,7 @@ use App\Entity\Booking;
|
||||
use App\Entity\BookingSeries;
|
||||
use App\Entity\Resource;
|
||||
use App\Entity\ResourceGroup;
|
||||
use App\Entity\ResourceTypeSettings;
|
||||
use App\Entity\User;
|
||||
use App\Enum\RecurrenceRule;
|
||||
use App\Enum\ResourceType;
|
||||
@@ -48,6 +49,9 @@ class ResourceAdminControllerTest extends WebTestCase
|
||||
|
||||
$this->client->request('GET', '/admin/resources/new/desk', server: ['HTTP_HX-Request' => 'true']);
|
||||
self::assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
||||
|
||||
$this->client->request('GET', '/admin/resource-types/desk/notifications', server: ['HTTP_HX-Request' => 'true']);
|
||||
self::assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
public function testTheListShowsRoomsAndRetiredResources(): void
|
||||
@@ -293,6 +297,52 @@ class ResourceAdminControllerTest extends WebTestCase
|
||||
*
|
||||
* @param array<string, string> $fields
|
||||
*/
|
||||
public function testNotificationRecipientsAreSavedForAKind(): void
|
||||
{
|
||||
$this->client->loginUser($this->admin());
|
||||
|
||||
$response = $this->submit('/admin/resource-types/desk/notifications', 'resource_type_settings_form', [
|
||||
// Pasted from a mail client, separators and all: the form is meant to cope.
|
||||
'notificationRecipients' => "[email protected], [email protected]\n\n",
|
||||
]);
|
||||
|
||||
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
||||
$settings = $this->em->getRepository(ResourceTypeSettings::class)->findOneBy(['type' => ResourceType::DESK]);
|
||||
self::assertNotNull($settings);
|
||||
self::assertSame(['[email protected]', '[email protected]'], $settings->getNotificationRecipients());
|
||||
}
|
||||
|
||||
public function testAnAddressThatIsNotOneIsRefused(): void
|
||||
{
|
||||
$this->client->loginUser($this->admin());
|
||||
|
||||
$response = $this->submit('/admin/resource-types/desk/notifications', 'resource_type_settings_form', [
|
||||
'notificationRecipients' => '[email protected] kein-komma-vergessen',
|
||||
]);
|
||||
|
||||
self::assertSame(Response::HTTP_UNPROCESSABLE_ENTITY, $response->getStatusCode());
|
||||
self::assertNull($this->em->getRepository(ResourceTypeSettings::class)->findOneBy(['type' => ResourceType::DESK]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Emptying the field is how notifications are switched off again.
|
||||
*/
|
||||
public function testRecipientsCanBeClearedAgain(): void
|
||||
{
|
||||
$settings = new ResourceTypeSettings(ResourceType::DESK);
|
||||
$settings->setNotificationRecipients(['[email protected]']);
|
||||
$this->em->persist($settings);
|
||||
$this->em->flush();
|
||||
$this->client->loginUser($this->admin());
|
||||
|
||||
$this->submit('/admin/resource-types/desk/notifications', 'resource_type_settings_form', ['notificationRecipients' => '']);
|
||||
|
||||
$this->em->clear();
|
||||
$fresh = $this->em->getRepository(ResourceTypeSettings::class)->findOneBy(['type' => ResourceType::DESK]);
|
||||
self::assertNotNull($fresh);
|
||||
self::assertSame([], $fresh->getNotificationRecipients());
|
||||
}
|
||||
|
||||
private function submit(string $uri, string $formName, array $fields): Response
|
||||
{
|
||||
$crawler = $this->client->request('GET', $uri, server: ['HTTP_HX-Request' => 'true']);
|
||||
|
||||
Reference in new issue
Block a user