Skip to content

Commit

Permalink
fixed some backend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IrisOlfermann committed Sep 17, 2024
1 parent 0a38309 commit 01c5e15
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/Mealz/MealBundle/Controller/MealGuestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function getEventInvitationData(
$guestData = [
'date' => $invitation->getDay()->getDateTime(),
'lockDate' => $invitation->getDay()->getLockParticipationDateTime(),
'event' => $invitation->getEventParticipation()->getEvent()->getTitle(),
'event' => $invitation->getEventParticipation() ? $invitation->getEventParticipation()->getEvent()->getTitle() : null,
];

return new JsonResponse($guestData, Response::HTTP_OK);
Expand Down
2 changes: 1 addition & 1 deletion src/Mealz/MealBundle/Entity/GuestInvitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function setId(string $id): static

return $this;
}
public function getEventParticipation() : EventParticipation
public function getEventParticipation(): ?EventParticipation
{
return $this->eventParticipation;
}
Expand Down
19 changes: 12 additions & 7 deletions src/Mealz/MealBundle/Tests/Controller/EventControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ public function testJoin(): void
$this->assertNotNull($day);

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

$url = '/api/events/participation/' . $day->getDateTime()->format('Y-m-d') . '%20' . $day->getDateTime()->format('H:i:s');
$eventParticipationId = $eventParticipation->getId();
$url = '/api/events/participation/' . $day->getDateTime()->format('Y-m-d') . '%20' . $day->getDateTime()->format('H:i:s') .'/'. $eventParticipationId;
$this->client->request('POST', $url);
$response = $this->client->getResponse();
$this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());

$content = json_decode($this->client->getResponse()->getContent());
Expand Down Expand Up @@ -175,11 +176,13 @@ public function testLeave(): void
$day = $dayRepo->matching($criteria)->get(0);

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


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

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

Expand Down Expand Up @@ -214,18 +217,20 @@ public function testGetEventParticipants(): void
$this->assertNotNull($day);

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

$date = $day->getDateTime()->format('Y-m-d') . '%20' . $day->getDateTime()->format('H:i:s');

// Verify no participants in new event
$this->client->request('GET', '/api/participations/event/' . $date);
$url = '/api/events/participation/' . $date .'/'. $eventParticipationId;
$this->client->request('GET', $url);
$participants = json_decode($this->client->getResponse()->getContent());
$this->assertEquals(0, count($participants));

$this->client->request('POST', '/api/events/participation/' . $date);
$this->client->request('POST', '/api/events/participation/' . $date.'/'. $eventParticipationId);
$this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());

$this->client->request('GET', '/api/participations/event/' . $date);
$this->client->request('GET', '/api/events/participation/' . $date .'/'. $eventParticipationId);
$participants = json_decode($this->client->getResponse()->getContent());

$this->assertEquals(1, count($participants));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private function createFutureEmptyWeek(DateTime $date): void
"-1": []
},
"id": -2,
"event": null,
"events": null,
"enabled": true,
"date": {
"date": "' . $localDate->modify('+1 day')->format('Y-m-d') . ' 12:00:00.000000",
Expand All @@ -260,7 +260,7 @@ private function createFutureEmptyWeek(DateTime $date): void
"-1": []
},
"id": -3,
"event": null,
"events": null,
"enabled": true,
"date": {
"date": "' . $localDate->modify('+1 day')->format('Y-m-d') . ' 12:00:00.000000",
Expand All @@ -278,7 +278,7 @@ private function createFutureEmptyWeek(DateTime $date): void
"-1": []
},
"id": -4,
"event": null,
"events": null,
"enabled": true,
"date": {
"date": "' . $localDate->modify('+1 day')->format('Y-m-d') . ' 12:00:00.000000",
Expand All @@ -296,7 +296,7 @@ private function createFutureEmptyWeek(DateTime $date): void
"-1": []
},
"id": -5,
"event": ' . $testEvent->getId() . ',
"events": ' . $testEvent->getId() . ',
"enabled": true,
"date": {
"date": "' . $localDate->modify('+1 day')->format('Y-m-d') . ' 12:00:00.000000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function testnewGuestEventInvitation(): void
$url = '/event/invitation/' . $eventParticipation->getDay()->getId() . $eventParticipation->getId();

$this->client->request('GET', $url);
$response = $this->client->getResponse();
$this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());

$guestLink = json_decode($this->client->getResponse()->getContent())->url;
Expand All @@ -65,9 +66,11 @@ public function testGetEventInvitationData(): void
$eventParticipation = $this->createFutureEvent();
$profile = $this->createProfile('Max', 'Mustermann' . time());
$this->persistAndFlushAll([$profile]);
$eventInvitation = $guestInvitationRepo->findOrCreateInvitation($profile, $eventParticipation->getDay());
$eventInvitation = $guestInvitationRepo->findOrCreateEventInvitation($profile, $eventParticipation->getDay(), $eventParticipation);

$this->client->request('GET', '/api/event/invitation/' . $eventInvitation->getId());
$response = $this->client->getResponse();

$this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());

