Skip to content

Commit 9a64b63

Browse files
committed
fix default sync function dry run
1 parent ee1f2a9 commit 9a64b63

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
@@ -1144,6 +1144,30 @@ func TestSyncFuncDryRun(t *testing.T) {
11441144
expectedOutput: SyncFnDryRun{},
11451145
expectedStatus: http.StatusBadRequest,
11461146
},
1147+
{
1148+
name: "no_custom_sync_func-default_db_sync_func-doc_body-no_existing_doc-no_doc_id",
1149+
document: map[string]any{"channels": "chanNew"},
1150+
existingDoc: false,
1151+
expectedOutput: SyncFnDryRun{
1152+
Channels: base.SetFromArray([]string{"chanNew"}),
1153+
Access: channels.AccessMap{},
1154+
Roles: channels.AccessMap{},
1155+
},
1156+
expectedStatus: http.StatusOK,
1157+
},
1158+
{
1159+
name: "no_custom_sync_func-default_db_sync_func-no_doc_body-existing_doc-doc_id",
1160+
docID: "doc22",
1161+
existingDoc: true,
1162+
existingDocID: "doc22",
1163+
existingDocBody: `{"channels": "chanNew"}`,
1164+
expectedOutput: SyncFnDryRun{
1165+
Channels: base.SetFromArray([]string{"chanNew"}),
1166+
Access: channels.AccessMap{},
1167+
Roles: channels.AccessMap{},
1168+
},
1169+
expectedStatus: http.StatusOK,
1170+
},
11471171
}
11481172

11491173
for _, test := range tests {

0 commit comments

Comments
 (0)