Skip to content

Commit

Permalink
tests(appointment): add integration test for base/calculated dates
Browse files Browse the repository at this point in the history
docs(appointment): add unit-test for documentation
  • Loading branch information
DumbergerL committed Nov 3, 2023
1 parent 1371fd2 commit 5b0c1f9
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 6 deletions.
105 changes: 102 additions & 3 deletions docs/out/CalendarAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Load all calendars:

```php
use CTApi\Models\Calendars\Appointment\Appointment;
use CTApi\Models\Calendars\Appointment\AppointmentRequest;
use CTApi\Models\Calendars\Calendar\CalendarRequest;

Expand Down Expand Up @@ -36,16 +37,17 @@
## Load appointments for calendar:

```php
use CTApi\Models\Calendars\Appointment\Appointment;
use CTApi\Models\Calendars\Appointment\AppointmentRequest;
use CTApi\Models\Calendars\Calendar\CalendarRequest;

$allCalendars = CalendarRequest::all();
$lastCalendar = end($allCalendars);

$appointments = $lastCalendar->requestAppointments()
?->where("from", "2020-01-01")
?->where("to", "2022-01-01")
?->get() ?? [];
?->where("from", "2020-01-01")
?->where("to", "2022-01-01")
?->get() ?? [];
$lastAppointment = end($appointments);

var_dump( $lastAppointment->getId());
Expand Down Expand Up @@ -129,6 +131,7 @@
## Load appointments for multiple calendars:

```php
use CTApi\Models\Calendars\Appointment\Appointment;
use CTApi\Models\Calendars\Appointment\AppointmentRequest;
use CTApi\Models\Calendars\Calendar\CalendarRequest;

Expand All @@ -139,6 +142,102 @@

```

## Series appointments:

```php
use CTApi\Models\Calendars\Appointment\Appointment;
use CTApi\Models\Calendars\Appointment\AppointmentRequest;
use CTApi\Models\Calendars\Calendar\CalendarRequest;

/**
* Load Seminar series:
* Consists of 2 series appointments
* - #1: Friday 03.11.2023
* - #2: Friday 10.11.2023
*/
$appointments = $this->loadSeriesAppointments();

$firstSeriesAppointment = $appointments[0];
$secondSeriesAppointment = $appointments[1];

/**
* ID PROPERTY:
* For every calculated series appointment the id stays the same as the base appointment:
*/
var_dump( $firstSeriesAppointment->getId());
// Output: 15

var_dump( $firstSeriesAppointment->getId());
// Output: 15


/**
* START_DATE / END_DATE PROPERTY:
* Shows the start date / end date of the series appointment.
*/
var_dump( $firstSeriesAppointment->getStartDate());
// Output: "2023-11-03T17:00:00Z"

var_dump( $firstSeriesAppointment->getEndDate());
// Output: "2023-11-03T18:30:00Z"


var_dump( $secondSeriesAppointment->getStartDate());
// Output: "2023-11-10T17:00:00Z"

var_dump( $secondSeriesAppointment->getEndDate());
// Output: "2023-11-10T18:30:00Z"


/**
* BASE START_DATE / END_DATE PROPERTY:
* Refers for every appointment to the base appointment, where the series starts:
*/
var_dump( $firstSeriesAppointment->getBaseStartDate());
// Output: "2023-11-03T17:00:00Z"

var_dump( $firstSeriesAppointment->getBaseEndDate());
// Output: "2023-11-03T18:30:00Z"


var_dump( $secondSeriesAppointment->getBaseStartDate());
// Output: "2023-11-03T17:00:00Z"

var_dump( $secondSeriesAppointment->getBaseEndDate());
// Output: "2023-11-03T18:30:00Z"


/**
* CALCULATED START_DATE / END_DATE PROPERTY:
* Same as default startDate / endDate property. Contains the calculated date for the specific appointment.
*/
var_dump( $firstSeriesAppointment->getCalculatedStartDate());
// Output: "2023-11-03T17:00:00Z"

var_dump( $firstSeriesAppointment->getCalculatedEndDate());
// Output: "2023-11-03T18:30:00Z"


var_dump( $secondSeriesAppointment->getCalculatedStartDate());
// Output: "2023-11-10T17:00:00Z"

var_dump( $secondSeriesAppointment->getCalculatedEndDate());
// Output: "2023-11-10T18:30:00Z"


/**
* DATE_TIME:
* All string properties can be casted to date time.
*/
$firstSeriesAppointment->getStartDateAsDateTime();
$firstSeriesAppointment->getBaseStartDateAsDateTime();
$firstSeriesAppointment->getCalculatedStartDateAsDateTime();
$firstSeriesAppointment->getEndDateAsDateTime();
$firstSeriesAppointment->getBaseEndDateAsDateTime();
$firstSeriesAppointment->getCalculatedEndDateAsDateTime();

```

