Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont committed Jun 4, 2023
1 parent 5fb3b9f commit f7507d8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/message_sender/message_sender_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"
"github.com/davecgh/go-spew/spew"
"github.com/mr-linch/go-tg"
"github.com/satont/twitch-notifier/internal/db/db_models"
"github.com/satont/twitch-notifier/internal/test_utils/mocks"
"io"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -92,8 +92,8 @@ func TestMessageSender_SendMessage(t *testing.T) {
name: "should call send message method with parse mode",
chat: chat,
opts: &MessageOpts{
Text: "test md",
ParseMode: &tg.MD,
Text: "test md",
TgParseMode: TgParseModeMD,
},
createServer: func(t *testing.T) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -126,9 +126,9 @@ func TestMessageSender_SendMessage(t *testing.T) {
t.Run(tt.name, func(c *testing.T) {
server := tt.createServer(c)
tgClient := test_utils.NewTelegramClient(server)
sender := NewMessageSender(tgClient)
sender := NewMessageSender(tgClient, &mocks.DbQueueMock{})

err := sender.SendMessage(context.Background(), tt.chat, tt.opts)
err := sender.SendMessage(context.Background(), tt.opts)
assert.NoError(c, err)
assert.Nil(c, err)
})
Expand Down
37 changes: 37 additions & 0 deletions internal/test_utils/mocks/db_queue_job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package mocks

import (
"context"
"github.com/google/uuid"
"github.com/satont/twitch-notifier/internal/db"
"github.com/satont/twitch-notifier/internal/db/db_models"
"github.com/stretchr/testify/mock"
)

type DbQueueMock struct {
mock.Mock
}

func (s *DbQueueMock) AddJob(ctx context.Context, job *db.QueueJobCreateOpts) (*db_models.QueueJob, error) {
args := s.Called(ctx, job)

return args.Get(0).(*db_models.QueueJob), args.Error(1)
}

func (s *DbQueueMock) RemoveJobById(ctx context.Context, id uuid.UUID) error {
args := s.Called(ctx, id)

return args.Error(0)
}

func (s *DbQueueMock) GetUnprocessedJobsByQueueName(ctx context.Context, queueName string) ([]db_models.QueueJob, error) {
args := s.Called(ctx, queueName)

return args.Get(0).([]db_models.QueueJob), args.Error(1)
}

func (s *DbQueueMock) UpdateJob(ctx context.Context, id uuid.UUID, data *db.QueueJobUpdateOpts) error {
args := s.Called(ctx, id, data)

return args.Error(0)
}

0 comments on commit f7507d8

Please sign in to comment.