Parcourir la source

feat(client): add `custom_js` field to Go API client

Frédéric Guillot il y a 1 an
Parent
commit
600dea6ce5
2 fichiers modifiés avec 31 ajouts et 0 suppressions
  1. 2 0
      client/model.go
  2. 29 0
      internal/api/api_integration_test.go

+ 2 - 0
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"`

+ 29 - 0
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() {