feat: initial commit

This commit is contained in:
2026-04-16 19:39:02 +02:00
commit 50d1686b1e
44 changed files with 2089 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
package testutil
import "context"
type FakeFileDownloader struct {
Data []byte
MimeType string
Error error
}
func (f *FakeFileDownloader) Download(_ context.Context, _ string) ([]byte, string, error) {
return f.Data, f.MimeType, f.Error
}
type FakeAudioConverter struct {
Output []byte
Error error
}
func (f *FakeAudioConverter) Convert(_ context.Context, _ []byte, _, _ string) ([]byte, error) {
if f.Output != nil {
return f.Output, f.Error
}
return []byte("converted-audio"), f.Error
}

View File

@@ -0,0 +1,15 @@
package testutil
import (
"context"
"github.com/paramah/gw_telegram/internal/domain/entity"
)
type FakeIntentRouter struct {
RouteResult entity.Route
Error error
}
func (f *FakeIntentRouter) Route(_ context.Context, _ entity.Message) (entity.Route, error) {
return f.RouteResult, f.Error
}

View File

@@ -0,0 +1,22 @@
package testutil
import "context"
type FakeMessageGateway struct {
LastSentText string
LastChatID int64
TypingChatIDs []int64
SendError error
TypingError error
}
func (f *FakeMessageGateway) SendText(_ context.Context, chatID int64, text string) error {
f.LastChatID = chatID
f.LastSentText = text
return f.SendError
}
func (f *FakeMessageGateway) SendTyping(_ context.Context, chatID int64) error {
f.TypingChatIDs = append(f.TypingChatIDs, chatID)
return f.TypingError
}

View File

@@ -0,0 +1,43 @@
package testutil
import (
"context"
"github.com/paramah/gw_telegram/internal/domain/apperror"
"github.com/paramah/gw_telegram/internal/domain/entity"
)
type FakeSessionStore struct {
Sessions map[int64]entity.Session
GetError error
SetCalled bool
LastSetSession entity.Session
}
func (f *FakeSessionStore) Get(_ context.Context, userID int64) (entity.Session, error) {
if f.GetError != nil {
return entity.Session{}, f.GetError
}
if f.Sessions != nil {
if s, ok := f.Sessions[userID]; ok {
return s, nil
}
}
return entity.Session{}, apperror.ErrSessionNotFound
}
func (f *FakeSessionStore) Set(_ context.Context, session entity.Session) error {
f.SetCalled = true
f.LastSetSession = session
if f.Sessions == nil {
f.Sessions = make(map[int64]entity.Session)
}
f.Sessions[session.UserID] = session
return nil
}
func (f *FakeSessionStore) Delete(_ context.Context, userID int64) error {
if f.Sessions != nil {
delete(f.Sessions, userID)
}
return nil
}

View File

@@ -0,0 +1,14 @@
package testutil
import "context"
type FakeSpeechTranscriber struct {
Transcript string
Error error
CallCount int
}
func (f *FakeSpeechTranscriber) Transcribe(_ context.Context, _ []byte, _ string) (string, error) {
f.CallCount++
return f.Transcript, f.Error
}

View File

@@ -0,0 +1,19 @@
package testutil
import (
"context"
"github.com/paramah/gw_telegram/internal/domain/entity"
)
type FakeWorkflowDispatcher struct {
Response entity.WorkflowResponse
Error error
CallCount int
LastRequest entity.WorkflowRequest
}
func (f *FakeWorkflowDispatcher) Dispatch(_ context.Context, req entity.WorkflowRequest) (entity.WorkflowResponse, error) {
f.CallCount++
f.LastRequest = req
return f.Response, f.Error
}

29
test/testutil/fixtures.go Normal file
View File

@@ -0,0 +1,29 @@
package testutil
import (
"time"
"github.com/paramah/gw_telegram/internal/domain/entity"
)
func NewTextMessage(chatID, userID int64, text string) entity.Message {
return entity.Message{
MessageID: 1,
ChatID: chatID,
UserID: userID,
Username: "testuser",
Type: entity.MessageTypeText,
Text: text,
Timestamp: time.Now(),
Metadata: make(map[string]any),
}
}
func NewSession(userID, chatID int64) entity.Session {
return entity.Session{
UserID: userID,
ChatID: chatID,
Data: make(map[string]any),
UpdatedAt: time.Now(),
TTL: 24,
}
}