aboutsummaryrefslogtreecommitdiff
path: root/internal/tests/tests.go
blob: 817aab61df1e112d78d7aaf531cd661d17026537 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//go:build integration
// +build integration

package tests

import (
	"math/rand"
	"strconv"
	"strings"
	"testing"

	miniflux "miniflux.app/v2/client"
)

const (
	testBaseURL           = "http://127.0.0.1:8080/"
	testAdminUsername     = "admin"
	testAdminPassword     = "test123"
	testStandardPassword  = "secret"
	testFeedURL           = "https://miniflux.app/feed.xml"
	testFeedTitle         = "Miniflux"
	testSubscriptionTitle = "Miniflux Releases"
	testWebsiteURL        = "https://miniflux.app"
)

func getRandomUsername() string {
	var suffix []string
	for i := 0; i < 10; i++ {
		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)
	}

	feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
		FeedURL:    testFeedURL,
		CategoryID: categories[0].ID,
	})
	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]
}