feat: add msglib message source metadata
This commit is contained in:
@@ -55,6 +55,32 @@ func TestDisplaySourcesPassesConfiguredPathsAndDecodesMetadata(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageSourcesPassesConfiguredPathsAndDecodesMetadata(t *testing.T) {
|
||||
cfg := Config{
|
||||
SQLiteDLLPath: `C:\fixture\System.Data.SQLite.dll`,
|
||||
DBPath: `C:\fixture\MsgLib.db`,
|
||||
Password: "123",
|
||||
}
|
||||
client := newFakeClient(t, "message_sources_ok", cfg)
|
||||
|
||||
got, err := client.MessageSources(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("MessageSources returned error: %v", err)
|
||||
}
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("len(MessageSources) = %d, want 2", len(got))
|
||||
}
|
||||
if got[0].Source != "direct_messages" || got[0].Table != "tblPersonMsg" || got[0].Role != "direct" || !got[0].Available {
|
||||
t.Fatalf("unexpected first message source: %+v", got[0])
|
||||
}
|
||||
if got[0].RowCount != "2132" || strings.Join(got[0].RequiredColumns, ",") != "Id,SndPersonId,RecvPersonId,ObjPersonId,ActionTime,MsgText,MessageBody" {
|
||||
t.Fatalf("unexpected first message source metadata: %+v", got[0])
|
||||
}
|
||||
if got[1].Source != "group_messages" || got[1].Table != "tblMsgGroupPersonMsg" || got[1].Role != "group" || got[1].RowCount != "2884" {
|
||||
t.Fatalf("unexpected second message source: %+v", got[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisplayEntitiesPassesBoundedArgsAndDecodesMetadata(t *testing.T) {
|
||||
cfg := Config{
|
||||
SQLiteDLLPath: `C:\fixture\System.Data.SQLite.dll`,
|
||||
@@ -240,6 +266,47 @@ func fakeSidecarMain() int {
|
||||
"error": nil,
|
||||
"warnings": []any{},
|
||||
})
|
||||
case "message_sources":
|
||||
args, _ := req["args"].(map[string]any)
|
||||
if args["sqlite_dll_path"] != `C:\fixture\System.Data.SQLite.dll` || args["db_path"] != `C:\fixture\MsgLib.db` || args["password"] != "123" {
|
||||
fmt.Fprintf(os.Stderr, "bad message_sources args: %#v\n", args)
|
||||
return 2
|
||||
}
|
||||
return writeFakeResponse(map[string]any{
|
||||
"protocol": Protocol,
|
||||
"request_id": requestID,
|
||||
"op": op,
|
||||
"ok": true,
|
||||
"data": map[string]any{
|
||||
"metadata_only": true,
|
||||
"read_only": true,
|
||||
"message_body_values_returned": false,
|
||||
"raw_rows_returned": false,
|
||||
"file_paths_returned": false,
|
||||
"message_sources": []any{
|
||||
map[string]any{
|
||||
"source": "direct_messages",
|
||||
"table": "tblPersonMsg",
|
||||
"role": "direct",
|
||||
"available": true,
|
||||
"required_columns": []any{"Id", "SndPersonId", "RecvPersonId", "ObjPersonId", "ActionTime", "MsgText", "MessageBody"},
|
||||
"present_columns": []any{"Id", "SndPersonId", "RecvPersonId", "ObjPersonId", "ActionTime", "MsgText", "MessageBody"},
|
||||
"row_count": "2132",
|
||||
},
|
||||
map[string]any{
|
||||
"source": "group_messages",
|
||||
"table": "tblMsgGroupPersonMsg",
|
||||
"role": "group",
|
||||
"available": true,
|
||||
"required_columns": []any{"Id", "SndPersonId", "MsgGroupId", "MsgGroupName", "MsgTime", "MsgText", "MessageBody"},
|
||||
"present_columns": []any{"Id", "SndPersonId", "MsgGroupId", "MsgGroupName", "MsgTime", "MsgText", "MessageBody"},
|
||||
"row_count": "2884",
|
||||
},
|
||||
},
|
||||
},
|
||||
"error": nil,
|
||||
"warnings": []any{},
|
||||
})
|
||||
case "display_entities":
|
||||
args, _ := req["args"].(map[string]any)
|
||||
if args["sqlite_dll_path"] != `C:\fixture\System.Data.SQLite.dll` || args["db_path"] != `C:\fixture\MsgLib.db` || args["password"] != "123" || args["entity_type"] != "contacts" || args["query"] != "alice" || args["limit"] != float64(2) {
|
||||
|
||||
Reference in New Issue
Block a user