2025-02-12 19:00:25 +00:00
|
|
|
package docsyncrunner_test
|
|
|
|
|
|
|
|
|
|
import (
|
2025-03-10 11:03:00 +00:00
|
|
|
"fmt"
|
2025-05-23 00:20:01 +00:00
|
|
|
"regexp"
|
2025-03-05 12:05:46 +00:00
|
|
|
"testing"
|
2025-05-20 12:47:22 +00:00
|
|
|
"time"
|
2025-03-05 12:05:46 +00:00
|
|
|
|
2025-02-12 19:00:25 +00:00
|
|
|
docsyncrunner "queryorchestration/api/docSyncRunner"
|
|
|
|
|
"queryorchestration/internal/client"
|
|
|
|
|
"queryorchestration/internal/database/repository"
|
|
|
|
|
"queryorchestration/internal/document"
|
|
|
|
|
documentsync "queryorchestration/internal/document/sync"
|
2025-04-02 18:50:03 +00:00
|
|
|
"queryorchestration/internal/server/runner"
|
2025-05-20 12:47:22 +00:00
|
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
2025-05-23 00:20:01 +00:00
|
|
|
"queryorchestration/internal/serviceconfig/queue"
|
2025-02-12 19:00:25 +00:00
|
|
|
"queryorchestration/internal/serviceconfig/queue/documentclean"
|
2025-05-20 12:47:22 +00:00
|
|
|
"queryorchestration/internal/test"
|
2025-02-12 19:00:25 +00:00
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2025-03-04 15:51:03 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2025-02-12 19:00:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type DocSyncConfig struct {
|
2025-04-02 18:50:03 +00:00
|
|
|
runner.BaseConfig[docsyncrunner.Body]
|
2025-02-12 19:00:25 +00:00
|
|
|
documentclean.DocCleanConfig
|
2025-05-23 00:20:01 +00:00
|
|
|
queue.QueueConfig
|
|
|
|
|
objectstore.ObjectStoreConfig
|
2025-02-12 19:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
2025-05-20 12:47:22 +00:00
|
|
|
func TestDocSyncRunner(t *testing.T) {
|
|
|
|
|
cfg := &DocSyncConfig{}
|
2025-05-23 00:20:01 +00:00
|
|
|
test.CreateDB(t, cfg)
|
|
|
|
|
acfg := test.CreateAWSContainer(t, cfg)
|
2025-02-12 19:00:25 +00:00
|
|
|
|
2025-05-23 00:20:01 +00:00
|
|
|
test.SetQueueClient(t, t.Context(), cfg, acfg.ExternalEndpoint)
|
|
|
|
|
cfg.DocumentCleanURL = test.CreateQueue(t, cfg, test.DocCleanRunnerName)
|
2025-02-12 19:00:25 +00:00
|
|
|
|
2025-04-22 14:40:16 +00:00
|
|
|
runner := docsyncrunner.New(&docsyncrunner.Services{
|
2025-02-12 19:00:25 +00:00
|
|
|
Document: documentsync.New(cfg, &documentsync.Services{
|
|
|
|
|
Document: document.New(cfg),
|
2025-03-10 13:00:57 +00:00
|
|
|
Client: client.New(cfg),
|
2025-02-12 19:00:25 +00:00
|
|
|
}),
|
|
|
|
|
})
|
|
|
|
|
|
2025-05-20 12:47:22 +00:00
|
|
|
err := cfg.GetDBQueries().CreateClient(t.Context(), &repository.CreateClientParams{
|
|
|
|
|
Clientid: "clientid",
|
|
|
|
|
Name: "client_name",
|
|
|
|
|
})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
err = cfg.GetDBQueries().AddClientCanSync(t.Context(), &repository.AddClientCanSyncParams{
|
|
|
|
|
Clientid: "clientid",
|
|
|
|
|
Cansync: true,
|
|
|
|
|
})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
docId, err := cfg.GetDBQueries().CreateDocument(t.Context(), &repository.CreateDocumentParams{
|
|
|
|
|
Clientid: "clientid",
|
|
|
|
|
Hash: "hash",
|
|
|
|
|
})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
part := uint16(1)
|
|
|
|
|
filetype := "pdf"
|
|
|
|
|
key := objectstore.BucketKey{
|
|
|
|
|
CreatedAt: time.Now().UTC(),
|
|
|
|
|
ClientID: "clientid",
|
|
|
|
|
EntityID: uuid.New(),
|
|
|
|
|
Location: objectstore.Import,
|
|
|
|
|
Part: &part,
|
|
|
|
|
FileType: &filetype,
|
|
|
|
|
}
|
|
|
|
|
err = cfg.GetDBQueries().AddDocumentEntry(t.Context(), &repository.AddDocumentEntryParams{
|
|
|
|
|
Documentid: docId,
|
|
|
|
|
Bucket: "bucket",
|
|
|
|
|
Key: key.String(),
|
|
|
|
|
})
|
|
|
|
|
require.NoError(t, err)
|
2025-02-12 19:00:25 +00:00
|
|
|
|
2025-05-20 12:47:22 +00:00
|
|
|
doc := docsyncrunner.Body{
|
|
|
|
|
DocumentID: docId,
|
|
|
|
|
}
|
2025-03-10 11:03:00 +00:00
|
|
|
|
2025-05-23 00:20:01 +00:00
|
|
|
assert.True(t, runner.Process(t.Context(), doc))
|
|
|
|
|
|
|
|
|
|
test.AssertMessageBody(t, cfg, cfg.GetDocumentCleanURL(), regexp.MustCompile(fmt.Sprintf("{\"id\":\"%s\"}", docId)))
|
2025-02-12 19:00:25 +00:00
|
|
|
}
|