$content = json_decode($this->client->getResponse()->getContent());
Expand All @@ -91,7 +94,7 @@ public function testJoinEventAsGuest(): void
$eventParticipation = $this->createFutureEvent();
$profile = $this->createProfile('Max', 'Mustermann' . time());
$this->persistAndFlushAll([$profile]);
$eventInvitation = $guestInvitationRepo->findOrCreateInvitation($profile, $eventParticipation->getDay());
$eventInvitation = $guestInvitationRepo->findOrCreateEventInvitation($profile, $eventParticipation->getDay(), $eventParticipation);

// with company
$this->client->request(
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/src/api/getDashboardData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type EventParticipation = {
participations: number;
isParticipating: boolean;
isPublic: boolean;
day:Day;
day: Day;
};

export type Event = {
Expand Down
11 changes: 9 additions & 2 deletions src/Resources/src/api/getEventGuestLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ import type { EventParticipation } from './getDashboardData';
import { type Link } from './getGuestLink';

export default async function getEventGuestLink(eventParticipation?: EventParticipation) {
console.log('eventParticipation im getEventGuestLink:\n '+ JSON.stringify(eventParticipation));
const { error, response: link, request } = useApi<Link>('GET', `/event/invitation/${eventParticipation?.day.dayId}/${eventParticipation?.participationId}`);
console.log('eventParticipation im getEventGuestLink:\n ' + JSON.stringify(eventParticipation));
const {
error,
response: link,
request
} = useApi<Link>(
'GET',
`/event/invitation/${eventParticipation?.day.dayId}/${eventParticipation?.participationId}`
);

await request();

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/src/api/getEventParticipants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default async function getEventParticipants(date: string, participationId
);

await request();
console.log(response)
console.log(response);
return { error, response };
}
4 changes: 3 additions & 1 deletion src/Resources/src/components/dashboard/GuestLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const url = ref('');
onMounted(async () => {
const { link, error } =
props.invitation === Invitation.MEAL ? await useGuestLink(props.dayID) : await getEventGuestLink(props.eventParticipation);
props.invitation === Invitation.MEAL
? await useGuestLink(props.dayID)
: await getEventGuestLink(props.eventParticipation);
if (error.value === false && link.value !== undefined) {
copyTextToClipboard(link.value.url);
url.value = link.value.url;
Expand Down
26 changes: 17 additions & 9 deletions src/Resources/src/stores/dashboardStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { Store } from '@/stores/store';
import { type Dashboard, type Day, type EventParticipation, type Meal, type Slot, useDashboardData, type Week } from '@/api/getDashboardData';
import {
type Dashboard,
type Day,
type EventParticipation,
type Meal,
type Slot,
useDashboardData,
type Week
} from '@/api/getDashboardData';
import { type Dictionary } from '@/types/types';
import { mercureReceiver } from '@/tools/mercureReceiver';
import useMealState from '@/services/useMealState';
Expand Down Expand Up @@ -43,12 +51,12 @@ class DashboardStore extends Store<Dashboard> {
public getDayByEventParticipationId(participationId: number): Day | undefined {
for (const week of Object.values(this.state.weeks)) {
for (const day of Object.values(week.days)) {
for (const iterator in Object.values(day.events )){
if( day.events[iterator].participationId === participationId){
for (const iterator in Object.values(day.events)) {
if (day.events[iterator].participationId === participationId) {
return day;
}
}
}
}
}
}

Expand Down Expand Up @@ -122,9 +130,9 @@ class DashboardStore extends Store<Dashboard> {

public updateEventParticipation(weekId: number, dayId: number, eventId: number, participations: number) {
const day = this.getDay(weekId, dayId);
if (day !== null && day !== undefined && day.events !== null ) {
for (const iterator in Object.values(day.events )){
if( day.events[iterator].eventId === eventId){
if (day !== null && day !== undefined && day.events !== null) {
for (const iterator in Object.values(day.events)) {
if (day.events[iterator].eventId === eventId) {
day.events[iterator].participations = participations;
}
}
Expand All @@ -135,8 +143,8 @@ class DashboardStore extends Store<Dashboard> {
const day = this.getDayByEventParticipationId(participationId);
console.log(day);
if (day !== undefined) {
for (const iterator in Object.values(day.events )){
if( day.events[iterator].participationId === participationId){
for (const iterator in Object.values(day.events)) {
if (day.events[iterator].participationId === participationId) {
day.events[iterator].isParticipating = isParticipating;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/src/stores/weeksStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface SimpleDay {
enabled: boolean;
}

export interface SimpleEvent {
export interface SimpleEvent {
id: number;
event: {
slug: string;
Expand Down Expand Up @@ -257,7 +257,7 @@ export function useWeeks() {
for (const [key, meals] of Object.entries(day.meals)) {
menuDay.meals[key] = meals.map((meal) => createMealDTO(meal));
}
if(day.events !== undefined){
if (day.events !== undefined) {
for (const [key, event] of Object.entries(day.events)) {
menuDay.events[key] = createEventDTO(event);
}
Expand Down

0 comments on commit 01c5e15

Please sign in to comment.