Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions controller/channel_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ func TestUpdateChannelPartialStatusDoesNotClearConfiguration(t *testing.T) {
require.Equal(t, "https://origin.example.com", *stored.BaseURL)
}

func TestUpdateChannelPersistsOpenAIOrganization(t *testing.T) {
db, channel := setupChannelUpdateControllerTestDB(t)

organization := "org-controller-update"
ctx, recorder := newAuthenticatedContext(t, http.MethodPut, "/api/channel/", map[string]any{
"id": channel.Id,
"openai_organization": organization,
}, 1)
UpdateChannel(ctx)
response := decodeAPIResponse(t, recorder)
require.True(t, response.Success, response.Message)

var stored model.Channel
require.NoError(t, db.First(&stored, channel.Id).Error)
require.NotNil(t, stored.OpenAIOrganization)
require.Equal(t, organization, *stored.OpenAIOrganization)
}

func TestUpdateChannelRejectsUnknownStatus(t *testing.T) {
db, channel := setupChannelUpdateControllerTestDB(t)

Expand Down
2 changes: 1 addition & 1 deletion model/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ func (channel *Channel) editableUpdateMap(fields []string) map[string]any {
updates["key"] = channel.Key
case "openai_organization":
if channel.OpenAIOrganization != nil {
updates["openai_organization"] = channel.OpenAIOrganization
updates["open_ai_organization"] = channel.OpenAIOrganization
}
case "test_model":
if channel.TestModel != nil {
Expand Down
14 changes: 14 additions & 0 deletions model/channel_update_fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ func TestUpdateFieldsSkipsAbilityRebuildForChannelInfoOnly(t *testing.T) {
require.EqualValues(t, 1, abilityCount)
}

func TestUpdateFieldsPersistsOpenAIOrganizationUsingSchemaColumn(t *testing.T) {
db, channel := setupChannelUpdateFieldsTestDB(t)

organization := "org-update-fields"
channel.OpenAIOrganization = &organization

require.NoError(t, channel.UpdateFields("openai_organization"))

var stored Channel
require.NoError(t, db.First(&stored, channel.Id).Error)
require.NotNil(t, stored.OpenAIOrganization)
require.Equal(t, organization, *stored.OpenAIOrganization)
}

func TestUpdateFieldsRollsBackChannelWhenAbilityRebuildFails(t *testing.T) {
db, channel := setupChannelUpdateFieldsTestDB(t)
installFailingAbilityDeleteTrigger(t, db)
Expand Down
Loading