Test removal handling for unavailable multi-channel revisions.
(t *testing.T)
| 932 | |
| 933 | // Test removal handling for unavailable multi-channel revisions. |
| 934 | func TestGetRemovalMultiChannel(t *testing.T) { |
| 935 | db, ctx := setupTestDB(t) |
| 936 | defer db.Close(ctx) |
| 937 | |
| 938 | auth := db.Authenticator(ctx) |
| 939 | |
| 940 | // Create a user who have access to both channel ABC and NBC. |
| 941 | userAlice, err := auth.NewUser("alice", "pass", base.SetOf("ABC", "NBC")) |
| 942 | require.NoError(t, err, "Error creating user") |
| 943 | |
| 944 | // Create a user who have access to channel NBC. |
| 945 | userBob, err := auth.NewUser("bob", "pass", base.SetOf("NBC")) |
| 946 | require.NoError(t, err, "Error creating user") |
| 947 | |
| 948 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 949 | collection.ChannelMapper = channels.NewChannelMapper(ctx, channels.DocChannelsSyncFunction, db.Options.JavascriptTimeout) |
| 950 | |
| 951 | // Create the first revision of doc1. |
| 952 | rev1Body := Body{ |
| 953 | "k1": "v1", |
| 954 | "channels": []string{"ABC", "NBC"}, |
| 955 | } |
| 956 | rev1ID, _, err := collection.Put(ctx, "doc1", rev1Body) |
| 957 | require.NoError(t, err, "Error creating doc") |
| 958 | |
| 959 | // Create the second revision of doc1 on channel ABC as removal from channel NBC. |
| 960 | rev2Body := Body{ |
| 961 | "k2": "v2", |
| 962 | "channels": []string{"ABC"}, |
| 963 | BodyRev: rev1ID, |
| 964 | } |
| 965 | rev2ID, _, err := collection.Put(ctx, "doc1", rev2Body) |
| 966 | require.NoError(t, err, "Error creating doc") |
| 967 | |
| 968 | // Create the third revision of doc1 on channel ABC. |
| 969 | rev3Body := Body{ |
| 970 | "k3": "v3", |
| 971 | "channels": []string{"ABC"}, |
| 972 | BodyRev: rev2ID, |
| 973 | } |
| 974 | rev3ID, _, err := collection.Put(ctx, "doc1", rev3Body) |
| 975 | require.NoError(t, err, "Error creating doc") |
| 976 | require.NotEmpty(t, rev3ID, "Error creating doc") |
| 977 | |
| 978 | // Get rev2 of the doc as a user who have access to this revision. |
| 979 | collection.user = userAlice |
| 980 | body, err := collection.Get1xRevBody(ctx, "doc1", rev2ID, true, nil) |
| 981 | require.NoError(t, err, "Error getting 1x rev body") |
| 982 | |
| 983 | _, rev1Digest := ParseRevID(ctx, rev1ID) |
| 984 | _, rev2Digest := ParseRevID(ctx, rev2ID) |
| 985 | |
| 986 | var interfaceListChannels []interface{} |
| 987 | interfaceListChannels = append(interfaceListChannels, "ABC") |
| 988 | bodyExpected := Body{ |
| 989 | "k2": "v2", |
| 990 | "channels": interfaceListChannels, |
| 991 | BodyRevisions: Revisions{ |
nothing calls this directly
no test coverage detected