@@ -3,7 +3,7 @@ import { v4 as uuidv4 } from 'uuid';
3
3
4
4
import { generateChannel } from './test-utils/generateChannel' ;
5
5
import { generateMsg } from './test-utils/generateMessage' ;
6
- import { generateThread } from './test-utils/generateThread ' ;
6
+ import { generateThreadResponse } from './test-utils/generateThreadResponse ' ;
7
7
8
8
import sinon from 'sinon' ;
9
9
import {
@@ -35,7 +35,7 @@ describe('Threads 2.0', () => {
35
35
} = { } ) {
36
36
return new Thread ( {
37
37
client,
38
- threadData : generateThread (
38
+ threadData : generateThreadResponse (
39
39
{ ...channelResponse , ...channelOverrides } ,
40
40
{ ...parentMessageResponse , ...parentMessageOverrides } ,
41
41
overrides ,
@@ -54,7 +54,12 @@ describe('Threads 2.0', () => {
54
54
55
55
describe ( 'Thread' , ( ) => {
56
56
it ( 'initializes properly' , ( ) => {
57
- const thread = new Thread ( { client, threadData : generateThread ( channelResponse , parentMessageResponse ) } ) ;
57
+ const threadResponse = generateThreadResponse ( channelResponse , parentMessageResponse ) ;
58
+ const thread = new Thread ( { client, threadData : threadResponse } ) ;
59
+ const state = thread . state . getLatestValue ( ) ;
60
+
61
+ expect ( threadResponse . read ) . to . have . lengthOf ( 0 ) ;
62
+ expect ( state . read ) . to . have . keys ( [ TEST_USER_ID ] ) ;
58
63
59
64
expect ( thread . id ) . to . equal ( parentMessageResponse . id ) ;
60
65
expect ( thread . channel . data ?. name ) . to . equal ( channelResponse . name ) ;
@@ -134,7 +139,7 @@ describe('Threads 2.0', () => {
134
139
it ( 'prevents updating a parent message if the ids do not match' , ( ) => {
135
140
const thread = createTestThread ( ) ;
136
141
const message = generateMsg ( ) as MessageResponse ;
137
- expect ( ( ) => thread . updateParentMessageLocally ( message ) ) . to . throw ( ) ;
142
+ expect ( ( ) => thread . updateParentMessageLocally ( { message } ) ) . to . throw ( ) ;
138
143
} ) ;
139
144
140
145
it ( 'updates parent message and related top-level properties' , ( ) => {
@@ -152,7 +157,7 @@ describe('Threads 2.0', () => {
152
157
deleted_at : new Date ( ) . toISOString ( ) ,
153
158
} ) as MessageResponse ;
154
159
155
- thread . updateParentMessageLocally ( updatedMessage ) ;
160
+ thread . updateParentMessageLocally ( { message : updatedMessage } ) ;
156
161
157
162
const stateAfter = thread . state . getLatestValue ( ) ;
158
163
expect ( stateAfter . deletedAt ) . to . be . not . null ;
@@ -603,7 +608,7 @@ describe('Threads 2.0', () => {
603
608
client . dispatchEvent ( {
604
609
type : 'message.read' ,
605
610
user : { id : 'bob' } ,
606
- thread : generateThread ( channelResponse , generateMsg ( ) ) as ThreadResponse ,
611
+ thread : generateThreadResponse ( channelResponse , generateMsg ( ) ) as ThreadResponse ,
607
612
} ) ;
608
613
609
614
const stateAfter = thread . state . getLatestValue ( ) ;
@@ -631,7 +636,10 @@ describe('Threads 2.0', () => {
631
636
client . dispatchEvent ( {
632
637
type : 'message.read' ,
633
638
user : { id : 'bob' } ,
634
- thread : generateThread ( channelResponse , generateMsg ( { id : parentMessageResponse . id } ) ) as ThreadResponse ,
639
+ thread : generateThreadResponse (
640
+ channelResponse ,
641
+ generateMsg ( { id : parentMessageResponse . id } ) ,
642
+ ) as ThreadResponse ,
635
643
created_at : createdAt . toISOString ( ) ,
636
644
} ) ;
637
645
@@ -858,10 +866,35 @@ describe('Threads 2.0', () => {
858
866
859
867
thread . unregisterSubscriptions ( ) ;
860
868
} ) ;
869
+
870
+ it ( 'handles deletion of the thread (updates deleted_at and parentMessage properties)' , ( ) => {
871
+ const thread = createTestThread ( ) ;
872
+ thread . registerSubscriptions ( ) ;
873
+
874
+ const stateBefore = thread . state . getLatestValue ( ) ;
875
+
876
+ const parentMessage = generateMsg ( {
877
+ id : thread . id ,
878
+ deleted_at : new Date ( ) . toISOString ( ) ,
879
+ type : 'deleted' ,
880
+ } ) as MessageResponse ;
881
+
882
+ expect ( thread . id ) . to . equal ( parentMessage . id ) ;
883
+ expect ( stateBefore . deletedAt ) . to . be . null ;
884
+
885
+ client . dispatchEvent ( { type : 'message.deleted' , message : parentMessage } ) ;
886
+
887
+ const stateAfter = thread . state . getLatestValue ( ) ;
888
+
889
+ expect ( stateAfter . deletedAt ) . to . be . a ( 'date' ) ;
890
+ expect ( stateAfter . deletedAt ! . toISOString ( ) ) . to . equal ( parentMessage . deleted_at ) ;
891
+ expect ( stateAfter . parentMessage . deleted_at ) . to . be . a ( 'date' ) ;
892
+ expect ( stateAfter . parentMessage . deleted_at ! . toISOString ( ) ) . to . equal ( parentMessage . deleted_at ) ;
893
+ } ) ;
861
894
} ) ;
862
895
863
896
describe ( 'Events: message.updated, reaction.new, reaction.deleted' , ( ) => {
864
- ( [ 'message.updated' , 'reaction.new' , 'reaction.deleted' ] as const ) . forEach ( ( eventType ) => {
897
+ ( [ 'message.updated' , 'reaction.new' , 'reaction.deleted' , 'reaction.updated' ] as const ) . forEach ( ( eventType ) => {
865
898
it ( `updates reply or parent message on "${ eventType } "` , ( ) => {
866
899
const thread = createTestThread ( ) ;
867
900
const updateParentMessageOrReplyLocallySpy = sinon . spy ( thread , 'updateParentMessageOrReplyLocally' ) ;
0 commit comments