(t *testing.T)
| 2402 | } |
| 2403 | |
| 2404 | func TestSyncFnOnPush(t *testing.T) { |
| 2405 | |
| 2406 | db, ctx := setupTestDB(t) |
| 2407 | defer db.Close(ctx) |
| 2408 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 2409 | |
| 2410 | _, err := collection.UpdateSyncFun(ctx, `function(doc, oldDoc) { |
| 2411 | log("doc _id = "+doc._id+", _rev = "+doc._rev); |
| 2412 | if (oldDoc) |
| 2413 | log("oldDoc _id = "+oldDoc._id+", _rev = "+oldDoc._rev); |
| 2414 | channel(doc.channels); |
| 2415 | }`) |
| 2416 | require.NoError(t, err) |
| 2417 | |
| 2418 | // Create first revision: |
| 2419 | body := Body{"key1": "value1", "key2": 1234, "channels": []string{"public"}} |
| 2420 | rev1id, _, err := collection.Put(ctx, "doc1", body) |
| 2421 | assert.NoError(t, err, "Couldn't create document") |
| 2422 | |
| 2423 | // Add several revisions at once to a doc, as on a push: |
| 2424 | log.Printf("Check PutExistingRev...") |
| 2425 | body[BodyRev] = "4-four" |
| 2426 | body["key1"] = "fourth value" |
| 2427 | body["key2"] = int64(4444) |
| 2428 | body["channels"] = "clibup" |
| 2429 | history := []string{"4-four", "3-three", "2-488724414d0ed6b398d6d2aeb228d797", |
| 2430 | rev1id} |
| 2431 | newDoc, _, err := collection.PutExistingRevWithBody(ctx, "doc1", body, history, false, ExistingVersionWithUpdateToHLV) |
| 2432 | assert.NoError(t, err, "PutExistingRev failed") |
| 2433 | |
| 2434 | // Check that the doc has the correct channel (test for issue #300) |
| 2435 | doc, err := collection.GetDocument(ctx, "doc1", DocUnmarshalAll) |
| 2436 | require.NoError(t, err) |
| 2437 | assert.Equal(t, channels.ChannelMap{ |
| 2438 | "clibup": nil, |
| 2439 | "public": &channels.ChannelRemoval{Seq: 2, Rev: channels.RevAndVersion{RevTreeID: "4-four", CurrentSource: newDoc.HLV.SourceID, CurrentVersion: base.CasToString(newDoc.HLV.Version)}}, |
| 2440 | }, doc.Channels) |
| 2441 | |
| 2442 | // We no longer store channels for the winning revision in the RevTree, |
| 2443 | // so don't expect it to be in doc.History like it used to be... |
| 2444 | // The above assertion ensured the doc was *actually* in the correct channel. |
| 2445 | assert.Nil(t, doc.History["4-four"].Channels) |
| 2446 | } |
| 2447 | |
| 2448 | func TestInvalidChannel(t *testing.T) { |
| 2449 |
nothing calls this directly
no test coverage detected