2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-08-25 20:53:14 +02:00
|
|
|
|
2022-08-09 06:33:38 +02:00
|
|
|
//go:build integration
|
2021-03-23 05:04:10 +01:00
|
|
|
// +build integration
|
|
|
|
|
2018-08-25 20:53:14 +02:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2023-08-10 06:15:55 +02:00
|
|
|
miniflux "miniflux.app/v2/client"
|
2018-08-25 20:53:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-11-18 07:53:11 +01:00
|
|
|
testBaseURL = "http://127.0.0.1:8080/"
|
|
|
|
testAdminUsername = "admin"
|
|
|
|
testAdminPassword = "test123"
|
|
|
|
testStandardPassword = "secret"
|
|
|
|
testFeedURL = "https://miniflux.app/feed.xml"
|
|
|
|
testFeedTitle = "Miniflux"
|
|
|
|
testSubscriptionTitle = "Miniflux Releases"
|
2022-11-13 05:59:06 +01:00
|
|
|
testWebsiteURL = "https://miniflux.app"
|
2018-08-25 20:53:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func getRandomUsername() string {
|
|
|
|
var suffix []string
|
2024-02-29 01:01:20 +01:00
|
|
|
for range 10 {
|
2018-08-25 20:53:14 +02:00
|
|
|
suffix = append(suffix, strconv.Itoa(rand.Intn(1000)))
|
|
|
|
}
|
|
|
|
return "user" + strings.Join(suffix, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func createClient(t *testing.T) *miniflux.Client {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
_, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return miniflux.New(testBaseURL, username, testStandardPassword)
|
|
|
|
}
|
|
|
|
|
|
|
|
func createFeed(t *testing.T, client *miniflux.Client) (*miniflux.Feed, *miniflux.Category) {
|
|
|
|
categories, err := client.Categories()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-01-03 01:33:41 +01:00
|
|
|
feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
|
|
|
|
FeedURL: testFeedURL,
|
|
|
|
CategoryID: categories[0].ID,
|
|
|
|
})
|
2018-08-25 20:53:14 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if feedID == 0 {
|
|
|
|
t.Fatalf(`Invalid feed ID, got %q`, feedID)
|
|
|
|
}
|
|
|
|
|
|
|
|
feed, err := client.Feed(feedID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return feed, categories[0]
|
|
|
|
}
|