Skip to content

Commit 9a08712

Browse files
test
1 parent 6500cea commit 9a08712

6 files changed

Lines changed: 70 additions & 13 deletions

File tree

infrastructure/injector/injector.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package injector
22

33
import (
4-
"fmt"
5-
64
"github.com/jmoiron/sqlx"
75
"github.com/traP-jp/anshin-techo-backend/internal/api"
86
"github.com/traP-jp/anshin-techo-backend/internal/handler"
@@ -18,12 +16,13 @@ type Dependencies struct {
1816
func InjectServer(deps Dependencies) (*api.Server, error) {
1917
repo := repository.New(deps.DB) //, deps.Bot)
2018

21-
botService, ok := deps.Bot.(*bot.Service)
22-
if !ok {
23-
return nil, fmt.Errorf("failed to cast bot client to service")
24-
}
19+
// botService, ok := deps.Bot.(*bot.Service)
20+
// if !ok {
21+
// return nil, fmt.Errorf("failed to cast bot client to service")
22+
// }
2523

26-
h := handler.New(repo, botService)
24+
// h := handler.New(repo, botService)
25+
h := handler.New(repo, deps.Bot)
2726
s, err := api.NewServer(h, h)
2827
if err != nil {
2928
return nil, err

integration_tests/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ replace github.com/traP-jp/anshin-techo-backend => ../
66

77
require (
88
github.com/jmoiron/sqlx v1.4.0
9-
github.com/labstack/echo/v4 v4.14.0
9+
github.com/labstack/echo/v4 v4.15.0
1010
github.com/ory/dockertest/v3 v3.12.0
1111
github.com/traP-jp/anshin-techo-backend v0.0.0
1212
gotest.tools/v3 v3.5.2
@@ -52,6 +52,7 @@ require (
5252
github.com/opencontainers/runc v1.3.0 // indirect
5353
github.com/pkg/errors v0.9.1 // indirect
5454
github.com/pressly/goose/v3 v3.26.0 // indirect
55+
github.com/robfig/cron/v3 v3.0.1 // indirect
5556
github.com/sashabaranov/go-openai v1.41.2 // indirect
5657
github.com/segmentio/asm v1.2.1 // indirect
5758
github.com/sethvargo/go-retry v0.3.0 // indirect

integration_tests/go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
7272
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
7373
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
7474
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
75-
github.com/labstack/echo/v4 v4.14.0 h1:+tiMrDLxwv6u0oKtD03mv+V1vXXB3wCqPHJqPuIe+7M=
76-
github.com/labstack/echo/v4 v4.14.0/go.mod h1:xmw1clThob0BSVRX1CRQkGQ/vjwcpOMjQZSZa9fKA/c=
75+
github.com/labstack/echo/v4 v4.15.0 h1:hoRTKWcnR5STXZFe9BmYun9AMTNeSbjHi2vtDuADJ24=
76+
github.com/labstack/echo/v4 v4.15.0/go.mod h1:xmw1clThob0BSVRX1CRQkGQ/vjwcpOMjQZSZa9fKA/c=
7777
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
7878
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
7979
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
@@ -112,6 +112,8 @@ github.com/pressly/goose/v3 v3.26.0 h1:KJakav68jdH0WDvoAcj8+n61WqOIaPGgH0bJWS6jp
112112
github.com/pressly/goose/v3 v3.26.0/go.mod h1:4hC1KrritdCxtuFsqgs1R4AU5bWtTAf+cnWvfhf2DNY=
113113
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
114114
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
115+
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
116+
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
115117
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
116118
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
117119
github.com/sashabaranov/go-openai v1.41.2 h1:vfPRBZNMpnqu8ELsclWcAvF19lDNgh1t6TVfFFOPiSM=

internal/handler/handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ import (
99

1010
"github.com/labstack/echo/v4"
1111
"github.com/traP-jp/anshin-techo-backend/internal/api"
12-
"github.com/traP-jp/anshin-techo-backend/internal/service/bot"
1312
"github.com/traP-jp/anshin-techo-backend/internal/repository"
13+
"github.com/traP-jp/anshin-techo-backend/internal/service/bot"
1414
)
1515

1616
type Handler struct {
1717
repo *repository.Repository
18-
bot *bot.Service
18+
bot bot.Client
1919
}
2020

2121
func New(
2222
repo *repository.Repository,
23-
bot *bot.Service,
23+
bot bot.Client,
2424
) *Handler {
2525
return &Handler{
2626
//photo,

internal/service/bot/interface.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package bot
33
import (
44
"context"
55

6+
"github.com/traP-jp/anshin-techo-backend/internal/repository" // 追加
67
"github.com/traPtitech/go-traq"
78
"github.com/traPtitech/traq-ws-bot/payload"
89
)
@@ -20,6 +21,14 @@ type Client interface {
2021

2122
// EventHandler インターフェースを埋め込み
2223
EventHandler
24+
25+
NotifyTicketCreated(ctx context.Context, ticket *repository.Ticket) error
26+
NotifyTicketUpdated(ctx context.Context, ticket *repository.Ticket) error
27+
NotifyNoteCreated(ctx context.Context, noteType string, contentPreview string, authorID string, shouldMention bool) error
28+
NotifyReviewCreated(ctx context.Context, noteTitle string, noteAuthorID string, reviewerID string, comment string) error
29+
SendDeadlineReminder(ctx context.Context, ticket *repository.Ticket, daysOverdue int) error
30+
SendWaitingSentReminder(ctx context.Context, ticket *repository.Ticket) error
31+
GetUserIDByName(ctx context.Context, name string) (string, error)
2332
}
2433

2534
// MessageSender はメッセージ送信機能を抽象化したインターフェース

internal/service/bot/mock.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package bot
33
import (
44
"context"
55

6+
"github.com/traP-jp/anshin-techo-backend/internal/repository"
67
"github.com/traPtitech/go-traq"
78
"github.com/traPtitech/traq-ws-bot/payload"
89
)
@@ -14,6 +15,14 @@ type MockService struct {
1415
PostMessageFunc func(ctx context.Context, channelID string, content string) error
1516
PostDirectMessageFunc func(ctx context.Context, userID string, content string) error
1617

18+
NotifyTicketCreatedFunc func(ctx context.Context, ticket *repository.Ticket) error
19+
NotifyTicketUpdatedFunc func(ctx context.Context, ticket *repository.Ticket) error
20+
NotifyNoteCreatedFunc func(ctx context.Context, noteType string, contentPreview string, authorID string, shouldMention bool) error
21+
NotifyReviewCreatedFunc func(ctx context.Context, noteTitle string, noteAuthorID string, reviewerID string, comment string) error
22+
SendDeadlineReminderFunc func(ctx context.Context, ticket *repository.Ticket, daysOverdue int) error
23+
SendWaitingSentReminderFunc func(ctx context.Context, ticket *repository.Ticket) error
24+
GetUserIDByNameFunc func(ctx context.Context, name string) (string, error)
25+
1726
// イベントハンドラの記録用
1827
MessageCreatedHandler func(messageID, channelID, userID, content string)
1928
MessageStampsUpdatedHandler func(messageID string, stamps []payload.MessageStamp)
@@ -36,6 +45,15 @@ func NewMockService() *MockService {
3645
PostDirectMessageFunc: func(_ context.Context, _ string, _ string) error {
3746
return nil
3847
},
48+
49+
NotifyTicketCreatedFunc: func(_ context.Context, _ *repository.Ticket) error { return nil },
50+
NotifyTicketUpdatedFunc: func(_ context.Context, _ *repository.Ticket) error { return nil },
51+
NotifyNoteCreatedFunc: func(_ context.Context, _ string, _ string, _ string, _ bool) error { return nil },
52+
NotifyReviewCreatedFunc: func(_ context.Context, _ string, _ string, _ string, _ string) error { return nil },
53+
SendDeadlineReminderFunc: func(_ context.Context, _ *repository.Ticket, _ int) error { return nil },
54+
SendWaitingSentReminderFunc: func(_ context.Context, _ *repository.Ticket) error { return nil },
55+
GetUserIDByNameFunc: func(_ context.Context, _ string) (string, error) { return "user-id", nil },
56+
3957
MessageCreatedHandler: func(_, _, _, _ string) {},
4058
MessageStampsUpdatedHandler: func(_ string, _ []payload.MessageStamp) {},
4159
}
@@ -57,6 +75,34 @@ func (m *MockService) PostDirectMessage(ctx context.Context, userID string, cont
5775
return m.PostDirectMessageFunc(ctx, userID, content)
5876
}
5977

78+
func (m *MockService) NotifyTicketCreated(ctx context.Context, ticket *repository.Ticket) error {
79+
return m.NotifyTicketCreatedFunc(ctx, ticket)
80+
}
81+
82+
func (m *MockService) NotifyTicketUpdated(ctx context.Context, ticket *repository.Ticket) error {
83+
return m.NotifyTicketUpdatedFunc(ctx, ticket)
84+
}
85+
86+
func (m *MockService) NotifyNoteCreated(ctx context.Context, noteType string, contentPreview string, authorID string, shouldMention bool) error {
87+
return m.NotifyNoteCreatedFunc(ctx, noteType, contentPreview, authorID, shouldMention)
88+
}
89+
90+
func (m *MockService) NotifyReviewCreated(ctx context.Context, noteTitle string, noteAuthorID string, reviewerID string, comment string) error {
91+
return m.NotifyReviewCreatedFunc(ctx, noteTitle, noteAuthorID, reviewerID, comment)
92+
}
93+
94+
func (m *MockService) SendDeadlineReminder(ctx context.Context, ticket *repository.Ticket, daysOverdue int) error {
95+
return m.SendDeadlineReminderFunc(ctx, ticket, daysOverdue)
96+
}
97+
98+
func (m *MockService) SendWaitingSentReminder(ctx context.Context, ticket *repository.Ticket) error {
99+
return m.SendWaitingSentReminderFunc(ctx, ticket)
100+
}
101+
102+
func (m *MockService) GetUserIDByName(ctx context.Context, name string) (string, error) {
103+
return m.GetUserIDByNameFunc(ctx, name)
104+
}
105+
60106
func (m *MockService) OnMessageCreated(handler func(messageID, channelID, userID, content string)) {
61107
m.MessageCreatedHandler = handler
62108
}

0 commit comments

Comments
 (0)