Skip to content

Commit 52ec132

Browse files
committed
fix default sync function dry run
1 parent 90198ba commit 52ec132

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

db/crud.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,12 +1711,15 @@ func (db *DatabaseCollectionWithUser) SyncFnDryrun(ctx context.Context, newDoc,
17111711
}
17121712
var output *channels.ChannelMapperOutput
17131713
var syncErr error
1714-
if syncFn == "" {
1714+
if syncFn == "" && db.ChannelMapper != nil {
17151715
output, err = db.ChannelMapper.MapToChannelsAndAccess(ctx, mutableBody, string(oldDoc._rawBody), metaMap, syncOptions)
17161716
if err != nil {
17171717
return nil, &base.SyncFnDryRunError{Err: err}
17181718
}
17191719
} else {
1720+
if syncFn == "" {
1721+
syncFn = channels.DocChannelsSyncFunction
1722+
}
17201723
jsTimeout := time.Duration(base.DefaultJavascriptTimeoutSecs) * time.Second
17211724
syncRunner, err := channels.NewSyncRunner(ctx, syncFn, jsTimeout)
17221725
if err != nil {

rest/diagnostic_doc_api_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,30 @@ func TestSyncFuncDryRun(t *testing.T) {
12141214
expectedOutput: SyncFnDryRun{},
12151215
expectedStatus: http.StatusBadRequest,
12161216
},
1217+
{
1218+
name: "no_custom_sync_func-default_db_sync_func-doc_body-no_existing_doc-no_doc_id",
1219+
document: map[string]any{"channels": "chanNew"},
1220+
existingDoc: false,
1221+
expectedOutput: SyncFnDryRun{
1222+
Channels: base.SetFromArray([]string{"chanNew"}),
1223+
Access: channels.AccessMap{},
1224+
Roles: channels.AccessMap{},
1225+
},
1226+
expectedStatus: http.StatusOK,
1227+
},
1228+
{
1229+
name: "no_custom_sync_func-default_db_sync_func-no_doc_body-existing_doc-doc_id",
1230+
docID: "doc22",
1231+
existingDoc: true,
1232+
existingDocID: "doc22",
1233+
existingDocBody: `{"channels": "chanNew"}`,
1234+
expectedOutput: SyncFnDryRun{
1235+
Channels: base.SetFromArray([]string{"chanNew"}),
1236+
Access: channels.AccessMap{},
1237+
Roles: channels.AccessMap{},
1238+
},
1239+
expectedStatus: http.StatusOK,
1240+
},
12171241
}
12181242

12191243
for _, test := range tests {

0 commit comments

Comments
 (0)