Add leads handlers, WhatsApp integration, and test files
This commit is contained in:
90
apps/go-crm/internal/db/crud_test.go
Normal file
90
apps/go-crm/internal/db/crud_test.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestClientWhatsAppColumns(t *testing.T) {
|
||||
tmpfile, err := os.CreateTemp("", "test_*.db")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(tmpfile.Name())
|
||||
tmpfile.Close()
|
||||
|
||||
db, err := Init(tmpfile.Name())
|
||||
if err != nil {
|
||||
t.Fatalf("failed to init db: %v", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
client := Client{
|
||||
AccountID: 1,
|
||||
Name: "Test Client",
|
||||
Phone: "+5521987654321",
|
||||
WhatsAppNumber: "+5521987654321",
|
||||
WhatsAppConnected: 1,
|
||||
CreatedAt: 1234567890,
|
||||
}
|
||||
|
||||
if err := client.Create(db); err != nil {
|
||||
t.Fatalf("failed to create client: %v", err)
|
||||
}
|
||||
|
||||
if client.ClientID == 0 {
|
||||
t.Error("expected client_id to be set after create")
|
||||
}
|
||||
|
||||
var found Client
|
||||
if err := found.Read(db, client.ClientID); err != nil {
|
||||
t.Fatalf("failed to read client: %v", err)
|
||||
}
|
||||
|
||||
if found.WhatsAppNumber != "+5521987654321" {
|
||||
t.Errorf("expected whatsapp_number to be +5521987654321, got %s", found.WhatsAppNumber)
|
||||
}
|
||||
|
||||
if found.WhatsAppConnected != 1 {
|
||||
t.Errorf("expected whatsapp_connected to be 1, got %d", found.WhatsAppConnected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientWhatsAppColumnsNullable(t *testing.T) {
|
||||
tmpfile, err := os.CreateTemp("", "test_*.db")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(tmpfile.Name())
|
||||
tmpfile.Close()
|
||||
|
||||
db, err := Init(tmpfile.Name())
|
||||
if err != nil {
|
||||
t.Fatalf("failed to init db: %v", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
client := Client{
|
||||
AccountID: 1,
|
||||
Name: "Test Client",
|
||||
Phone: "+5521987654321",
|
||||
CreatedAt: 1234567890,
|
||||
}
|
||||
|
||||
if err := client.Create(db); err != nil {
|
||||
t.Fatalf("failed to create client: %v", err)
|
||||
}
|
||||
|
||||
var found Client
|
||||
if err := found.Read(db, client.ClientID); err != nil {
|
||||
t.Fatalf("failed to read client: %v", err)
|
||||
}
|
||||
|
||||
if found.WhatsAppNumber != "" {
|
||||
t.Errorf("expected whatsapp_number to be empty, got %s", found.WhatsAppNumber)
|
||||
}
|
||||
|
||||
if found.WhatsAppConnected != 0 {
|
||||
t.Errorf("expected whatsapp_connected to default to 0, got %d", found.WhatsAppConnected)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user