Skip to content

Commit

Permalink
🐛 tests verfeinert
Browse files Browse the repository at this point in the history
sicherggestellt, dass events nur einmal kommen
  • Loading branch information
P1tt187 committed Jun 18, 2023
1 parent 7488a86 commit da70998
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 29 deletions.
8 changes: 5 additions & 3 deletions app/EventApi/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

namespace Lara\EventApi;

use Carbon\Carbon;

class Event
{
public string $import_id;
public string $name;
public string $start;
public \DateTime $start_time;
public string $start_time;
public string $end;
public \DateTime $end_time;
public string $end_time;
public ?string $place;
public ?string $icon;
public ?string $color;
public ?int $preparation_time;
public ?string $marquee;
public ?string $link;
public bool $cancelled;
public \DateTime $updated_on;
public string $updated_on;
}
2 changes: 1 addition & 1 deletion app/EventApi/EventData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Lara\EventApi;
class EventData
{
public \DateTime $generated_on;
public string $generated_on;

/** */
public array $events;
Expand Down
20 changes: 12 additions & 8 deletions app/EventView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

namespace Lara;

use Illuminate\Support\Carbon;
use Lara\EventApi\Event;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Casts\AsStringable;

/** EVENT_VIEW
* @property string import_id
* @property string name
* @property \DateTime start
* @property Carbon\Carbon start
* @property string start_time
* @property \DateTime end
* @property Carbon\Carbon end
* @property string end_time
* @property string place
* @property string marquee
* @property string link
* @property bool cancelled
* @property \DateTime updated_on
* @property Carbon\Carbon updated_on
* @property int section_id
*/
class EventView extends Model
Expand All @@ -28,22 +30,24 @@ class EventView extends Model

protected $fillable = ['import_id', 'name', 'start', 'start_time', 'end', 'end_time', 'place', 'marquee', 'link', 'cancelled', 'updated_on', 'section_id'];

protected $casts = ['start' => 'date', 'start_time'=>'datetime', 'end' => 'date', 'end_time'=>'datetime', 'updated_on' => 'datetime'];

public function toEvent(){
$event = new Event();
$event->import_id = $this->import_id;
$event->name = $this->name;
$event->start = $this->start;
$event->start_time = $this->start_time;
$event->end = $this->end;
$event->end_time = $this->end_time;
$event->start = $this->start->toDateString();
$event->start_time = $this->start_time->toTimeString();
$event->end = $this->end->toDateString();
$event->end_time = $this->end_time->toTimeString();
$event->place = $this->place;
$event->icon = $this->icon;
$event->color = $this->color;
$event->preparation_time = $this->preparation_time;
$event->marquee = $this->marquee;
$event->link = $this->link;
$event->cancelled = $this->cancelled;
$event->updated_on = new \DateTime($this->updated_on);
$event->updated_on = Carbon::create($this->updated_on)->toIso8601ZuluString();
return $event;
}
}
5 changes: 4 additions & 1 deletion app/Http/Controllers/EventApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lara\Http\Controllers;


use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use Lara\EventApi\EventData;
Expand All @@ -23,7 +24,9 @@ public function getEventsFor($sectionName)
});

$eventData = new EventData();
$eventData->generated_on = Carbon::now()->toIso8601ZuluString();
$eventData->events = $events->toArray();
return response()->json($eventData, 200);
$json = preg_replace('/,\s*"[^"]+":null|"[^"]+":null,?/', '',json_encode($eventData));
return response($json)->header('Content-Type', 'application/json');
}
}
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,24 @@


