Test the userCtx.channels parameter with a list
(t *testing.T)
| 389 | |
| 390 | // Test the userCtx.channels parameter with a list |
| 391 | func TestCheckAccessArray(t *testing.T) { |
| 392 | ctx := base.TestCtx(t) |
| 393 | mapper := NewChannelMapper(ctx, `function(doc, oldDoc) { |
| 394 | requireAccess(doc.channels) |
| 395 | }`, 0) |
| 396 | var sally = map[string]interface{}{"name": "sally", "roles": []string{"girl", "5yo"}, "channels": []string{"party", "school"}} |
| 397 | res, err := mapper.MapToChannelsAndAccess(ctx, parse(t, `{"channels": ["swim","party"]}`), `{}`, emptyMetaMap(), sally) |
| 398 | assert.NoError(t, err, "MapToChannelsAndAccess failed") |
| 399 | assert.Equal(t, nil, res.Rejection) |
| 400 | |
| 401 | var linus = map[string]interface{}{"name": "linus", "roles": []string{"boy", "musician"}, "channels": []string{"party", "school"}} |
| 402 | res, err = mapper.MapToChannelsAndAccess(ctx, parse(t, `{"channels": ["work"]}`), `{}`, emptyMetaMap(), linus) |
| 403 | assert.NoError(t, err, "MapToChannelsAndAccess failed") |
| 404 | assert.Equal(t, base.HTTPErrorf(403, base.SyncFnErrorMissingChannelAccess), res.Rejection) |
| 405 | |
| 406 | res, err = mapper.MapToChannelsAndAccess(ctx, parse(t, `{"channels": ["magic"]}`), `{}`, emptyMetaMap(), nil) |
| 407 | assert.NoError(t, err, "MapToChannelsAndAccess failed") |
| 408 | assert.Equal(t, nil, res.Rejection) |
| 409 | } |
| 410 | |
| 411 | // Test changing the function |
| 412 | func TestSetFunction(t *testing.T) { |
nothing calls this directly
no test coverage detected