Skip to content

Commit

Permalink
Fix tests for real
Browse files Browse the repository at this point in the history
- Tests did check on german words, test ran on github with english locale
- Added more beauty to the methods
- Adjusted .env.example to get a better kickstart
- Updated migrations to handle the on_delete process correctly
  • Loading branch information
FloKnapp committed Nov 18, 2024
1 parent 3510bd5 commit f92adfd
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 23 deletions.
10 changes: 6 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
APP_NAME=Laravel
APP_NAME=Epilepsy-Tracker
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_TIMEZONE=Europe/Berlin
APP_URL=http://localhost

APP_LOCALE=en
APP_LOCALE=de
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US
APP_FAKER_LOCALE=de_DE

#SAIL_XDEBUG_MODE=develop,debug,coverage

APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Api/EpisodeDraftController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public function index()
public function store(Request $request)
{
$episode = Episode::create();
$episode->save();

return response()->json($episode->public_id);
}
Expand Down
14 changes: 6 additions & 8 deletions app/Http/Controllers/EpisodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,19 @@ public function show(string $publicId): View
*/
public function store(EpisodeStoreRequest $request)
{
$rawType = $request->get('type');
$rawType = $request->get('type');
$rawIntensity = $request->get('intensity');
$rawSymptoms = $request->get('symptoms');
$rawTriggers = $request->get('triggers');
$rawDuration = $request->get('duration');
$rawSymptoms = $request->get('symptoms');
$rawTriggers = $request->get('triggers');
$rawDuration = $request->get('duration');

$type = EpisodeType::firstOrCreate(['name' => $rawType]);

$episode = new Episode([
$episode = Episode::create([
'intensity' => $rawIntensity,
'duration' => $rawDuration,
'state' => EpisodeStateType::PUBLISHED->value
]);
$episode->save();

$type = EpisodeType::firstOrCreate(['name' => $rawType]);
$episode->types()->attach($type);

$this->processSymptoms($episode, $rawSymptoms);
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/WebsiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function index(): View
->orderBy('id', 'desc')
->get();

// Calendar events
$events = [];

foreach ($episodes as $episode) {
Expand All @@ -29,6 +30,7 @@ public function index(): View
];
}

// Only show the last 3 episodes
$episodes = collect($episodes)->slice(0,3);

return view('index', compact('events', 'episodes'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function up(): void
Schema::create('episodes', function (Blueprint $table) {
$table->id();
$table->uuid('public_id')->nullable()->unique();
$table->enum('state', [EpisodeStateType::DRAFT->value, EpisodeStateType::PUBLISHED->value]);
$table->enum('state', [EpisodeStateType::DRAFT->value, EpisodeStateType::PUBLISHED->value])->default(EpisodeStateType::DRAFT->value);
$table->foreignId('user_id')->nullable()->constrained('users');
$table->smallInteger('intensity', false, true)->nullable();
$table->smallInteger('duration', false, true)->nullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
public function up(): void
{
Schema::create('episodes_episode_types', function (Blueprint $table) {
$table->foreignId('episode_id')->references('id')->on('episodes')->onDelete('cascade');
$table->foreignId('episode_type_id')->references('id')->on('episode_types')->onDelete('cascade');
$table->foreignId('episode_id')->constrained('episodes')->onDelete('cascade');
$table->foreignId('episode_type_id')->constrained('episode_types')->onDelete('cascade');
$table->unique(['episode_id', 'episode_type_id']);
$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
public function up(): void
{
Schema::create('episodes_episode_triggers', function (Blueprint $table) {
$table->foreignId('episode_id')->constrained('episodes');
$table->foreignId('episode_trigger_id')->constrained('episode_triggers');;
$table->foreignId('episode_id')->constrained('episodes')->onDelete('cascade');
$table->foreignId('episode_trigger_id')->constrained('episode_triggers')->onDelete('cascade');
$table->unique(['episode_id', 'episode_trigger_id']);
$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public function up(): void
{
Schema::create('symptom_timings', function (Blueprint $table) {
$table->id();
$table->foreignId('symptom_id')->constrained('episode_symptoms');
$table->foreignId('timing_id')->constrained('timings');
$table->foreignId('symptom_id')->constrained('episode_symptoms')->onDelete('cascade');
$table->foreignId('timing_id')->constrained('timings')->onDelete('cascade');
$table->unique(['symptom_id', 'timing_id']);
$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
public function up(): void
{
Schema::create('episodes_symptom_timings', function (Blueprint $table) {
$table->foreignId('episode_id')->constrained('episodes');
$table->foreignId('symptom_timing_id')->constrained('symptom_timings');
$table->foreignId('episode_id')->constrained('episodes')->onDelete('cascade');
$table->foreignId('symptom_timing_id')->constrained('symptom_timings')->onDelete('cascade');
$table->unique(['episode_id', 'symptom_timing_id'], 'symptom_timing_unique');
$table->timestamps();
});
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/WebsiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function test_homepage_is_rendered_successfully()
$response = $this->get('/');
$response
->assertStatus(200)
->assertSee(' Epilepsie-Tracker');
->assertSee('Epilepsie-Tracker');
}

public function test_episode_can_be_created_through_controller()
Expand Down

0 comments on commit f92adfd

Please sign in to comment.