From 600dea6ce54989a792e666a0a26de0ee847e4562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sat, 5 Oct 2024 18:06:14 -0700 Subject: [PATCH] feat(client): add `custom_js` field to Go API client --- client/model.go | 2 ++ internal/api/api_integration_test.go | 29 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/client/model.go b/client/model.go index 69f2c227..f0583ae4 100644 --- a/client/model.go +++ b/client/model.go @@ -27,6 +27,7 @@ type User struct { EntryDirection string `json:"entry_sorting_direction"` EntryOrder string `json:"entry_sorting_order"` Stylesheet string `json:"stylesheet"` + CustomJS string `json:"custom_js"` GoogleID string `json:"google_id"` OpenIDConnectID string `json:"openid_connect_id"` EntriesPerPage int `json:"entries_per_page"` @@ -70,6 +71,7 @@ type UserModificationRequest struct { EntryDirection *string `json:"entry_sorting_direction"` EntryOrder *string `json:"entry_sorting_order"` Stylesheet *string `json:"stylesheet"` + CustomJS *string `json:"custom_js"` GoogleID *string `json:"google_id"` OpenIDConnectID *string `json:"openid_connect_id"` EntriesPerPage *int `json:"entries_per_page"` diff --git a/internal/api/api_integration_test.go b/internal/api/api_integration_test.go index 1d06fb8c..1a95cf08 100644 --- a/internal/api/api_integration_test.go +++ b/internal/api/api_integration_test.go @@ -592,6 +592,35 @@ func TestUpdateUserEndpointByChangingDefaultTheme(t *testing.T) { } } +func TestUpdateUserEndpointByChangingCustomJS(t *testing.T) { + testConfig := newIntegrationTestConfig() + if !testConfig.isConfigured() { + t.Skip(skipIntegrationTestsMessage) + } + + adminClient := miniflux.NewClient(testConfig.testBaseURL, testConfig.testAdminUsername, testConfig.testAdminPassword) + regularTestUser, err := adminClient.CreateUser(testConfig.genRandomUsername(), testConfig.testRegularPassword, false) + if err != nil { + t.Fatal(err) + } + defer adminClient.DeleteUser(regularTestUser.ID) + + regularUserClient := miniflux.NewClient(testConfig.testBaseURL, regularTestUser.Username, testConfig.testRegularPassword) + + userUpdateRequest := &miniflux.UserModificationRequest{ + CustomJS: miniflux.SetOptionalField("alert('Hello, World!');"), + } + + updatedUser, err := regularUserClient.UpdateUser(regularTestUser.ID, userUpdateRequest) + if err != nil { + t.Fatal(err) + } + + if updatedUser.CustomJS != "alert('Hello, World!');" { + t.Fatalf(`Invalid custom JS, got %q`, updatedUser.CustomJS) + } +} + func TestUpdateUserEndpointByChangingDefaultThemeToInvalidValue(t *testing.T) { testConfig := newIntegrationTestConfig() if !testConfig.isConfigured() {