|
@@ -4,6 +4,9 @@
|
|
|
package form // import "miniflux.app/v2/internal/ui/form"
|
|
package form // import "miniflux.app/v2/internal/ui/form"
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "net/http/httptest"
|
|
|
|
|
+ "net/url"
|
|
|
|
|
+ "strings"
|
|
|
"testing"
|
|
"testing"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -57,3 +60,30 @@ func TestValidateGoogleReader(t *testing.T) {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func TestNewIntegrationFormLinktacoVisibility(t *testing.T) {
|
|
|
|
|
+ scenarios := []struct {
|
|
|
|
|
+ name string
|
|
|
|
|
+ values url.Values
|
|
|
|
|
+ expected string
|
|
|
|
|
+ }{
|
|
|
|
|
+ {name: "missing field", values: url.Values{}, expected: "PUBLIC"},
|
|
|
|
|
+ {name: "empty value", values: url.Values{"linktaco_visibility": {""}}, expected: "PUBLIC"},
|
|
|
|
|
+ {name: "public", values: url.Values{"linktaco_visibility": {"PUBLIC"}}, expected: "PUBLIC"},
|
|
|
|
|
+ {name: "private", values: url.Values{"linktaco_visibility": {"PRIVATE"}}, expected: "PRIVATE"},
|
|
|
|
|
+ {name: "invalid value", values: url.Values{"linktaco_visibility": {"UNLISTED"}}, expected: "PUBLIC"},
|
|
|
|
|
+ {name: "lowercase value", values: url.Values{"linktaco_visibility": {"private"}}, expected: "PUBLIC"},
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for _, scenario := range scenarios {
|
|
|
|
|
+ t.Run(scenario.name, func(t *testing.T) {
|
|
|
|
|
+ request := httptest.NewRequest("POST", "/integration", strings.NewReader(scenario.values.Encode()))
|
|
|
|
|
+ request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
|
+
|
|
|
|
|
+ integrationForm := NewIntegrationForm(request)
|
|
|
|
|
+ if integrationForm.LinktacoVisibility != scenario.expected {
|
|
|
|
|
+ t.Fatalf("expected visibility %q, got %q", scenario.expected, integrationForm.LinktacoVisibility)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+}
|