package main

import (
	"strings"
	"testing"
)

// The default QSL e-mail closes with a credit line carrying the download page.
//
// It is part of the BODY TEMPLATE, deliberately: an operator who does not want
// it deletes it once, and one who already wrote their own body never sees it,
// because a stored template is returned verbatim and the default is only the
// fallback. Appending it at send time would have made it unremovable.
func TestQSLCreditIsInTheDefaultBody(t *testing.T) {
	if !strings.HasSuffix(defaultQSLEmailBody, qslCredit) {
		t.Errorf("the default QSL e-mail does not end with the credit line:\n%q", defaultQSLEmailBody)
	}
	// The body still has to be a usable template — the credit is added to it,
	// not in place of it.
	for _, v := range []string{"{DATE}", "{BAND}", "{MODE}", "{MYCALL}"} {
		if !strings.Contains(defaultQSLEmailBody, v) {
			t.Errorf("the default QSL e-mail lost %s", v)
		}
	}
}

// The link must be the page a person can read. updateCheckURL sits beside it and
// answers JSON — sending a correspondent there is the easy mistake to make.
func TestQSLCreditLinksTheHumanPage(t *testing.T) {
	if !strings.Contains(qslCredit, releasesPageURL) {
		t.Errorf("credit %q does not carry the releases page", qslCredit)
	}
	if strings.Contains(qslCredit, "api.github.com") {
		t.Errorf("credit %q points at the update API, which answers JSON to whoever clicks it", qslCredit)
	}
	if !strings.Contains(qslCredit, "OpsLog") {
		t.Errorf("credit %q does not name OpsLog", qslCredit)
	}
}
