Skip to content

Commit

Permalink
make blade default, fix controller
Browse files Browse the repository at this point in the history
  • Loading branch information
axyr committed Jul 1, 2024
1 parent c1d560c commit aa2aa7a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Laravel Email Viewer

[![Latest Version on Packagist](https://img.shields.io/packagist/v/axyr/laravel-email-viewer.svg?style=flat-square)](https://packagist.org/packages/axyr/laravel-email-viewer)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/spatie/laravel-permission/run-tests-L8.yml?branch=main&label=Tests)](https://github.com/axyr/laravel-email-viewer/actions?query=workflow%3ATests+branch%3Amain)

## Introduction
Expand Down
11 changes: 8 additions & 3 deletions routes/emailviewer.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?php

use Axyr\EmailViewer\Http\Controllers\BladeEmailController;
use Axyr\EmailViewer\Http\Controllers\JsonEmailController;
use Illuminate\Support\Facades\Route;

$routeNamespace = config('emailviewer.route-namespace');

Route::get($routeNamespace, [JsonEmailController::class, 'index'])->name($routeNamespace . '.index');
Route::get($routeNamespace . '/{id}', [JsonEmailController::class, 'show'])->name($routeNamespace . '.show');
Route::delete($routeNamespace . '/{id}', [JsonEmailController::class, 'destroy'])->name($routeNamespace . '.destroy');
Route::get($routeNamespace . '/json', [JsonEmailController::class, 'index'])->name($routeNamespace . '.json.index');
Route::get($routeNamespace . '/{id}/json', [JsonEmailController::class, 'show'])->name($routeNamespace . '.json.show');
Route::delete($routeNamespace . '/{id}/json', [JsonEmailController::class, 'destroy'])->name($routeNamespace . '.json.destroy');

Route::get($routeNamespace, [BladeEmailController::class, 'index'])->name($routeNamespace . '.index');
Route::get($routeNamespace . '/{id}', [BladeEmailController::class, 'show'])->name($routeNamespace . '.show');
Route::delete($routeNamespace . '/{id}', [BladeEmailController::class, 'destroy'])->name($routeNamespace . '.destroy');
2 changes: 1 addition & 1 deletion src/Http/Controllers/BladeEmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function show(string|int $id): View
return view('email-viewer::show', compact('emails', 'email'));
}

public function destroy(tring|int $id): RedirectResponse
public function destroy(string|int $id): RedirectResponse
{
Emails::delete($id);

Expand Down
7 changes: 4 additions & 3 deletions tests/Http/Controllers/JsonEmailControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ class JsonEmailControllerTest extends TestCase
public function testListsPaginatedEmails(): void
{
config()->set('emailviewer.default_pagination', 3);

$routeNamespace = config('emailviewer.route-namespace');

for ($i = 0; $i < 6; $i++) {
app(Repository::class)->create($this->emailContent . $i);
}

$response = $this->getJson(route($routeNamespace . '.index'));
$response = $this->getJson(route($routeNamespace . '.json.index'));

$this->assertCount(3, $response->json('data'));

Expand All @@ -44,7 +45,7 @@ public function testShowsAnEmail(): void

$email = app(Repository::class)->create($this->emailContent);

$response = $this->getJson(route($routeNamespace . '.show', [$email->id()]));
$response = $this->getJson(route($routeNamespace . '.json.show', [$email->id()]));

$this->assertEquals($this->resourceKeys, array_keys($response->json('data')));
}
Expand All @@ -55,7 +56,7 @@ public function testDeletesAnEmail(): void

$email = app(Repository::class)->create($this->emailContent);

$response = $this->deleteJson(route($routeNamespace . '.destroy', [$email->id()]));
$response = $this->deleteJson(route($routeNamespace . '.json.destroy', [$email->id()]));

$response->assertStatus(204);

Expand Down

0 comments on commit aa2aa7a

Please sign in to comment.