## Load appointment with event and bookings (CombinedAppointment):

Load single appointment including the event and bookings for this appointment.
Expand Down
4 changes: 4 additions & 0 deletions docs/src/ressources/CalendarAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

{{ \CTApi\Test\Unit\Docs\CalendarRequestTest.testGetAppointmentsViaBuilder }}

## Series appointments:

{{ \CTApi\Test\Unit\Docs\CalendarRequestTest.testGetSeriesAppointments}}

## Load appointment with event and bookings (CombinedAppointment):

Load single appointment including the event and bookings for this appointment.
Expand Down
37 changes: 37 additions & 0 deletions tests/Integration/Requests/CalendarRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
namespace CTApi\Test\Integration\Requests;


use CTApi\CTLog;
use CTApi\Models\Calendars\Appointment\Appointment;
use CTApi\Models\Calendars\Appointment\AppointmentRequest;
use CTApi\Models\Calendars\Calendar\CalendarRequest;
use CTApi\Models\Calendars\CombinedAppointment\CombinedAppointmentRequest;
Expand Down Expand Up @@ -100,4 +102,39 @@ public function testCombinedAppointmentRequest()
$this->assertEqualsTestData("combined_appointment", "any_booking.resource.id", $oneBooking->getResource()?->getId());
$this->assertEqualsTestData("combined_appointment", "any_booking.resource.name", $oneBooking->getResource()?->getName());
}

