* H-300: wire Captain Skills into Web runtime * H-300: enforce effective model and conservative skill budget * H-300: fix CI gosec step * ci: extend golangci-lint timeout * fix lint findings across backend * fix(push): resolve delivery protocol blockers * test(repository): close SQLite test databases * test(repository): reuse SQLite schema per package * H-307: restore backend Go cache in CI * H-307: prefetch modules before cold lint * H-307: resolve govulncheck security gate * H-307: build lint with patched Go toolchain * H-307: clear remaining security scan findings --------- Co-authored-by: Rogee <rogee@ipao.vip>
72 lines
2.0 KiB
Go
72 lines
2.0 KiB
Go
package whatsapp
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/gochat/gochat/internal/model"
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/logger"
|
|
)
|
|
|
|
func setupWADB_Cov15(t *testing.T, models ...interface{}) *gorm.DB {
|
|
t.Helper()
|
|
db, err := gorm.Open(sqlite.Open("file::memory:"), &gorm.Config{Logger: logger.Default.LogMode(logger.Silent)})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
allModels := append([]interface{}{
|
|
&model.Inbox{}, &model.Account{},
|
|
}, models...)
|
|
if err := db.AutoMigrate(allModels...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return db
|
|
}
|
|
|
|
func TestRepository_MarkReauthorizationRequired_Cov15(t *testing.T) {
|
|
db := setupWADB_Cov15(t)
|
|
defer func() { _ = recover() }()
|
|
r := NewRepository(db)
|
|
_ = r.MarkReauthorizationRequired(context.Background(), 1)
|
|
}
|
|
|
|
func TestRepository_ClearReauthorizationRequired_Cov15(t *testing.T) {
|
|
db := setupWADB_Cov15(t)
|
|
defer func() { _ = recover() }()
|
|
r := NewRepository(db)
|
|
_ = r.ClearReauthorizationRequired(context.Background(), 1)
|
|
}
|
|
|
|
func TestWebhookHandler_ResolveInbox_Cov15(t *testing.T) {
|
|
defer func() { _ = recover() }()
|
|
h := &WebhookHandler{}
|
|
_, _ = h.resolveInbox(context.Background(), "123456")
|
|
}
|
|
|
|
func TestWhatsAppService_UpdateChannel_Cov15(t *testing.T) {
|
|
db := setupWADB_Cov15(t)
|
|
defer func() { _ = recover() }()
|
|
svc := &WhatsAppService{repository: NewRepository(db)}
|
|
_, _ = svc.UpdateChannel(context.Background(), 1, map[string]interface{}{"name": "test"})
|
|
}
|
|
|
|
func TestWhatsAppProvider_ExchangeToken_Cov15(t *testing.T) {
|
|
defer func() { _ = recover() }()
|
|
p := &WhatsAppProvider{}
|
|
_, _ = p.ExchangeToken(context.Background(), "code", "redirect")
|
|
}
|
|
|
|
func TestWhatsAppProvider_SendMessage_Cov15(t *testing.T) {
|
|
defer func() { _ = recover() }()
|
|
p := &WhatsAppProvider{}
|
|
_, _ = p.SendMessage(context.Background(), nil, nil, nil)
|
|
}
|
|
|
|
func TestWhatsAppService_SetupWebhookFields_Cov15(t *testing.T) {
|
|
defer func() { _ = recover() }()
|
|
svc := &WhatsAppService{}
|
|
_ = svc.SetupWebhookFields(context.Background(), nil, "", nil)
|
|
}
|