Skip to content

Commit ea32366

Browse files
committed
fixing app env sync
1 parent 4ad94e2 commit ea32366

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

internal/service/application.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ type BulkUpdateEnvsRequest struct {
184184
}
185185

186186
// BulkUpdateEnvsResponse represents the response from bulk update
187-
type BulkUpdateEnvsResponse struct {
188-
Message string `json:"message"`
189-
}
187+
type BulkUpdateEnvsResponse []models.EnvironmentVariable
190188

191189
// BulkUpdateEnvs updates multiple environment variables in a single request
192190
func (s *ApplicationService) BulkUpdateEnvs(ctx context.Context, appUUID string, req *BulkUpdateEnvsRequest) (*BulkUpdateEnvsResponse, error) {

internal/service/application_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,3 +1194,37 @@ func TestApplicationService_CreateDockerImage(t *testing.T) {
11941194
assert.NotNil(t, result)
11951195
assert.Equal(t, "new-app-uuid", result.UUID)
11961196
}
1197+
1198+
func TestApplicationService_BulkUpdateEnvs(t *testing.T) {
1199+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1200+
assert.Equal(t, "/api/v1/applications/app-uuid-123/envs/bulk", r.URL.Path)
1201+
assert.Equal(t, "PATCH", r.Method)
1202+
assert.Equal(t, "Bearer test-token", r.Header.Get("Authorization"))
1203+
1204+
// Return array response as per API
1205+
w.Header().Set("Content-Type", "application/json")
1206+
resp := []models.EnvironmentVariable{
1207+
{
1208+
Key: "KEY1",
1209+
Value: "VAL1",
1210+
},
1211+
}
1212+
_ = json.NewEncoder(w).Encode(resp)
1213+
}))
1214+
defer server.Close()
1215+
1216+
client := api.NewClient(server.URL, "test-token")
1217+
svc := NewApplicationService(client)
1218+
1219+
req := &BulkUpdateEnvsRequest{
1220+
Data: []models.EnvironmentVariableCreateRequest{
1221+
{Key: "KEY1", Value: "VAL1"},
1222+
},
1223+
}
1224+
1225+
result, err := svc.BulkUpdateEnvs(context.Background(), "app-uuid-123", req)
1226+
require.NoError(t, err)
1227+
assert.NotNil(t, result)
1228+
assert.Len(t, *result, 1)
1229+
assert.Equal(t, "KEY1", (*result)[0].Key)
1230+
}

0 commit comments

Comments
 (0)