diff --git a/app/Http/Controllers/BookmarkletController.php b/app/Http/Controllers/BookmarkletController.php new file mode 100644 index 0000000..7349829 --- /dev/null +++ b/app/Http/Controllers/BookmarkletController.php @@ -0,0 +1,47 @@ + 'text/javascript; charset=utf-8', + 'Cache-Control' => 'public, max-age=3600', + ]); + } +} diff --git a/routes/web.php b/routes/web.php index 2835bf7..3a8b2d4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use App\Http\Controllers\ApiLogController; use App\Http\Controllers\AuthController; +use App\Http\Controllers\BookmarkletController; use App\Http\Controllers\LabelImportController; use App\Http\Controllers\MacroAssignmentController; use App\Http\Controllers\MacroImportController; @@ -46,6 +47,8 @@ ->middleware('auth') ->name('logout'); +Route::get('/bookmarklets/ccli-import.js', [BookmarkletController::class, 'show'])->name('bookmarklets.ccli'); + Route::middleware('auth')->group(function () { Route::get('/', function () { return redirect()->route('dashboard'); diff --git a/tests/Feature/BookmarkletControllerTest.php b/tests/Feature/BookmarkletControllerTest.php new file mode 100644 index 0000000..aa53db2 --- /dev/null +++ b/tests/Feature/BookmarkletControllerTest.php @@ -0,0 +1,41 @@ +get('/bookmarklets/ccli-import.js'); + + $response->assertStatus(200); + $response->assertHeader('Content-Type', 'text/javascript; charset=utf-8'); +}); + +test('bookmarklet response starts with javascript: prefix', function () { + $response = $this->get('/bookmarklets/ccli-import.js'); + + expect($response->getContent())->toStartWith('javascript:'); +}); + +test('bookmarklet response is a single line with no actual newlines', function () { + $response = $this->get('/bookmarklets/ccli-import.js'); + $content = $response->getContent(); + + expect(substr_count($content, "\n"))->toBe(0); +}); + +test('bookmarklet response contains app URL and import path', function () { + $response = $this->get('/bookmarklets/ccli-import.js'); + $content = $response->getContent(); + + expect($content)->toContain('import-from-ccli-paste'); + expect($content)->toContain('songselect.ccli.com'); + expect($content)->toContain('btoa'); +}); + +test('bookmarklet endpoint does not require authentication', function () { + $response = $this->get('/bookmarklets/ccli-import.js'); + + $response->assertStatus(200); + $response->assertHeader('Content-Type', 'text/javascript; charset=utf-8'); +});