(t *testing.T)
| 208 | } |
| 209 | |
| 210 | func 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 | |
| 235 | func TestBatchUpdateToTargets(t *testing.T) { |
| 236 | var ( |
nothing calls this directly
no test coverage detected