mirror of
https://github.com/sartoopjj/thefeed.git
synced 2026-05-19 06:14:35 +03:00
feat: Implement version tracking, fix telegram fetcher, hourly report, fix add channel bug
This commit is contained in:
@@ -3,11 +3,13 @@ package e2e_test
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/sartoopjj/thefeed/internal/protocol"
|
||||
"github.com/sartoopjj/thefeed/internal/web"
|
||||
)
|
||||
|
||||
@@ -112,3 +114,92 @@ func TestE2E_Settings_MethodNotAllowed(t *testing.T) {
|
||||
t.Errorf("expected 405, got %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestE2E_VersionCheck_NoConfig(t *testing.T) {
|
||||
base, _ := startWebServer(t)
|
||||
|
||||
resp := postJSON(t, base+"/api/version-check", `{}`)
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 400 {
|
||||
t.Fatalf("POST /api/version-check: expected 400, got %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestE2E_VersionCheck_MethodNotAllowed(t *testing.T) {
|
||||
base, _ := startWebServer(t)
|
||||
|
||||
req, _ := http.NewRequest(http.MethodGet, base+"/api/version-check", nil)
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("GET /api/version-check: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 405 {
|
||||
t.Fatalf("GET /api/version-check: expected 405, got %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestE2E_VersionCheck_Success(t *testing.T) {
|
||||
domain := "test.example.com"
|
||||
passphrase := "testpass"
|
||||
resolver, feed, cancel := startDNSServerEx(t, domain, passphrase, false, []string{"news"}, map[int][]protocol.Message{})
|
||||
defer cancel()
|
||||
feed.SetLatestVersion("v9.9.9")
|
||||
|
||||
dataDir := t.TempDir()
|
||||
port := findFreePort(t, "tcp")
|
||||
srv, err := web.New(dataDir, port, "")
|
||||
if err != nil {
|
||||
t.Fatalf("create web server: %v", err)
|
||||
}
|
||||
go srv.Run()
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
base := fmt.Sprintf("http://127.0.0.1:%d", port)
|
||||
cfg := fmt.Sprintf(`{"domain":%q,"key":%q,"resolvers":[%q],"queryMode":"single","rateLimit":10}`, domain, passphrase, resolver)
|
||||
resp := postJSON(t, base+"/api/config", cfg)
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
t.Fatalf("POST /api/config status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
resp2 := postJSON(t, base+"/api/version-check", `{}`)
|
||||
defer resp2.Body.Close()
|
||||
if resp2.StatusCode != 200 {
|
||||
body, _ := io.ReadAll(resp2.Body)
|
||||
t.Fatalf("POST /api/version-check status=%d body=%s", resp2.StatusCode, body)
|
||||
}
|
||||
m := decodeJSON(t, resp2)
|
||||
if m["latestVersion"] != "v9.9.9" {
|
||||
t.Fatalf("latestVersion = %v, want v9.9.9", m["latestVersion"])
|
||||
}
|
||||
|
||||
resp3 := getJSON(t, base+"/api/status")
|
||||
defer resp3.Body.Close()
|
||||
status := decodeJSON(t, resp3)
|
||||
if status["latestVersion"] != "v9.9.9" {
|
||||
t.Fatalf("status latestVersion = %v, want v9.9.9", status["latestVersion"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestE2E_SettingsPage_HasVersionControls(t *testing.T) {
|
||||
base, _ := startWebServer(t)
|
||||
|
||||
resp, err := http.Get(base + "/")
|
||||
if err != nil {
|
||||
t.Fatalf("GET /: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("read body: %v", err)
|
||||
}
|
||||
html := string(body)
|
||||
if !strings.Contains(html, `id="latestVersionEl"`) {
|
||||
t.Fatalf("settings page missing latestVersionEl")
|
||||
}
|
||||
if !strings.Contains(html, `id="checkVersionBtn"`) {
|
||||
t.Fatalf("settings page missing checkVersionBtn")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user