@@ -2,6 +2,7 @@ package repository
22
33import (
44 "context"
5+ "encoding/json"
56 "testing"
67 "time"
78
@@ -51,6 +52,79 @@ func TestDataSourceRepositoryUpdateSyncStateClearsErrorMessage(t *testing.T) {
5152 require .NotNil (t , stored .LastSyncAt )
5253}
5354
55+ func TestDataSourceRepositoryInvalidateCursorItemRemovesFeishuNode (t * testing.T ) {
56+ db := setupDataSourceRepoTestDB (t )
57+ repo := NewDataSourceRepository (db )
58+ cursor := types .JSON (`{
59+ "last_sync_time":"2026-06-10T00:00:00Z",
60+ "connector_cursor":{
61+ "space_node_times":{
62+ "space-1:root-a":{"node-a":"100","node-b":"200"},
63+ "space-1:root-b":{"node-a":"300"}
64+ }
65+ }
66+ }` )
67+ ds := & types.DataSource {
68+ ID : "ds-feishu" ,
69+ TenantID : 1 ,
70+ KnowledgeBaseID : "kb-1" ,
71+ Name : "Feishu" ,
72+ Type : types .ConnectorTypeFeishu ,
73+ Status : types .DataSourceStatusActive ,
74+ LastSyncCursor : cursor ,
75+ }
76+ require .NoError (t , repo .Create (context .Background (), ds ))
77+
78+ require .NoError (t , repo .InvalidateCursorItem (context .Background (), 1 , ds .ID , "node-a" , "space-1:root-a" ))
79+
80+ var stored types.DataSource
81+ require .NoError (t , db .First (& stored , "id = ?" , ds .ID ).Error )
82+ var decoded map [string ]interface {}
83+ require .NoError (t , json .Unmarshal (stored .LastSyncCursor , & decoded ))
84+ connectorCursor := decoded ["connector_cursor" ].(map [string ]interface {})
85+ spaceNodeTimes := connectorCursor ["space_node_times" ].(map [string ]interface {})
86+ rootA := spaceNodeTimes ["space-1:root-a" ].(map [string ]interface {})
87+ rootB := spaceNodeTimes ["space-1:root-b" ].(map [string ]interface {})
88+ assert .NotContains (t , rootA , "node-a" )
89+ assert .Equal (t , "200" , rootA ["node-b" ])
90+ assert .Equal (t , "300" , rootB ["node-a" ])
91+ }
92+
93+ func TestDataSourceRepositoryInvalidateCursorItemRemovesGenericExternalID (t * testing.T ) {
94+ db := setupDataSourceRepoTestDB (t )
95+ repo := NewDataSourceRepository (db )
96+ cursor := types .JSON (`{
97+ "last_sync_time":"2026-06-10T00:00:00Z",
98+ "connector_cursor":{
99+ "page_edit_times":{
100+ "page-a":"2026-06-09T00:00:00Z",
101+ "page-b":"2026-06-09T01:00:00Z"
102+ }
103+ }
104+ }` )
105+ ds := & types.DataSource {
106+ ID : "ds-notion" ,
107+ TenantID : 1 ,
108+ KnowledgeBaseID : "kb-1" ,
109+ Name : "Notion" ,
110+ Type : types .ConnectorTypeNotion ,
111+ Status : types .DataSourceStatusActive ,
112+ LastSyncCursor : cursor ,
113+ }
114+ require .NoError (t , repo .Create (context .Background (), ds ))
115+
116+ require .NoError (t , repo .InvalidateCursorItem (context .Background (), 1 , ds .ID , "page-a" , "" ))
117+
118+ var stored types.DataSource
119+ require .NoError (t , db .First (& stored , "id = ?" , ds .ID ).Error )
120+ var decoded map [string ]interface {}
121+ require .NoError (t , json .Unmarshal (stored .LastSyncCursor , & decoded ))
122+ connectorCursor := decoded ["connector_cursor" ].(map [string ]interface {})
123+ pageEditTimes := connectorCursor ["page_edit_times" ].(map [string ]interface {})
124+ assert .NotContains (t , pageEditTimes , "page-a" )
125+ assert .Contains (t , pageEditTimes , "page-b" )
126+ }
127+
54128func TestSyncLogRepositoryUpdateResultClearsErrorMessage (t * testing.T ) {
55129 db := setupDataSourceRepoTestDB (t )
56130 repo := NewSyncLogRepository (db )
0 commit comments