MCPcopy Create free account
hub / github.com/GetStream/stream-go2 / TestBatchUpdateToTargets

Function TestBatchUpdateToTargets

feed_test.go:235–282  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

233}
234
235func TestBatchUpdateToTargets(t *testing.T) {
236 var (
237 client, requester = newClient(t)
238 ctx = context.Background()
239 flat, _ = newFlatFeedWithUserID(client, "123")
240 f1, _ = newFlatFeedWithUserID(client, "f1")
241 f2, _ = newFlatFeedWithUserID(client, "f2")
242 now = getTime(time.Now())
243 )
244
245 reqs := []stream.UpdateToTargetsRequest{
246 {
247 ForeignID: "bob:123",
248 Time: now,
249 Opts: []stream.UpdateToTargetsOption{
250 stream.WithToTargetsAdd(f2.ID()),
251 stream.WithToTargetsRemove(f1.ID()),
252 },
253 },
254 }
255
256 _, err := flat.BatchUpdateToTargets(ctx, reqs)
257 require.NoError(t, err)
258 body := fmt.Sprintf(`[{"foreign_id":"bob:123","time":%q,"added_targets":["flat:f2"],"removed_targets":["flat:f1"]}]`, now.Format(stream.TimeLayout))
259 testRequest(t, requester.req, http.MethodPost, "https://api.stream-io-api.com/api/v1.0/feed_targets/flat/123/activity_to_targets/?api_key=key", body)
260
261 reqs = append(reqs, stream.UpdateToTargetsRequest{
262 ForeignID: "bob:234",
263 Time: now,
264 Opts: []stream.UpdateToTargetsOption{
265 stream.WithToTargetsNew(f1.ID(), f2.ID()),
266 },
267 })
268
269 _, err = flat.BatchUpdateToTargets(ctx, reqs)
270 require.NoError(t, err)
271 body = fmt.Sprintf(`[{"foreign_id":"bob:123","time":%q,"added_targets":["flat:f2"],"removed_targets":["flat:f1"]},{"foreign_id":"bob:234","time":%q,"new_targets":["flat:f1","flat:f2"]}]`, now.Format(stream.TimeLayout), now.Format(stream.TimeLayout))
272 testRequest(t, requester.req, http.MethodPost, "https://api.stream-io-api.com/api/v1.0/feed_targets/flat/123/activity_to_targets/?api_key=key", body)
273
274 reqs = append(reqs, stream.UpdateToTargetsRequest{
275 ForeignID: "bob:345",
276 Time: now,
277 })
278
279 // this should error since we have not specified any changes to the last request
280 _, err = flat.BatchUpdateToTargets(ctx, reqs)
281 require.Error(t, err)
282}
283
284func TestRealtimeToken(t *testing.T) {
285 client, err := stream.New("key", "super secret")

Callers

nothing calls this directly

Calls 7

newClientFunction · 0.85
newFlatFeedWithUserIDFunction · 0.85
getTimeFunction · 0.85
testRequestFunction · 0.85
ErrorMethod · 0.80
IDMethod · 0.65
BatchUpdateToTargetsMethod · 0.65

Tested by

no test coverage detected