"johngrogg/ics-parser": "^3",
"justinrainbow/json-schema": "^5.2",
"laravel/framework": "^8",
"laravel/legacy-factories": "^1.3",
"laravel/tinker": "^2.0",
"laravel/ui": "^3.0",
"laravelcollective/html": "^6",
"pragmarx/google2fa-laravel": "^2.0",
"rap2hpoutre/laravel-log-viewer": "^2.0"
"rap2hpoutre/laravel-log-viewer": "^2.0",
"wol-soft/php-json-schema-model-generator-production": "^0.18.1"
},
"require-dev": {
"nunomaduro/collision": "^5.0",
"fakerphp/faker": "^1.14",
"facade/ignition": "^2.5",
"doctrine/dbal": "^3.0",
"mockery/mockery": "~1.6.0",
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.14",
"filp/whoops": "^2.7.3",
"mockery/mockery": "~0.9.11",
"nunomaduro/collision": "^5.0",
"orangehill/iseed": "dev-master",
"phpunit/phpunit": "^9",
"filp/whoops": "^2.7.3"
Expand Down
4 changes: 2 additions & 2 deletions database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@
'evnt_public_info' => $faker->sentence(),
'evnt_private_details' => $faker->boolean(70) ? $privateInfoAdditionalLine : '' . $faker->sentence(),
'evnt_is_private' => $faker->boolean(10),
'evnt_is_published' => 0,
'evnt_is_published' => $faker->boolean(70),
'price_tickets_normal' => $faker->numberBetween(0, 5),
'price_tickets_external' => $faker->numberBetween(0, 10),
'price_normal' => $faker->randomFloat(2, 0, 1),
'price_external' => $faker->randomFloat(2, 1, 2),
'facebook_done' => $faker->boolean(50),
'event_url' => $faker->url(),
'event_url' => str_replace("http://","https://", $faker->url()),
'external_id' => $faker->word()
];
});
Expand Down
11 changes: 7 additions & 4 deletions database/migrations/2023_06_15_003622_create_view_event_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@ public function up()
join sections s on
s.id = ce.plc_id
where
ce.evnt_is_published = 1
and ce.evnt_is_private = 0
AND (
STR_TO_DATE(CONCAT(ce.evnt_date_start,
' ',
ce.evnt_time_start),
'%Y-%m-%d %H:%i:%s') > now()
or
or
STR_TO_DATE(CONCAT(ce.evnt_date_end,
' ',
ce.evnt_time_end),
'%Y-%m-%d %H:%i:%s') > now()
' ',
ce.evnt_time_end),
'%Y-%m-%d %H:%i:%s') > now())
order by
STR_TO_DATE(CONCAT(ce.evnt_date_start,
' ',
Expand Down
17 changes: 11 additions & 6 deletions tests/Feature/EventApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Lara\ClubEvent;
use Lara\Club;
use Tests\TestCase;

use Lara\EventView;
use Lara\Section;
use Illuminate\Support\Facades\Storage;
use JsonSchema\Validator;

use Carbon\Carbon;
class EventApiControllerTest extends TestCase
Expand All @@ -21,11 +24,16 @@ public function testGetEventsForExistingSection()

// Create a section for testing
$section = Section::create(['title' => 'Test-Section']);
Club::create(['id' => $section->id,'clb_title' => 'Test-Section']);


// Create event views for the section
factory(ClubEvent::class,3)->create()->each(function( ClubEvent $clubEvent ) {
$clubEvent->start = Carbon::now()->add(1,'day');
$clubEvent->end = Carbon::now()->add(2,'day');
factory(ClubEvent::class,3)->create()->each(function( ClubEvent $clubEvent ) use($section) {
$clubEvent->evnt_date_start = Carbon::now()->add(1,'day');
$clubEvent->evnt_date_end = Carbon::now()->add(2,'day');
$clubEvent->evnt_is_published=true;
$clubEvent->plc_id = $section->id;
$clubEvent->save();
});

// Send a GET request to the API endpoint
Expand All @@ -48,9 +56,6 @@ public function testGetEventsForExistingSection()
'end',
'end_time',
'place',
'icon',
'color',
'preparation_time',
'marquee',
'link',
'cancelled',
Expand Down

0 comments on commit da70998

Please sign in to comment.