Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

test: improve validation test coverage from 65.3% to 92.1%

Aldino Kemal20eb57666868
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 00000000..796c0ba5
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,85 @@
+# CLAUDE.md
+
+This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
+
+## Common Development Commands
+
+### Building and Running
+
+- **Build binary**: `cd src && go build -o whatsapp` (Linux/macOS) or `go build -o whatsapp.exe` (Windows)
+- **Run REST API mode**: `cd src && go run . rest` or `./whatsapp rest`
+- **Run MCP server mode**: `cd src && go run . mcp` or `./whatsapp mcp`
+- **Run with Docker**: `docker-compose up -d --build`
+
+### Testing
+
+- **Run all tests**: `cd src && go test ./...`
+- **Run specific package tests**: `cd src && go test ./validations`
+- **Run tests with coverage**: `cd src && go test -cover ./...`
+
+### Development
+
+- **Format code**: `cd src && go fmt ./...`
+- **Get dependencies**: `cd src && go mod tidy`
+- **Check for issues**: `cd src && go vet ./...`
+
+## Project Architecture
+
+This is a Go-based WhatsApp Web API server supporting both REST API and MCP (Model Context Protocol) modes.
+
+### Core Architecture Pattern
+
+- **Domain-Driven Design**: Business logic separated into domain packages (`domains/`)
+- **Clean Architecture**: Clear separation between UI, use cases, and infrastructure layers
+- **Cobra CLI**: Command pattern with separate commands for `rest` and `mcp` modes
+
+### Key Directories
+
+- `src/`: Main source code directory
+- `src/cmd/`: CLI commands (root, rest, mcp)
+- `src/domains/`: Business domain logic (app, chat, group, message, send, user, newsletter)
+- `src/infrastructure/`: External integrations (WhatsApp, database)
+- `src/ui/`: User interface layers (REST API, MCP server, WebSocket)
+- `src/usecase/`: Application use cases bridging domains and UI
+- `src/validations/`: Input validation logic
+- `src/pkg/`: Shared utilities and helpers
+
+### Configuration
+
+- **Environment Variables**: See `.env.example` for all available options
+- **Command Line Flags**: All env vars can be overridden with CLI flags
+- **Config Priority**: CLI flags > Environment variables > `.env` file
+
+### Database
+
+- **Main DB**: WhatsApp connection data (SQLite by default, supports PostgreSQL)
+- **Chat Storage**: Separate SQLite database for chat history (`storages/chatstorage.db`)
+- **Database URIs**: Configurable via `DB_URI` and `DB_KEYS_URI` environment variables
+
+### Mode-Specific Architecture
+
+- **REST Mode**: Fiber web server with HTML templates, WebSocket support, middleware stack
+- **MCP Mode**: Model Context Protocol server with SSE transport for AI agent integration
+
+### Key Dependencies
+
+- `go.mau.fi/whatsmeow`: WhatsApp Web protocol implementation
+- `github.com/gofiber/fiber/v2`: Web framework for REST API
+- `github.com/mark3labs/mcp-go`: MCP server implementation
+- `github.com/spf13/cobra`: CLI framework
+- `github.com/spf13/viper`: Configuration management
+
+### WhatsApp Integration
+
+- Uses whatsmeow library for WhatsApp Web protocol
+- Supports multi-device WhatsApp accounts
+- Auto-reconnection and connection monitoring
+- Media compression and webhook support
+
+## Important Notes
+
+- The application cannot run both REST and MCP modes simultaneously (limitation from whatsmeow library)
+- All source code must be in the `src/` directory
+- Media files are stored in `src/statics/media/` and `src/storages/`
+- HTML templates and assets are embedded in the binary using Go's embed feature
+- FFmpeg is required for media processing (installation varies by platform)
diff --git a/src/config/settings.go b/src/config/settings.go
index 74edcb6f..b202c314 100644
--- a/src/config/settings.go
+++ b/src/config/settings.go
@@ -5,7 +5,7 @@ import (
)
var (
- AppVersion = "v7.2.1"
+ AppVersion = "v7.3.0"
AppPort = "3000"
AppDebug = false
AppOs = "AldinoKemal"
@@ -20,7 +20,7 @@ var (
PathMedia = "statics/media"
PathStorages = "storages"
- DBURI = "file:storages/whatsapp.db?_foreign_keys=on"
+ DBURI = "file:storages/whatsapp.db?_foreign_keys=on"
DBKeysURI = ""
WhatsappAutoReplyMessage string
diff --git a/src/go.mod b/src/go.mod
index f3b6809f..da5fbea7 100644
--- a/src/go.mod
+++ b/src/go.mod
@@ -12,16 +12,16 @@ require (
github.com/gofiber/websocket/v2 v2.2.1
github.com/google/uuid v1.6.0
github.com/lib/pq v1.10.9
- github.com/mark3labs/mcp-go v0.33.0
+ github.com/mark3labs/mcp-go v0.34.0
github.com/mattn/go-sqlite3 v1.14.28
github.com/sirupsen/logrus v1.9.3
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/spf13/cobra v1.9.1
github.com/spf13/viper v1.20.1
github.com/stretchr/testify v1.10.0
- github.com/valyala/fasthttp v1.63.0
+ github.com/valyala/fasthttp v1.64.0
go.mau.fi/libsignal v0.2.0
- go.mau.fi/whatsmeow v0.0.0-20250709212552-0b8557ee0860
+ go.mau.fi/whatsmeow v0.0.0-20250717084138-aecc878ab213
golang.org/x/image v0.29.0
google.golang.org/protobuf v1.36.6
)
@@ -34,7 +34,7 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fasthttp/websocket v1.5.12 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
- github.com/go-viper/mapstructure/v2 v2.3.0 // indirect
+ github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/gofiber/template v1.8.3 // indirect
github.com/gofiber/utils v1.1.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
@@ -53,14 +53,14 @@ require (
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.14.0 // indirect
github.com/spf13/cast v1.9.2 // indirect
- github.com/spf13/pflag v1.0.6 // indirect
+ github.com/spf13/pflag v1.0.7 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
go.mau.fi/util v0.8.8 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.40.0 // indirect
- golang.org/x/exp v0.0.0-20250711185948-6ae5c78190dc // indirect
+ golang.org/x/exp v0.0.0-20250718183923-645b1fa84792 // indirect
golang.org/x/net v0.42.0 // indirect
golang.org/x/sys v0.34.0 // indirect
golang.org/x/text v0.27.0 // indirect
diff --git a/src/go.sum b/src/go.sum
index b8510f86..432490f9 100644
--- a/src/go.sum
+++ b/src/go.sum
@@ -33,6 +33,8 @@ github.com/go-ozzo/ozzo-validation/v4 v4.3.0 h1:byhDUpfEwjsVQb1vBunvIjh2BHQ9ead5
github.com/go-ozzo/ozzo-validation/v4 v4.3.0/go.mod h1:2NKgrcHl3z6cJs+3Oo940FPRiTzuqKbvfrL2RxCj6Ew=
github.com/go-viper/mapstructure/v2 v2.3.0 h1:27XbWsHIqhbdR5TIC911OfYvgSaW93HM+dX7970Q7jk=
github.com/go-viper/mapstructure/v2 v2.3.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
+github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
+github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofiber/fiber/v2 v2.52.8 h1:xl4jJQ0BV5EJTA2aWiKw/VddRpHrKeZLF0QPUxqn0x4=
github.com/gofiber/fiber/v2 v2.52.8/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
@@ -62,6 +64,8 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mark3labs/mcp-go v0.33.0 h1:naxhjnTIs/tyPZmWUZFuG0lDmdA6sUyYGGf3gsHvTCc=
github.com/mark3labs/mcp-go v0.33.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
+github.com/mark3labs/mcp-go v0.34.0 h1:eWy7WBGvhk6EyAAyVzivTCprE52iXJwNtvHV6Cv3bR0=
+github.com/mark3labs/mcp-go v0.34.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
@@ -108,6 +112,8 @@ github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
+github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M=
+github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -121,6 +127,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.63.0 h1:DisIL8OjB7ul2d7cBaMRcKTQDYnrGy56R4FCiuDP0Ns=
github.com/valyala/fasthttp v1.63.0/go.mod h1:REc4IeW+cAEyLrRPa5A81MIjvz0QE1laoTX2EaPHKJM=
+github.com/valyala/fasthttp v1.64.0 h1:QBygLLQmiAyiXuRhthf0tuRkqAFcrC42dckN2S+N3og=
+github.com/valyala/fasthttp v1.64.0/go.mod h1:dGmFxwkWXSK0NbOSJuF7AMVzU+lkHz0wQVvVITv2UQA=
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
@@ -132,6 +140,8 @@ go.mau.fi/util v0.8.8 h1:OnuEEc/sIJFhnq4kFggiImUpcmnmL/xpvQMRu5Fiy5c=
go.mau.fi/util v0.8.8/go.mod h1:Y/kS3loxTEhy8Vill513EtPXr+CRDdae+Xj2BXXMy/c=
go.mau.fi/whatsmeow v0.0.0-20250709212552-0b8557ee0860 h1:0AdAzM/QtzgUKiJ2oyVfiSiZq/fIjxadUtepPy2lZwk=
go.mau.fi/whatsmeow v0.0.0-20250709212552-0b8557ee0860/go.mod h1:bEyyFvXlwr/18B2pOkdX1vWAx1+y1NJX+sCXVyw01UA=
+go.mau.fi/whatsmeow v0.0.0-20250717084138-aecc878ab213 h1:CYkW6OUQk0uvzMa3wN7RtGd7H8DxYdYqw/DoFobTK2w=
+go.mau.fi/whatsmeow v0.0.0-20250717084138-aecc878ab213/go.mod h1:ltDTXUgOAT7LcFKp11H+5S7UY7+xHBMGzNJcv3dLHGk=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -148,6 +158,8 @@ golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/y
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
golang.org/x/exp v0.0.0-20250711185948-6ae5c78190dc h1:TS73t7x3KarrNd5qAipmspBDS1rkMcgVG/fS1aRb4Rc=
golang.org/x/exp v0.0.0-20250711185948-6ae5c78190dc/go.mod h1:A+z0yzpGtvnG90cToK5n2tu8UJVP2XUATh+r+sfOOOc=
+golang.org/x/exp v0.0.0-20250718183923-645b1fa84792 h1:R9PFI6EUdfVKgwKjZef7QIwGcBKu86OEFpJ9nUEP2l4=
+golang.org/x/exp v0.0.0-20250718183923-645b1fa84792/go.mod h1:A+z0yzpGtvnG90cToK5n2tu8UJVP2XUATh+r+sfOOOc=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.28.0 h1:gdem5JW1OLS4FbkWgLO+7ZeFzYtL3xClb97GaUzYMFE=
golang.org/x/image v0.28.0/go.mod h1:GUJYXtnGKEUgggyzh+Vxt+AviiCcyiwpsl8iQ8MvwGY=
diff --git a/src/validations/chat_validation_test.go b/src/validations/chat_validation_test.go
index 009ed40b..643db6ec 100644
--- a/src/validations/chat_validation_test.go
+++ b/src/validations/chat_validation_test.go
@@ -9,6 +9,138 @@ import (
"github.com/stretchr/testify/assert"
)
+func TestValidateListChats(t *testing.T) {
+ type args struct {
+ request domainChat.ListChatsRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with valid request",
+ args: args{request: domainChat.ListChatsRequest{
+ Limit: 25,
+ Offset: 0,
+ }},
+ err: nil,
+ },
+ {
+ name: "should success with zero limit (auto set to default)",
+ args: args{request: domainChat.ListChatsRequest{
+ Limit: 0,
+ Offset: 0,
+ }},
+ err: nil,
+ },
+ {
+ name: "should success with max limit",
+ args: args{request: domainChat.ListChatsRequest{
+ Limit: 100,
+ Offset: 50,
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with limit too high",
+ args: args{request: domainChat.ListChatsRequest{
+ Limit: 101,
+ Offset: 0,
+ }},
+ err: pkgError.ValidationError("limit: must be no greater than 100."),
+ },
+ {
+ name: "should error with negative offset",
+ args: args{request: domainChat.ListChatsRequest{
+ Limit: 25,
+ Offset: -1,
+ }},
+ err: pkgError.ValidationError("offset: must be no less than 0."),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateListChats(context.Background(), &tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
+
+func TestValidateGetChatMessages(t *testing.T) {
+ type args struct {
+ request domainChat.GetChatMessagesRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with valid request",
+ args: args{request: domainChat.GetChatMessagesRequest{
+ ChatJID: "[email protected]",
+ Limit: 50,
+ Offset: 0,
+ }},
+ err: nil,
+ },
+ {
+ name: "should success with zero limit (auto set to default)",
+ args: args{request: domainChat.GetChatMessagesRequest{
+ ChatJID: "[email protected]",
+ Limit: 0,
+ Offset: 0,
+ }},
+ err: nil,
+ },
+ {
+ name: "should success with max limit",
+ args: args{request: domainChat.GetChatMessagesRequest{
+ ChatJID: "[email protected]",
+ Limit: 100,
+ Offset: 50,
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with empty chat_jid",
+ args: args{request: domainChat.GetChatMessagesRequest{
+ ChatJID: "",
+ Limit: 50,
+ Offset: 0,
+ }},
+ err: pkgError.ValidationError("chat_jid: cannot be blank."),
+ },
+ {
+ name: "should error with limit too high",
+ args: args{request: domainChat.GetChatMessagesRequest{
+ ChatJID: "[email protected]",
+ Limit: 101,
+ Offset: 0,
+ }},
+ err: pkgError.ValidationError("limit: must be no greater than 100."),
+ },
+ {
+ name: "should error with negative offset",
+ args: args{request: domainChat.GetChatMessagesRequest{
+ ChatJID: "[email protected]",
+ Limit: 50,
+ Offset: -1,
+ }},
+ err: pkgError.ValidationError("offset: must be no less than 0."),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateGetChatMessages(context.Background(), &tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
+
func TestValidatePinChat(t *testing.T) {
type args struct {
request domainChat.PinChatRequest
diff --git a/src/validations/group_validation_test.go b/src/validations/group_validation_test.go
index 2f16339d..cbbbadf2 100644
--- a/src/validations/group_validation_test.go
+++ b/src/validations/group_validation_test.go
@@ -348,3 +348,361 @@ func TestValidateManageGroupRequestParticipants(t *testing.T) {
})
}
}
+
+func TestValidateGetGroupInfoFromLink(t *testing.T) {
+ type args struct {
+ request domainGroup.GetGroupInfoFromLinkRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with valid link",
+ args: args{request: domainGroup.GetGroupInfoFromLinkRequest{
+ Link: "https://chat.whatsapp.com/ABC123XYZ",
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with empty link",
+ args: args{request: domainGroup.GetGroupInfoFromLinkRequest{
+ Link: "",
+ }},
+ err: pkgError.ValidationError("link: cannot be blank."),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateGetGroupInfoFromLink(context.Background(), tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
+
+func TestValidateSetGroupPhoto(t *testing.T) {
+ type args struct {
+ request domainGroup.SetGroupPhotoRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with valid group id and nil photo",
+ args: args{request: domainGroup.SetGroupPhotoRequest{
+ GroupID: "[email protected]",
+ Photo: nil,
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with empty group id",
+ args: args{request: domainGroup.SetGroupPhotoRequest{
+ GroupID: "",
+ Photo: nil,
+ }},
+ err: pkgError.ValidationError("group_id: cannot be blank."),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateSetGroupPhoto(context.Background(), tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
+
+func TestIsImageContentType(t *testing.T) {
+ tests := []struct {
+ name string
+ contentType string
+ expected bool
+ }{
+ {
+ name: "should return true for image/jpeg",
+ contentType: "image/jpeg",
+ expected: true,
+ },
+ {
+ name: "should return true for image/jpg",
+ contentType: "image/jpg",
+ expected: true,
+ },
+ {
+ name: "should return true for image/png",
+ contentType: "image/png",
+ expected: true,
+ },
+ {
+ name: "should return true for image/gif",
+ contentType: "image/gif",
+ expected: true,
+ },
+ {
+ name: "should return true for image/webp",
+ contentType: "image/webp",
+ expected: true,
+ },
+ {
+ name: "should return false for text/plain",
+ contentType: "text/plain",
+ expected: false,
+ },
+ {
+ name: "should return false for application/pdf",
+ contentType: "application/pdf",
+ expected: false,
+ },
+ {
+ name: "should return false for empty string",
+ contentType: "",
+ expected: false,
+ },
+ {
+ name: "should return false for video/mp4",
+ contentType: "video/mp4",
+ expected: false,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ result := isImageContentType(tt.contentType)
+ assert.Equal(t, tt.expected, result)
+ })
+ }
+}
+
+func TestValidateSetGroupName(t *testing.T) {
+ type args struct {
+ request domainGroup.SetGroupNameRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with valid group id and name",
+ args: args{request: domainGroup.SetGroupNameRequest{
+ GroupID: "[email protected]",
+ Name: "Test Group Name",
+ }},
+ err: nil,
+ },
+ {
+ name: "should success with single character name",
+ args: args{request: domainGroup.SetGroupNameRequest{
+ GroupID: "[email protected]",
+ Name: "A",
+ }},
+ err: nil,
+ },
+ {
+ name: "should success with 25 character name",
+ args: args{request: domainGroup.SetGroupNameRequest{
+ GroupID: "[email protected]",
+ Name: "1234567890123456789012345",
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with empty group id",
+ args: args{request: domainGroup.SetGroupNameRequest{
+ GroupID: "",
+ Name: "Test Group",
+ }},
+ err: pkgError.ValidationError("group_id: cannot be blank."),
+ },
+ {
+ name: "should error with empty name",
+ args: args{request: domainGroup.SetGroupNameRequest{
+ GroupID: "[email protected]",
+ Name: "",
+ }},
+ err: pkgError.ValidationError("name: cannot be blank."),
+ },
+ {
+ name: "should error with name too long",
+ args: args{request: domainGroup.SetGroupNameRequest{
+ GroupID: "[email protected]",
+ Name: "12345678901234567890123456",
+ }},
+ err: pkgError.ValidationError("name: the length must be between 1 and 25."),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateSetGroupName(context.Background(), tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
+
+func TestValidateSetGroupLocked(t *testing.T) {
+ type args struct {
+ request domainGroup.SetGroupLockedRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with valid group id and locked true",
+ args: args{request: domainGroup.SetGroupLockedRequest{
+ GroupID: "[email protected]",
+ Locked: true,
+ }},
+ err: nil,
+ },
+ {
+ name: "should success with valid group id and locked false",
+ args: args{request: domainGroup.SetGroupLockedRequest{
+ GroupID: "[email protected]",
+ Locked: false,
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with empty group id",
+ args: args{request: domainGroup.SetGroupLockedRequest{
+ GroupID: "",
+ Locked: true,
+ }},
+ err: pkgError.ValidationError("group_id: cannot be blank."),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateSetGroupLocked(context.Background(), tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
+
+func TestValidateSetGroupAnnounce(t *testing.T) {
+ type args struct {
+ request domainGroup.SetGroupAnnounceRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with valid group id and announce true",
+ args: args{request: domainGroup.SetGroupAnnounceRequest{
+ GroupID: "[email protected]",
+ Announce: true,
+ }},
+ err: nil,
+ },
+ {
+ name: "should success with valid group id and announce false",
+ args: args{request: domainGroup.SetGroupAnnounceRequest{
+ GroupID: "[email protected]",
+ Announce: false,
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with empty group id",
+ args: args{request: domainGroup.SetGroupAnnounceRequest{
+ GroupID: "",
+ Announce: true,
+ }},
+ err: pkgError.ValidationError("group_id: cannot be blank."),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateSetGroupAnnounce(context.Background(), tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
+
+func TestValidateSetGroupTopic(t *testing.T) {
+ type args struct {
+ request domainGroup.SetGroupTopicRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with valid group id and topic",
+ args: args{request: domainGroup.SetGroupTopicRequest{
+ GroupID: "[email protected]",
+ Topic: "This is a test topic",
+ }},
+ err: nil,
+ },
+ {
+ name: "should success with valid group id and empty topic",
+ args: args{request: domainGroup.SetGroupTopicRequest{
+ GroupID: "[email protected]",
+ Topic: "",
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with empty group id",
+ args: args{request: domainGroup.SetGroupTopicRequest{
+ GroupID: "",
+ Topic: "Test topic",
+ }},
+ err: pkgError.ValidationError("group_id: cannot be blank."),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateSetGroupTopic(context.Background(), tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
+
+func TestValidateGroupInfo(t *testing.T) {
+ type args struct {
+ request domainGroup.GroupInfoRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with valid group id",
+ args: args{request: domainGroup.GroupInfoRequest{
+ GroupID: "[email protected]",
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with empty group id",
+ args: args{request: domainGroup.GroupInfoRequest{
+ GroupID: "",
+ }},
+ err: pkgError.ValidationError("group_id: cannot be blank."),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateGroupInfo(context.Background(), tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
diff --git a/src/validations/send_validation_test.go b/src/validations/send_validation_test.go
index b844689f..03d0e522 100644
--- a/src/validations/send_validation_test.go
+++ b/src/validations/send_validation_test.go
@@ -815,3 +815,294 @@ func TestValidateSendPresence(t *testing.T) {
})
}
}
+
+func TestValidateSendChatPresence(t *testing.T) {
+ type args struct {
+ request domainSend.ChatPresenceRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with start action",
+ args: args{request: domainSend.ChatPresenceRequest{
+ Phone: "[email protected]",
+ Action: "start",
+ }},
+ err: nil,
+ },
+ {
+ name: "should success with stop action",
+ args: args{request: domainSend.ChatPresenceRequest{
+ Phone: "[email protected]",
+ Action: "stop",
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with empty phone",
+ args: args{request: domainSend.ChatPresenceRequest{
+ Phone: "",
+ Action: "start",
+ }},
+ err: pkgError.ValidationError("phone: cannot be blank."),
+ },
+ {
+ name: "should error with empty action",
+ args: args{request: domainSend.ChatPresenceRequest{
+ Phone: "[email protected]",
+ Action: "",
+ }},
+ err: pkgError.ValidationError("action: cannot be blank."),
+ },
+ {
+ name: "should error with invalid action",
+ args: args{request: domainSend.ChatPresenceRequest{
+ Phone: "[email protected]",
+ Action: "invalid",
+ }},
+ err: pkgError.ValidationError("action: must be a valid value."),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateSendChatPresence(context.Background(), tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
+
+func TestValidateDuration(t *testing.T) {
+ tests := []struct {
+ name string
+ duration *int
+ err any
+ }{
+ {
+ name: "should success with nil duration",
+ duration: nil,
+ err: nil,
+ },
+ {
+ name: "should success with zero duration",
+ duration: func() *int { d := 0; return &d }(),
+ err: nil,
+ },
+ {
+ name: "should success with valid duration",
+ duration: func() *int { d := 3600; return &d }(),
+ err: nil,
+ },
+ {
+ name: "should success with max duration",
+ duration: func() *int { d := int(maxDuration); return &d }(),
+ err: nil,
+ },
+ {
+ name: "should error with negative duration",
+ duration: func() *int { d := -1; return &d }(),
+ err: pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)"),
+ },
+ {
+ name: "should error with duration too high",
+ duration: func() *int { d := int(maxDuration) + 1; return &d }(),
+ err: pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)"),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := validateDuration(tt.duration)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
+
+func TestValidateSendMessage_WithDuration(t *testing.T) {
+ type args struct {
+ request domainSend.MessageRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with valid duration",
+ args: args{request: domainSend.MessageRequest{
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ Duration: func() *int { d := 3600; return &d }(),
+ },
+ Message: "Hello this is testing",
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with invalid duration",
+ args: args{request: domainSend.MessageRequest{
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ Duration: func() *int { d := -1; return &d }(),
+ },
+ Message: "Hello this is testing",
+ }},
+ err: pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)"),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateSendMessage(context.Background(), tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
+
+func TestValidateSendImage_WithImageURL(t *testing.T) {
+ type args struct {
+ request domainSend.ImageRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with image URL",
+ args: args{request: domainSend.ImageRequest{
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
+ Caption: "Hello this is testing",
+ ImageURL: func() *string { s := "https://example.com/image.jpg"; return &s }(),
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with empty image URL",
+ args: args{request: domainSend.ImageRequest{
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
+ Caption: "Hello this is testing",
+ ImageURL: func() *string { s := ""; return &s }(),
+ }},
+ err: pkgError.ValidationError("either Image or ImageURL must be provided"),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateSendImage(context.Background(), tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
+
+func TestValidateSendFile_WithDuration(t *testing.T) {
+ file := &multipart.FileHeader{
+ Filename: "sample-file.pdf",
+ Size: 100,
+ Header: map[string][]string{"Content-Type": {"application/pdf"}},
+ }
+
+ type args struct {
+ request domainSend.FileRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with valid duration",
+ args: args{request: domainSend.FileRequest{
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ Duration: func() *int { d := 3600; return &d }(),
+ },
+ File: file,
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with invalid duration",
+ args: args{request: domainSend.FileRequest{
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ Duration: func() *int { d := -1; return &d }(),
+ },
+ File: file,
+ }},
+ err: pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)"),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateSendFile(context.Background(), tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
+
+func TestValidateSendAudio_WithDuration(t *testing.T) {
+ audio := &multipart.FileHeader{
+ Filename: "sample-audio.mp3",
+ Size: 100,
+ Header: map[string][]string{"Content-Type": {"audio/mpeg"}},
+ }
+
+ type args struct {
+ request domainSend.AudioRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with valid duration and audio file",
+ args: args{request: domainSend.AudioRequest{
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ Duration: func() *int { d := 3600; return &d }(),
+ },
+ Audio: audio,
+ }},
+ err: nil,
+ },
+ {
+ name: "should success with audio URL",
+ args: args{request: domainSend.AudioRequest{
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
+ AudioURL: func() *string { s := "https://example.com/audio.mp3"; return &s }(),
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with invalid duration",
+ args: args{request: domainSend.AudioRequest{
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ Duration: func() *int { d := -1; return &d }(),
+ },
+ Audio: audio,
+ }},
+ err: pkgError.ValidationError("duration must be between 0 and 4294967295 seconds (0 means no expiry)"),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateSendAudio(context.Background(), tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}
diff --git a/src/validations/user_validation_test.go b/src/validations/user_validation_test.go
index 95b7a16d..16f58fd4 100644
--- a/src/validations/user_validation_test.go
+++ b/src/validations/user_validation_test.go
@@ -77,3 +77,36 @@ func TestValidateUserInfo(t *testing.T) {
})
}
}
+
+func TestValidateBusinessProfile(t *testing.T) {
+ type args struct {
+ request domainUser.BusinessProfileRequest
+ }
+ tests := []struct {
+ name string
+ args args
+ err any
+ }{
+ {
+ name: "should success with valid phone",
+ args: args{request: domainUser.BusinessProfileRequest{
+ Phone: "[email protected]",
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with empty phone",
+ args: args{request: domainUser.BusinessProfileRequest{
+ Phone: "",
+ }},
+ err: pkgError.ValidationError("phone: cannot be blank."),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := ValidateBusinessProfile(context.Background(), tt.args.request)
+ assert.Equal(t, tt.err, err)
+ })
+ }
+}