MCPcopy Create free account
hub / github.com/daodst/chat / testSendToDevice

Function testSendToDevice

syncapi/syncapi_test.go:321–448  ·  view source on GitHub ↗
(t *testing.T, dbType test.DBType)

Source from the content-addressed store, hash-verified

319}
320
321func testSendToDevice(t *testing.T, dbType test.DBType) {
322 user := test.NewUser(t)
323 alice := userapi.Device{
324 ID: "ALICEID",
325 UserID: user.ID,
326 AccessToken: "ALICE_BEARER_TOKEN",
327 DisplayName: "Alice",
328 AccountType: userapi.AccountTypeUser,
329 }
330
331 base, close := testrig.CreateBaseDendrite(t, dbType)
332 defer close()
333
334 jsctx, _ := base.NATS.Prepare(base.ProcessContext, &base.Cfg.Global.JetStream)
335 defer jetstream.DeleteAllStreams(jsctx, &base.Cfg.Global.JetStream)
336
337 AddPublicRoutes(base, &syncUserAPI{accounts: []userapi.Device{alice}}, &syncRoomserverAPI{}, &syncKeyAPI{})
338
339 producer := producers.SyncAPIProducer{
340 TopicSendToDeviceEvent: base.Cfg.Global.JetStream.Prefixed(jetstream.OutputSendToDeviceEvent),
341 JetStream: jsctx,
342 }
343
344 msgCounter := 0
345
346 testCases := []struct {
347 name string
348 since string
349 want []string
350 sendMessagesCount int
351 }{
352 {
353 name: "initial sync, no messages",
354 want: []string{},
355 },
356 {
357 name: "initial sync, one new message",
358 sendMessagesCount: 1,
359 want: []string{
360 "message 1",
361 },
362 },
363 {
364 name: "initial sync, two new messages", // we didn't advance the since token, so we'll receive two messages
365 sendMessagesCount: 1,
366 want: []string{
367 "message 1",
368 "message 2",
369 },
370 },
371 {
372 name: "incremental sync, one message", // this deletes message 1, as we advanced the since token
373 since: types.StreamingToken{SendToDevicePosition: 1}.String(),
374 want: []string{
375 "message 2",
376 },
377 },
378 {

Callers

nothing calls this directly

Calls 7

SendToDeviceMethod · 0.95
PrefixedMethod · 0.80
AddPublicRoutesFunction · 0.70
PrepareMethod · 0.65
GetMethod · 0.65
StringMethod · 0.45
ServeHTTPMethod · 0.45

Tested by

no test coverage detected