Files
nostrlib/nip11/nip11_test.go
2026-02-09 14:40:37 -08:00

68 lines
2.1 KiB
Go

package nip11
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAddSupportedNIP(t *testing.T) {
info := RelayInformationDocument{}
info.AddSupportedNIP("12")
info.AddSupportedNIP("12")
info.AddSupportedNIP("13")
info.AddSupportedNIP("1")
info.AddSupportedNIP("12")
info.AddSupportedNIP("44")
info.AddSupportedNIP("2")
info.AddSupportedNIP("13")
info.AddSupportedNIP("2")
info.AddSupportedNIP("13")
info.AddSupportedNIP("0")
info.AddSupportedNIP("17")
info.AddSupportedNIP("19")
info.AddSupportedNIP("1")
info.AddSupportedNIP("18")
assert.Contains(t, info.SupportedNIPs, "0", "1", "2", "12", "13", "17", "18", "19", "44")
}
func TestAddSupportedNIPs(t *testing.T) {
info := RelayInformationDocument{}
info.AddSupportedNIPs([]int{"0", "1", "2", "12", "13", "17", "18", "19", "44"})
assert.Contains(t, info.SupportedNIPs, "0", "1", "2", "12", "13", "17", "18", "19", "44")
}
func TestFetch(t *testing.T) {
tests := []struct {
inputURL string
expectError bool
expectedName string
expectedURL string
}{
{"wss://nostr.wine", false, "", "wss://nostr.wine"},
{"https://nostr.wine", false, "", "wss://nostr.wine"},
{"nostr.wine", false, "", "wss://nostr.wine"},
{"relay.damus.io", false, "", "wss://relay.damus.io"},
{"https://relay.damus.io", false, "", "wss://relay.damus.io"},
{"wss://relay.damus.io", false, "", "wss://relay.damus.io"},
{"wlenwqkeqwe.asjdaskd", true, "", "wss://wlenwqkeqwe.asjdaskd"},
}
for _, test := range tests {
res, err := Fetch(context.Background(), test.inputURL)
if test.expectError {
assert.Error(t, err, "expected error for URL: %s", test.inputURL)
assert.NotNil(t, res, "expected result not to be nil for URL: %s", test.inputURL)
assert.Equal(t, test.expectedURL, res.URL, "expected URL to be %s for input: %s", test.expectedURL, test.inputURL)
} else {
assert.Nil(t, err, "unexpect error for URL: %s", test.inputURL)
assert.NotEmpty(t, res.Name, "expected non-empty name for URL: %s", test.inputURL)
assert.Equal(t, test.expectedURL, res.URL, "expected URL to be %s for input: %s", test.expectedURL, test.inputURL)
}
}
}