public function testSeriesAppointment()
{
$testCase = IntegrationTestData::getTestCase("appointment_series");

$calendar_id = $testCase->getFilterAsInt("calendar_id");
$from = $testCase->getFilter("from");
$to = $testCase->getFilter("to");

$appointments = AppointmentRequest::forCalendar($calendar_id)
->where("from", $from)
->where("to", $to)->get();

$this->assertTrue(sizeof($appointments) >= 2);

$firstSeriesAppointment = null;
$first_startDate = $testCase->getResult("first_series_appointment.calculated_start_date");
$secondSeriesAppointment = null;
$second_startDate = $testCase->getResult("second_series_appointment.calculated_start_date");

foreach($appointments as $appointment){
if($first_startDate === $appointment->getStartDate()){
$firstSeriesAppointment = $appointment;
}
if($second_startDate === $appointment->getStartDate()){
$secondSeriesAppointment = $appointment;
}
}

$this->assertNotNull($firstSeriesAppointment);
$this->assertEquals($testCase->getResult("first_series_appointment.base_start_date"), $firstSeriesAppointment->getBaseStartDate());

$this->assertNotNull($secondSeriesAppointment);
$this->assertEquals($testCase->getResult("second_series_appointment.base_start_date"), $secondSeriesAppointment->getBaseStartDate());
}
}
20 changes: 20 additions & 0 deletions tests/Integration/integration-test-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,26 @@
}
}
},
"appointment_series": {
"description": "Filter series appointment.",
"filter": {
"calendar_id": 2,
"from": "2023-11-02",
"to": "2023-11-11"
},
"result": {
"first_series_appointment": {
"id": 14,
"base_start_date": "2023-11-03T17:00:00Z",
"calculated_start_date": "2023-11-03T17:00:00Z"
},
"second_series_appointment": {
"id": 14,
"base_start_date": "2023-11-03T17:00:00Z",
"calculated_start_date": "2023-11-10T17:00:00Z"
}
}
},
"permission_group": {
"description": "Load permission for group.",
"filter": {
Expand Down
80 changes: 77 additions & 3 deletions tests/Unit/Docs/CalendarRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace CTApi\Test\Unit\Docs;


use CTApi\Models\Calendars\Appointment\Appointment;
use CTApi\Models\Calendars\Appointment\AppointmentRequest;
use CTApi\Models\Calendars\Calendar\CalendarRequest;
use CTApi\Test\Unit\TestCaseHttpMocked;
Expand Down Expand Up @@ -31,9 +32,9 @@ public function testGetApppointments()
$lastCalendar = end($allCalendars);

$appointments = $lastCalendar->requestAppointments()
?->where("from", "2020-01-01")
?->where("to", "2022-01-01")
?->get() ?? [];
?->where("from", "2020-01-01")
?->where("to", "2022-01-01")
?->get() ?? [];
$lastAppointment = end($appointments);

$this->assertEquals(848, $lastAppointment->getId());
Expand Down Expand Up @@ -78,4 +79,77 @@ public function testGetAppointmentsViaBuilder()
->where("to", "2022-02-01")->get();
}


public function testGetSeriesAppointments()
{
/**
* Load Seminar series:
* Consists of 2 series appointments
* - #1: Friday 03.11.2023
* - #2: Friday 10.11.2023
*/
$appointments = $this->loadSeriesAppointments();

$firstSeriesAppointment = $appointments[0];
$secondSeriesAppointment = $appointments[1];

/**
* ID PROPERTY:
* For every calculated series appointment the id stays the same as the base appointment:
*/
$this->assertEquals(15, $firstSeriesAppointment->getId());
$this->assertEquals(15, $firstSeriesAppointment->getId());

/**
* START_DATE / END_DATE PROPERTY:
* Shows the start date / end date of the series appointment.
*/
$this->assertEquals("2023-11-03T17:00:00Z", $firstSeriesAppointment->getStartDate());
$this->assertEquals("2023-11-03T18:30:00Z", $firstSeriesAppointment->getEndDate());

$this->assertEquals("2023-11-10T17:00:00Z", $secondSeriesAppointment->getStartDate());
$this->assertEquals("2023-11-10T18:30:00Z", $secondSeriesAppointment->getEndDate());

/**
* BASE START_DATE / END_DATE PROPERTY:
* Refers for every appointment to the base appointment, where the series starts:
*/
$this->assertEquals("2023-11-03T17:00:00Z", $firstSeriesAppointment->getBaseStartDate());
$this->assertEquals("2023-11-03T18:30:00Z", $firstSeriesAppointment->getBaseEndDate());

$this->assertEquals("2023-11-03T17:00:00Z", $secondSeriesAppointment->getBaseStartDate());
$this->assertEquals("2023-11-03T18:30:00Z", $secondSeriesAppointment->getBaseEndDate());

/**
* CALCULATED START_DATE / END_DATE PROPERTY:
* Same as default startDate / endDate property. Contains the calculated date for the specific appointment.
*/
$this->assertEquals("2023-11-03T17:00:00Z", $firstSeriesAppointment->getCalculatedStartDate());
$this->assertEquals("2023-11-03T18:30:00Z", $firstSeriesAppointment->getCalculatedEndDate());

$this->assertEquals("2023-11-10T17:00:00Z", $secondSeriesAppointment->getCalculatedStartDate());
$this->assertEquals("2023-11-10T18:30:00Z", $secondSeriesAppointment->getCalculatedEndDate());

/**
* DATE_TIME:
* All string properties can be casted to date time.
*/
$firstSeriesAppointment->getStartDateAsDateTime();
$firstSeriesAppointment->getBaseStartDateAsDateTime();
$firstSeriesAppointment->getCalculatedStartDateAsDateTime();
$firstSeriesAppointment->getEndDateAsDateTime();
$firstSeriesAppointment->getBaseEndDateAsDateTime();
$firstSeriesAppointment->getCalculatedEndDateAsDateTime();
}

/**
* @return Appointment[]
*/
private function loadSeriesAppointments(): array
{
$fileContent = file_get_contents(__DIR__ . '/calendar_request_series_appointments.json');
$json = json_decode($fileContent, true);
return Appointment::createModelsFromArray($json["data"]);
}

}
Loading

0 comments on commit 5b0c1f9

Please sign in to comment.