(t *testing.T)
| 233 | } |
| 234 | |
| 235 | func 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 | |
| 284 | func TestRealtimeToken(t *testing.T) { |
| 285 | client, err := stream.New("key", "super secret") |
nothing calls this directly
no test coverage detected