Skip to content

Commit feace27

Browse files
committed
use GetDefaultSyncFunction in syncFuncDryRun
1 parent 52ec132 commit feace27

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

db/crud.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,8 @@ func (db *DatabaseCollectionWithUser) SyncFnDryrun(ctx context.Context, newDoc,
17181718
}
17191719
} else {
17201720
if syncFn == "" {
1721-
syncFn = channels.DocChannelsSyncFunction
1721+
scopeAndCollectionName := db.ScopeAndCollectionName()
1722+
syncFn = channels.GetDefaultSyncFunction(scopeAndCollectionName.Scope, scopeAndCollectionName.Collection)
17221723
}
17231724
jsTimeout := time.Duration(base.DefaultJavascriptTimeoutSecs) * time.Second
17241725
syncRunner, err := channels.NewSyncRunner(ctx, syncFn, jsTimeout)

rest/diagnostic_doc_api_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,12 +1214,16 @@ func TestSyncFuncDryRun(t *testing.T) {
12141214
expectedOutput: SyncFnDryRun{},
12151215
expectedStatus: http.StatusBadRequest,
12161216
},
1217+
// Since the tests run in named Scopes and Collections therefore the
1218+
// default sync function is:
1219+
// function(doc){channel("<collection_name>");}
1220+
// therefore the channels returned will be named collections
12171221
{
12181222
name: "no_custom_sync_func-default_db_sync_func-doc_body-no_existing_doc-no_doc_id",
12191223
document: map[string]any{"channels": "chanNew"},
12201224
existingDoc: false,
12211225
expectedOutput: SyncFnDryRun{
1222-
Channels: base.SetFromArray([]string{"chanNew"}),
1226+
Channels: base.SetFromArray([]string{"sg_test_0"}),
12231227
Access: channels.AccessMap{},
12241228
Roles: channels.AccessMap{},
12251229
},
@@ -1232,7 +1236,7 @@ func TestSyncFuncDryRun(t *testing.T) {
12321236
existingDocID: "doc22",
12331237
existingDocBody: `{"channels": "chanNew"}`,
12341238
expectedOutput: SyncFnDryRun{
1235-
Channels: base.SetFromArray([]string{"chanNew"}),
1239+
Channels: base.SetFromArray([]string{"sg_test_0"}),
12361240
Access: channels.AccessMap{},
12371241
Roles: channels.AccessMap{},
12381242
},

0 commit comments

Comments
 (0)