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

Function TestUpdateToTargets

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

Source from the content-addressed store, hash-verified

208}
209
210func TestUpdateToTargets(t *testing.T) {
211 var (
212 client, requester = newClient(t)
213 ctx = context.Background()
214 flat, _ = newFlatFeedWithUserID(client, "123")
215 f1, _ = newFlatFeedWithUserID(client, "f1")
216 f2, _ = newFlatFeedWithUserID(client, "f2")
217 f3, _ = newFlatFeedWithUserID(client, "f3")
218 now = getTime(time.Now())
219 activity = stream.Activity{Time: now, ForeignID: "bob:123", Actor: "bob", Verb: "like", Object: "ice-cream", To: []string{f1.ID()}, Extra: map[string]any{"popularity": 9000}}
220 )
221 _, err := flat.UpdateToTargets(ctx, activity, stream.WithToTargetsAdd(f2.ID()), stream.WithToTargetsRemove(f1.ID()))
222 require.NoError(t, err)
223 body := fmt.Sprintf(`{"foreign_id":"bob:123","time":%q,"added_targets":["flat:f2"],"removed_targets":["flat:f1"]}`, now.Format(stream.TimeLayout))
224 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)
225 _, err = flat.UpdateToTargets(ctx, activity, stream.WithToTargetsNew(f3.ID()))
226 require.NoError(t, err)
227 body = fmt.Sprintf(`{"foreign_id":"bob:123","time":%q,"new_targets":["flat:f3"]}`, now.Format(stream.TimeLayout))
228 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)
229
230 // should error since we have not specified any changes
231 _, err = flat.UpdateToTargets(ctx, activity)
232 require.Error(t, err)
233}
234
235func TestBatchUpdateToTargets(t *testing.T) {
236 var (

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
UpdateToTargetsMethod · 0.65

Tested by

no test coverage detected