Files
crowd-fund-api/tests/Entity/ProjectCalendarTest.php
daniel.subiabre eb822d7ff1 feat: Mail integration (#259)
* feat: composer require symfony/mailer

* feat: add entities for massive emailing

* feat: expose mail API resources

* feat: add BatchStatus::SentErrors

* fix: show client status after consent command

* feat: define shape of audiences criteria

* fix: missing map entity provider for mail entities

* fix: unsupported array/object conversion of audience criterias

* fix: rename MailBatch to MailBroadcast and MailBatchRecipient to MailDispatch

* feat: add command to process broadcasts

* feat: add lock to broadcast process command

* fix: remove dispatchCursor from Broadcast

* fix: make broadcasts-process command fast

* feat: update mailpit config for local dev

* feat: add app:mail:dispatches-process command

* feat: it was fun to play with a massive mailing prototype

* feat: composer require symfonycasts/reset-password-bundle

* feat: make reset-password

* fix: bad ALTER on migration down op

* feat: add migration for reset password bundle

* fix: update forms style

* feat: configure mailer address via env var

* fix: remove missing asset reference

* feat: translate /auth/reset-password

* feat: translate email message

* fix: calendar minimum optimum deadline not being set when release was given

* feat: translate /check-email

* feat: translate /reset

* fix: rename main SecurityController path to /auth

* feat: add known oauth2 clients controllr

* fix: deprecated custom responses openapi context definitions

* fix: projects not in campaign can still have a calendar

* fix: weird af regression out of the blue, fuck software

* feat: fuck my life
2026-10-26 12:52:19 +01:00

94 lines
3.1 KiB
PHP

<?php
namespace App\Tests\Entity;
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use App\Entity\Project\Project;
use App\Entity\Project\ProjectDeadline;
use App\Entity\Project\ProjectStatus;
use App\Entity\User\User;
use App\Factory\Project\ProjectFactory;
use App\Factory\User\UserFactory;
use App\Service\Project\ProjectService;
use Doctrine\ORM\EntityManagerInterface;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;
class ProjectCalendarTest extends ApiTestCase
{
use ResetDatabase;
use Factories;
private EntityManagerInterface $entityManager;
private ProjectService $projectService;
private User $owner;
protected function setUp(): void
{
parent::setUp();
$this->entityManager = static::getContainer()->get(EntityManagerInterface::class);
$this->projectService = static::getContainer()->get(ProjectService::class);
$this->owner = $this->createTestUser();
}
private function createTestUser(string $handle = 'test_user', string $email = 'testuser@example.com'): User
{
return UserFactory::new([
'handle' => $handle,
'email' => $email,
'password' => 'projectapitestpassword',
])->create()->_real();
}
private function createTestProject(ProjectDeadline $deadline = ProjectDeadline::Minimum): Project
{
return ProjectFactory::createOne([
'owner' => $this->owner,
'status' => ProjectStatus::ToCampaign,
'deadline' => $deadline,
])->_real();
}
private function createProjectAndSetToInCampaign(ProjectDeadline $deadline = ProjectDeadline::Minimum): Project
{
$project = $this->createTestProject($deadline);
$project = $this->projectService->transition($project, ProjectStatus::InCampaign);
$this->entityManager->flush();
return $project;
}
public function testReleaseDateUpdatesOnCampaignStart(): void
{
$project = $this->createProjectAndSetToInCampaign();
$today = new \DateTimeImmutable('today');
$releaseDate = $project->getCalendar()->release;
$this->assertNotNull($releaseDate);
$this->assertGreaterThan($today, $releaseDate);
}
public function testMinimumDeadlineIsSetCorrectly(): void
{
$project = $this->createProjectAndSetToInCampaign(ProjectDeadline::Minimum);
$releaseDate = $project->getCalendar()->release;
$minimumDeadline = $project->getCalendar()->minimum;
$this->assertNotNull($releaseDate);
$this->assertNotNull($minimumDeadline);
$this->assertEquals($releaseDate->modify('+40 days'), $minimumDeadline);
}
public function testOptimumDeadlineIsSetCorrectly(): void
{
$project = $this->createProjectAndSetToInCampaign(ProjectDeadline::Optimum);
$minimumDeadline = $project->getCalendar()->minimum;
$optimumDeadline = $project->getCalendar()->optimum;
$this->assertNotNull($minimumDeadline);
$this->assertNotNull($optimumDeadline);
$this->assertEquals($minimumDeadline->modify('+40 days'), $optimumDeadline);
}
}