<?php

use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

test('bookmarklet endpoint returns 200 with text/javascript content type', function () {
    $response = $this->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');
});
