@@ -38,13 +38,16 @@ let listNextCursor = ''
3838let history : Record < string , unknown > [ ] = MESSAGES
3939/** Whether `conversations.info` reports the channel as missing; per-test overridable. */
4040let channelMissing = false
41+ /** The channel `conversations.info` returns; per-test overridable. */
42+ let infoChannel : Record < string , unknown > = GENERAL
4143
4244beforeEach ( ( ) => {
4345 requestedUrls . length = 0
4446 listedChannels = [ GENERAL , PLATFORM ]
4547 listNextCursor = ''
4648 history = MESSAGES
4749 channelMissing = false
50+ infoChannel = GENERAL
4851 fetchMock . mockReset ( )
4952 fetchMock . mockImplementation ( async ( input ) => {
5053 const url = new URL ( String ( input ) )
@@ -61,7 +64,7 @@ beforeEach(() => {
6164 case '/api/conversations.info' :
6265 return channelMissing
6366 ? jsonResponse ( { ok : false , error : 'channel_not_found' } )
64- : jsonResponse ( { ok : true , channel : GENERAL } )
67+ : jsonResponse ( { ok : true , channel : infoChannel } )
6568 case '/api/conversations.history' :
6669 return jsonResponse ( { ok : true , messages : history , response_metadata : { } } )
6770 case '/api/users.info' : {
@@ -163,7 +166,9 @@ describe('getDocument', () => {
163166 expect ( doc ) . toMatchObject ( {
164167 externalId : 'C0GENERAL' ,
165168 title : '#general' ,
166- contentHash : 'slack-v3:C0GENERAL:1700000000.000100:1700000200.000100:3:noedit:noreply:0' ,
169+ contentHash : expect . stringMatching (
170+ / ^ s l a c k - v 3 : C 0 G E N E R A L : [ 0 - 9 a - f ] { 16 } : 1 7 0 0 0 0 0 0 0 0 \. 0 0 0 1 0 0 : 1 7 0 0 0 0 0 2 0 0 \. 0 0 0 1 0 0 : 3 : n o e d i t : n o r e p l y : 0 $ /
171+ ) ,
167172 metadata : expect . objectContaining ( { channelName : 'general' , messageCount : 2 } ) ,
168173 } )
169174 expect ( doc ?. content ) . toBe (
@@ -177,6 +182,22 @@ describe('getDocument', () => {
177182 )
178183 } )
179184
185+ it ( 'moves the hash when the header changes without any message changing' , async ( ) => {
186+ const before = await slackConnector . getDocument ( 'token' , { } , 'C0GENERAL' , { } )
187+
188+ infoChannel = { ...GENERAL , name : 'general-renamed' }
189+ const renamed = await slackConnector . getDocument ( 'token' , { } , 'C0GENERAL' , { } )
190+ expect ( renamed ?. contentHash ) . not . toBe ( before ?. contentHash )
191+
192+ infoChannel = { ...GENERAL , topic : { value : 'A new topic' } }
193+ const retopiced = await slackConnector . getDocument ( 'token' , { } , 'C0GENERAL' , { } )
194+ expect ( retopiced ?. contentHash ) . not . toBe ( before ?. contentHash )
195+
196+ infoChannel = GENERAL
197+ const again = await slackConnector . getDocument ( 'token' , { } , 'C0GENERAL' , { } )
198+ expect ( again ?. contentHash ) . toBe ( before ?. contentHash )
199+ } )
200+
180201 it ( 'keeps a channel with no messages as a live document' , async ( ) => {
181202 history = [ ]
182203 const doc = await slackConnector . getDocument ( 'token' , { } , 'C0GENERAL' , { } )
0 commit comments