Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Ruf committed Jan 17, 2024
1 parent 83645f7 commit 3162329
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 5 deletions.
56 changes: 52 additions & 4 deletions src/Mealz/MealBundle/Tests/Controller/EventControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use App\Mealz\MealBundle\Entity\Day;
use App\Mealz\MealBundle\Entity\Event;
use App\Mealz\MealBundle\Repository\DayRepositoryInterface;
use App\Mealz\MealBundle\Repository\EventParticipationRepositoryInterface;
use App\Mealz\MealBundle\Repository\ParticipantRepositoryInterface;
use App\Mealz\UserBundle\DataFixtures\ORM\LoadRoles;
use App\Mealz\UserBundle\DataFixtures\ORM\LoadUsers;
use DateTime;
Expand Down Expand Up @@ -141,9 +143,55 @@ public function testJoin(): void
$this->client->request('POST', $url);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(), $this->client->getResponse());

/** @var Day $changedDay */
$changedDay = $dayRepo->getDayByDate($day->getDateTime());
$this->assertCount(1, $changedDay->getEvent()->getParticipants());
$this->assertEquals(self::USER_KITCHEN_STAFF, $changedDay->getEvent()->getParticipants()->get(0)->getProfile()->getUsername());
$content = json_decode($this->client->getResponse()->getContent());
$this->assertNotNull($content);

$eventPartRepo = self::$container->get(EventParticipationRepositoryInterface::class);
$eventPart = $eventPartRepo->findOneBy(['id' => $content->participationId]);
$this->assertNotNull($eventPart);

$partRepo = self::$container->get(ParticipantRepositoryInterface::class);

/** @var Participant $part */
$part = $partRepo->findOneBy(['event' => $eventPart->getId()]);
$this->assertNotNull($part);

$this->assertEquals(self::USER_KITCHEN_STAFF, $part->getProfile()->getUsername());
}

public function testLeave(): void
{
$newEvent = $this->createEvent();
$this->persistAndFlushAll([$newEvent]);

$dayRepo = self::$container->get(DayRepositoryInterface::class);

$criteria = new \Doctrine\Common\Collections\Criteria();
$criteria->where(\Doctrine\Common\Collections\Criteria::expr()->gt('lockParticipationDateTime', new DateTime()));

/** @var Day $day */
$day = $dayRepo->matching($criteria)->get(0);

$eventParticipation = $this->createEventParticipation($day, $newEvent);

$url = '/api/events/participation/' . $day->getDateTime()->format('Y-m-d') . '%20' . $day->getDateTime()->format('H:i:s');
$this->client->request('POST', $url);

$url = '/api/events/participation/' . $day->getDateTime()->format('Y-m-d') . '%20' . $day->getDateTime()->format('H:i:s');
$this->client->request('DELETE', $url);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(), $this->client->getResponse());

$content = json_decode($this->client->getResponse()->getContent());
$this->assertNotNull($content);

$eventPartRepo = self::$container->get(EventParticipationRepositoryInterface::class);
$eventPart = $eventPartRepo->findOneBy(['id' => $content->participationId]);
$this->assertNotNull($eventPart);

$partRepo = self::$container->get(ParticipantRepositoryInterface::class);

/** @var Participant $part */
$part = $partRepo->findOneBy(['event' => $eventPart->getId()]);
$this->assertNull($part);
}
}
2 changes: 1 addition & 1 deletion src/Resources/src/stores/eventsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useFlashMessage from "@/services/useFlashMessage";
import { FlashMessageType } from "@/enums/FlashMessage";
import putEventUpdate from "@/api/putEventUpdate";
import deleteEvent from "@/api/deleteEvent";
import postJoinEvent, { EventParticipationResponse } from "@/api/postJoinEvent";
import postJoinEvent from "@/api/postJoinEvent";
import useEventsBus from '@/tools/eventBus';
import { deleteLeaveEvent } from "@/api/deleteLeaveEvent";

Expand Down
130 changes: 130 additions & 0 deletions tests/e2e/cypress/e2e/Dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,134 @@ describe('Test Dashboard View', () => {
}
});
});

it('should create an event, book it then leave the event again', () => {
cy.intercept('GET', '**/api/weeks').as('getWeeks');
cy.intercept('GET', '**/api/meals/count').as('getDishesCount');
cy.intercept('GET', '**/api/categories').as('getCategories');
cy.intercept('GET', '**/api/dishes').as('getDishes');
cy.intercept('GET', '**/api/events').as('getEvents');
cy.intercept('GET', '**/api/dashboard').as('getDashboard');


cy.visitMeals();
cy.get('span > a').contains('Mahlzeiten').click();
cy.wait(['@getWeeks']);

// Go to the next week
cy.get('h4').eq(1).contains('Woche').click();
cy.wait(['@getDishesCount', '@getCategories', '@getDishes']);

// add an event on monday
cy.get('input')
.eq(2)
.click()
.parent().parent()
.find('li').contains('Afterwork')
.click();

cy.get('h2').should('contain', 'Woche').click();

// Save
cy.contains('input', 'Speichern').click();

cy.get('[data-cy="msgClose"]').click();

// find the saved event
cy.get('input')
.eq(2)
.should('have.value', 'Afterwork');

// go to dashboard
cy.get('header > nav > div > a > svg').click();
cy.wait(['@getDashboard', '@getEvents']);

// confirm event is not joined yet
cy.get('h2')
.contains('Nächste Woche')
.parent()
.parent()
.find('span')
.contains('Montag')
.parent()
.parent()
.find('span')
.contains('Afterwork')
.parent()
.parent()
.find('div')
.eq(4)
.children()
.should('have.length', 0);

// join afterwork
cy.get('h2')
.contains('Nächste Woche')
.parent()
.parent()
.find('span')
.contains('Montag')
.parent()
.parent()
.find('span')
.contains('Afterwork')
.parent()
.parent()
.find('div')
.eq(4)
.click();

// confirm event has been joined
cy.get('h2')
.contains('Nächste Woche')
.parent()
.parent()
.find('span')
.contains('Montag')
.parent()
.parent()
.find('span')
.contains('Afterwork')
.parent()
.parent()
.find('div')
.eq(4)
.children()
.should('have.length', 1);

// leave afterwork
cy.get('h2')
.contains('Nächste Woche')
.parent()
.parent()
.find('span')
.contains('Montag')
.parent()
.parent()
.find('span')
.contains('Afterwork')
.parent()
.parent()
.find('div')
.eq(4)
.click();

// confirm event has been left
cy.get('h2')
.contains('Nächste Woche')
.parent()
.parent()
.find('span')
.contains('Montag')
.parent()
.parent()
.find('span')
.contains('Afterwork')
.parent()
.parent()
.find('div')
.eq(4)
.children()
.should('have.length', 0);
});
});

0 comments on commit 3162329

Please sign in to comment.