-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #416 from AOEpeople/tests/#261420-event-api
added tests for new event invitation functionality
- Loading branch information
Showing
7 changed files
with
290 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
src/Mealz/MealBundle/Tests/Controller/MealGuestControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Mealz\MealBundle\Tests\Controller; | ||
|
||
use App\Mealz\MealBundle\DataFixtures\ORM\LoadCategories; | ||
use App\Mealz\MealBundle\DataFixtures\ORM\LoadDays; | ||
use App\Mealz\MealBundle\DataFixtures\ORM\LoadDishes; | ||
use App\Mealz\MealBundle\DataFixtures\ORM\LoadDishVariations; | ||
use App\Mealz\MealBundle\DataFixtures\ORM\LoadEvents; | ||
use App\Mealz\MealBundle\DataFixtures\ORM\LoadMeals; | ||
use App\Mealz\MealBundle\DataFixtures\ORM\LoadWeeks; | ||
use App\Mealz\MealBundle\Repository\GuestInvitationRepository; | ||
use App\Mealz\UserBundle\DataFixtures\ORM\LoadRoles; | ||
use App\Mealz\UserBundle\DataFixtures\ORM\LoadUsers; | ||
|
||
class MealGuestControllerTest extends AbstractControllerTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->clearAllTables(); | ||
$this->loadFixtures([ | ||
new LoadWeeks(), | ||
new LoadDays(), | ||
new LoadCategories(), | ||
new LoadDishes(), | ||
new LoadDishVariations(), | ||
new LoadEvents(), | ||
new LoadMeals(), | ||
new LoadRoles(), | ||
new LoadUsers(self::$container->get('security.user_password_encoder.generic')), | ||
]); | ||
|
||
$this->loginAs(self::USER_KITCHEN_STAFF); | ||
} | ||
|
||
public function testnewGuestEventInvitation(): void | ||
{ | ||
$guestInvitationRepo = self::$container->get(GuestInvitationRepository::class); | ||
$eventParticipation = $this->createFutureEvent(); | ||
$url = '/event/invitation/' . $eventParticipation->getDay()->getId(); | ||
|
||
$this->client->request('GET', $url); | ||
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
|
||
$guestLink = json_decode($this->client->getResponse()->getContent())->url; | ||
$prefix = 'http://localhost/guest/event/'; | ||
$invitationId = str_ireplace($prefix, '', $guestLink); | ||
|
||
$invitation = $guestInvitationRepo->find($invitationId); | ||
$this->assertNotNull($invitation); | ||
$this->assertEquals( | ||
$eventParticipation->getEvent()->getTitle(), | ||
$invitation->getDay()->getEvent()->getEvent()->getTitle() | ||
); | ||
} | ||
|
||
public function testGetEventInvitationData(): void | ||
{ | ||
$guestInvitationRepo = self::$container->get(GuestInvitationRepository::class); | ||
$eventParticipation = $this->createFutureEvent(); | ||
$profile = $this->createProfile('Max', 'Mustermann' . time()); | ||
$this->persistAndFlushAll([$profile]); | ||
$eventInvitation = $guestInvitationRepo->findOrCreateInvitation($profile, $eventParticipation->getDay()); | ||
|
||
$this->client->request('GET', '/api/event/invitation/' . $eventInvitation->getId()); | ||
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
|
||
$content = json_decode($this->client->getResponse()->getContent()); | ||
$this->assertEquals( | ||
json_encode($eventParticipation->getDay()->getDateTime()), | ||
json_encode($content->date) | ||
); | ||
$this->assertEquals( | ||
json_encode($eventParticipation->getDay()->getLockParticipationDateTime()), | ||
json_encode($content->lockDate) | ||
); | ||
$this->assertEquals( | ||
$eventParticipation->getDay()->getEvent()->getEvent()->getTitle(), | ||
$content->event | ||
); | ||
} | ||
|
||
public function testJoinEventAsGuest(): void | ||
{ | ||
$guestInvitationRepo = self::$container->get(GuestInvitationRepository::class); | ||
$eventParticipation = $this->createFutureEvent(); | ||
$profile = $this->createProfile('Max', 'Mustermann' . time()); | ||
$this->persistAndFlushAll([$profile]); | ||
$eventInvitation = $guestInvitationRepo->findOrCreateInvitation($profile, $eventParticipation->getDay()); | ||
|
||
// with company | ||
$this->client->request( | ||
'POST', | ||
'/api/event/invitation/' . $eventInvitation->getId(), | ||
[], | ||
[], | ||
[], | ||
json_encode([ | ||
'firstName' => 'John', | ||
'lastName' => 'Doe', | ||
'company' => 'District 9', | ||
]) | ||
); | ||
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
|
||
// without company | ||
$this->client->request( | ||
'POST', | ||
'/api/event/invitation/' . $eventInvitation->getId(), | ||
[], | ||
[], | ||
[], | ||
json_encode([ | ||
'firstName' => 'Jane', | ||
'lastName' => 'Doe', | ||
'company' => null, | ||
]) | ||
); | ||
$this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
|
||
// without firstName | ||
$this->client->request( | ||
'POST', | ||
'/api/event/invitation/' . $eventInvitation->getId(), | ||
[], | ||
[], | ||
[], | ||
json_encode([ | ||
'firstName' => null, | ||
'lastName' => 'Doe', | ||
'company' => 'District 9', | ||
]) | ||
); | ||
$this->assertEquals(404, $this->client->getResponse()->getStatusCode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
describe('Test GuestEventInvitation', () => { | ||
beforeEach(() => { | ||
cy.resetDB(); | ||
cy.loginAs('kochomi'); | ||
}); | ||
|
||
it('should copy a invitation link to the clipboard then visit the link and register for an event', () => { | ||
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.intercept('GET', '**/api/participations/event/**').as('getParticipants'); | ||
cy.intercept('GET', '**/event/invitation/**').as('getEventInvitation'); | ||
cy.intercept('POST', '**/api/event/invitation/**').as('postEventInvitation'); | ||
|
||
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() | ||
.find('svg') | ||
.eq(0) | ||
.click(); | ||
|
||
cy.wait('@getEventInvitation'); | ||
|
||
cy.contains('span', 'In die Zwischenablage kopiert!') | ||
.parent() | ||
.parent() | ||
.children() | ||
.eq(0) | ||
.then($el => { | ||
cy.log('Link: ' + $el[0].innerText); | ||
const link = $el[0].innerText; | ||
expect(link).to.match(/^(http|https):\/\/(meals.test|localhost)\/guest\/event\/\S*$/); | ||
|
||
cy.clearAllSessionStorage(); | ||
cy.visit(link); | ||
|
||
cy.get('input[placeholder="Vorname"]') | ||
.click() | ||
.type('John'); | ||
|
||
cy.get('input[placeholder="Nachname"]') | ||
.click() | ||
.type('Doe'); | ||
|
||
cy.get('input[placeholder="Betrieb"]') | ||
.click() | ||
.type('District 17') | ||
|
||
cy.contains('input', 'An Event teilnehmen').click(); | ||
|
||
cy.wait('@postEventInvitation'); | ||
cy.get('[data-cy=msgClose]').click(); | ||
|
||
cy.visitMeals(); | ||
cy.loginAs('kochomi'); | ||
|
||
cy.get('h2') | ||
.contains('Nächste Woche') | ||
.parent() | ||
.parent() | ||
.find('span') | ||
.contains('Montag') | ||
.parent() | ||
.parent() | ||
.find('span') | ||
.contains('Afterwork') | ||
.parent() | ||
.find('svg') | ||
.eq(1) | ||
.click(); | ||
|
||
cy.get('span') | ||
.contains('Teilnahmen "Afterwork"') | ||
.parent() | ||
.parent() | ||
.find('ul') | ||
.contains('Doe, John (District 17)'); | ||
}); | ||
}); | ||
}); |