package channel import ( "testing" "github.com/stretchr/testify/assert" "github.com/gochat/gochat/internal/model" ) // --- ChannelBase Tests --- func TestChannelBase_TableName(t *testing.T) { assert.Equal(t, "channels", ChannelBase{}.TableName()) } func TestChannelBase_Fields(t *testing.T) { cb := ChannelBase{ ID: 1, AccountID: 10, InboxID: 20, ChannelType: "telegram", } assert.Equal(t, uint(1), cb.ID) assert.Equal(t, uint(10), cb.AccountID) assert.Equal(t, uint(20), cb.InboxID) assert.Equal(t, "telegram", cb.ChannelType) } // --- ChannelAPI Tests --- func TestChannelAPI_TableName(t *testing.T) { assert.Equal(t, "channel_api", ChannelAPI{}.TableName()) } func TestChannelAPI_GetInboxID(t *testing.T) { c := ChannelAPI{InboxID: 42} assert.Equal(t, uint(42), c.GetInboxID()) } func TestChannelAPI_GetChannelType(t *testing.T) { c := ChannelAPI{} assert.Equal(t, model.InboxChannelTypeAPI, c.GetChannelType()) } // --- ChannelEmail Tests --- func TestChannelEmail_TableName(t *testing.T) { assert.Equal(t, "channel_emails", ChannelEmail{}.TableName()) } func TestChannelEmail_GetChannelBase(t *testing.T) { c := &ChannelEmail{ AccountID: 5, InboxID: 10, } cb := c.GetChannelBase() assert.Equal(t, uint(5), cb.AccountID) assert.Equal(t, uint(10), cb.InboxID) assert.Equal(t, "email", cb.ChannelType) } func TestChannelEmail_GetChannelType(t *testing.T) { c := &ChannelEmail{} assert.Equal(t, "email", c.GetChannelType()) } func TestChannelEmail_IsIMAPConfigured_True(t *testing.T) { c := &ChannelEmail{ IMAPEnabled: true, IMAPAddress: "imap.gmail.com", IMAPLogin: "user@gmail.com", IMAPPassword: "password", } assert.True(t, c.IsIMAPConfigured()) } func TestChannelEmail_IsIMAPConfigured_False_NotEnabled(t *testing.T) { c := &ChannelEmail{ IMAPAddress: "imap.gmail.com", IMAPLogin: "user@gmail.com", IMAPPassword: "password", } assert.False(t, c.IsIMAPConfigured()) } func TestChannelEmail_IsIMAPConfigured_False_NoAddress(t *testing.T) { c := &ChannelEmail{ IMAPEnabled: true, IMAPLogin: "user@gmail.com", IMAPPassword: "password", } assert.False(t, c.IsIMAPConfigured()) } func TestChannelEmail_IsIMAPConfigured_False_NoLogin(t *testing.T) { c := &ChannelEmail{ IMAPEnabled: true, IMAPAddress: "imap.gmail.com", IMAPPassword: "password", } assert.False(t, c.IsIMAPConfigured()) } func TestChannelEmail_IsIMAPConfigured_False_NoPassword(t *testing.T) { c := &ChannelEmail{ IMAPEnabled: true, IMAPAddress: "imap.gmail.com", IMAPLogin: "user@gmail.com", } assert.False(t, c.IsIMAPConfigured()) } func TestChannelEmail_IsSMTPConfigured_True(t *testing.T) { c := &ChannelEmail{ SMTPEnabled: true, SMTPAddress: "smtp.gmail.com", SMTPLogin: "user@gmail.com", SMTPPassword: "password", } assert.True(t, c.IsSMTPConfigured()) } func TestChannelEmail_IsSMTPConfigured_False_NotEnabled(t *testing.T) { c := &ChannelEmail{ SMTPAddress: "smtp.gmail.com", SMTPLogin: "user@gmail.com", SMTPPassword: "password", } assert.False(t, c.IsSMTPConfigured()) } func TestChannelEmail_IsSMTPConfigured_False_NoAddress(t *testing.T) { c := &ChannelEmail{ SMTPEnabled: true, SMTPLogin: "user@gmail.com", SMTPPassword: "password", } assert.False(t, c.IsSMTPConfigured()) } func TestChannelEmail_IsSMTPConfigured_False_NoLogin(t *testing.T) { c := &ChannelEmail{ SMTPEnabled: true, SMTPAddress: "smtp.gmail.com", SMTPPassword: "password", } assert.False(t, c.IsSMTPConfigured()) } func TestChannelEmail_IsSMTPConfigured_False_NoPassword(t *testing.T) { c := &ChannelEmail{ SMTPEnabled: true, SMTPAddress: "smtp.gmail.com", SMTPLogin: "user@gmail.com", } assert.False(t, c.IsSMTPConfigured()) } func TestChannelEmail_IMAPConnectionString_Configured(t *testing.T) { c := &ChannelEmail{ IMAPEnabled: true, IMAPAddress: "imap.gmail.com", IMAPLogin: "user@gmail.com", IMAPPassword: "password", IMAPPort: 993, } str := c.IMAPConnectionString() assert.Equal(t, "user@gmail.com@imap.gmail.com:993", str) } func TestChannelEmail_IMAPConnectionString_NotConfigured(t *testing.T) { c := &ChannelEmail{} str := c.IMAPConnectionString() assert.Equal(t, "IMAP not configured", str) } func TestChannelEmail_SMTPConnectionString_Configured(t *testing.T) { c := &ChannelEmail{ SMTPEnabled: true, SMTPAddress: "smtp.gmail.com", SMTPLogin: "user@gmail.com", SMTPPassword: "password", SMTPPort: 587, } str := c.SMTPConnectionString() assert.Equal(t, "user@gmail.com@smtp.gmail.com:587", str) } func TestChannelEmail_SMTPConnectionString_NotConfigured(t *testing.T) { c := &ChannelEmail{} str := c.SMTPConnectionString() assert.Equal(t, "SMTP not configured", str) } func TestFormatPort_Zero(t *testing.T) { assert.Equal(t, "default", formatPort(0)) } func TestFormatPort_NonZero(t *testing.T) { assert.Equal(t, "993", formatPort(993)) assert.Equal(t, "587", formatPort(587)) } // --- ChannelFacebook Tests --- func TestChannelFacebook_TableName(t *testing.T) { assert.Equal(t, "channel_facebook_pages", ChannelFacebook{}.TableName()) } func TestChannelFacebook_GetChannelBase(t *testing.T) { c := &ChannelFacebook{ AccountID: 1, InboxID: 2, } cb := c.GetChannelBase() assert.Equal(t, uint(1), cb.AccountID) assert.Equal(t, uint(2), cb.InboxID) assert.Equal(t, "facebook", cb.ChannelType) } func TestChannelFacebook_GetChannelType(t *testing.T) { c := &ChannelFacebook{} assert.Equal(t, "facebook", c.GetChannelType()) } // --- ChannelGoogle Tests --- func TestChannelGoogle_TableName(t *testing.T) { assert.Equal(t, "channel_google", ChannelGoogle{}.TableName()) } func TestChannelGoogle_GetChannelBase(t *testing.T) { c := ChannelGoogle{ Base: model.Base{ID: 5}, AccountID: 1, InboxID: 2, } cb := c.GetChannelBase() assert.Equal(t, uint(5), cb.ID) assert.Equal(t, uint(1), cb.AccountID) assert.Equal(t, uint(2), cb.InboxID) assert.Equal(t, "google", cb.ChannelType) } func TestChannelGoogle_GetChannelType(t *testing.T) { c := ChannelGoogle{} assert.Equal(t, "google", c.GetChannelType()) } // --- ChannelInstagram Tests --- func TestChannelInstagram_TableName(t *testing.T) { assert.Equal(t, "channel_instagrams", ChannelInstagram{}.TableName()) } func TestChannelInstagram_GetChannelBase(t *testing.T) { c := &ChannelInstagram{ AccountID: 1, InboxID: 2, } cb := c.GetChannelBase() assert.Equal(t, uint(1), cb.AccountID) assert.Equal(t, uint(2), cb.InboxID) assert.Equal(t, "instagram", cb.ChannelType) } func TestChannelInstagram_GetChannelType(t *testing.T) { c := &ChannelInstagram{} assert.Equal(t, "instagram", c.GetChannelType()) } // --- ChannelLINE Tests --- func TestChannelLINE_TableName(t *testing.T) { assert.Equal(t, "channel_lines", ChannelLINE{}.TableName()) } func TestChannelLINE_GetChannelType(t *testing.T) { c := &ChannelLINE{} assert.Equal(t, "line", c.GetChannelType()) } func TestChannelLINE_GetChannelID(t *testing.T) { c := &ChannelLINE{ChannelID: "12345"} assert.Equal(t, "12345", c.GetChannelID()) } func TestChannelLINE_GetName(t *testing.T) { c := &ChannelLINE{Name: "My LINE Account"} assert.Equal(t, "My LINE Account", c.GetName()) } func TestChannelLINE_GetAccountID(t *testing.T) { c := &ChannelLINE{AccountID: 42} assert.Equal(t, uint(42), c.GetAccountID()) } func TestChannelLINE_GetInboxID(t *testing.T) { c := &ChannelLINE{InboxID: 99} assert.Equal(t, uint(99), c.GetInboxID()) } func TestChannelLINE_SetInboxID(t *testing.T) { c := &ChannelLINE{} c.SetInboxID(77) assert.Equal(t, uint(77), c.InboxID) } // --- ChannelMicrosoft Tests --- func TestChannelMicrosoft_TableName(t *testing.T) { assert.Equal(t, "channel_microsoft", ChannelMicrosoft{}.TableName()) } func TestChannelMicrosoft_GetChannelBase(t *testing.T) { c := ChannelMicrosoft{ Base: model.Base{ID: 3}, AccountID: 1, InboxID: 2, } cb := c.GetChannelBase() assert.Equal(t, uint(3), cb.ID) assert.Equal(t, uint(1), cb.AccountID) assert.Equal(t, uint(2), cb.InboxID) assert.Equal(t, "microsoft", cb.ChannelType) } func TestChannelMicrosoft_GetChannelType(t *testing.T) { c := ChannelMicrosoft{} assert.Equal(t, "microsoft", c.GetChannelType()) } // --- ChannelTelegram Tests --- func TestChannelTelegram_TableName(t *testing.T) { assert.Equal(t, "channel_telegrams", ChannelTelegram{}.TableName()) } func TestChannelTelegram_GetChannelBase(t *testing.T) { ct := &ChannelTelegram{ Base: model.Base{ID: 1}, AccountID: 10, InboxID: 20, } cb := ct.GetChannelBase() assert.Equal(t, uint(1), cb.ID) assert.Equal(t, uint(10), cb.AccountID) assert.Equal(t, uint(20), cb.InboxID) assert.Equal(t, "telegram", cb.ChannelType) } func TestChannelTelegram_GetChannelType(t *testing.T) { ct := &ChannelTelegram{} assert.Equal(t, "telegram", ct.GetChannelType()) } // --- ChannelTikTok Tests --- func TestChannelTikTok_TableName(t *testing.T) { assert.Equal(t, "channel_tiktoks", ChannelTikTok{}.TableName()) } func TestChannelTikTok_GetChannelBase(t *testing.T) { c := ChannelTikTok{ Base: model.Base{ID: 7}, AccountID: 1, InboxID: 2, } cb := c.GetChannelBase() assert.Equal(t, uint(7), cb.ID) assert.Equal(t, uint(1), cb.AccountID) assert.Equal(t, uint(2), cb.InboxID) assert.Equal(t, "tiktok", cb.ChannelType) } func TestChannelTikTok_GetChannelType(t *testing.T) { c := ChannelTikTok{} assert.Equal(t, "tiktok", c.GetChannelType()) } // --- ChannelTwilioSMS Tests --- func TestChannelTwilioSMS_TableName(t *testing.T) { assert.Equal(t, "channel_twilio_sms", ChannelTwilioSMS{}.TableName()) } func TestChannelTwilioSMS_GetChannelType(t *testing.T) { c := &ChannelTwilioSMS{} assert.Equal(t, "twilio_sms", c.GetChannelType()) } func TestChannelTwilioSMS_GetChannelID(t *testing.T) { c := &ChannelTwilioSMS{AccountSID: "AC123"} assert.Equal(t, "AC123", c.GetChannelID()) } func TestChannelTwilioSMS_GetName(t *testing.T) { c := &ChannelTwilioSMS{PhoneNumber: "+1234567890"} assert.Equal(t, "+1234567890", c.GetName()) } func TestChannelTwilioSMS_GetAccountID(t *testing.T) { c := &ChannelTwilioSMS{AccountID: 5} assert.Equal(t, uint(5), c.GetAccountID()) } func TestChannelTwilioSMS_GetInboxID(t *testing.T) { c := &ChannelTwilioSMS{InboxID: 10} assert.Equal(t, uint(10), c.GetInboxID()) } func TestChannelTwilioSMS_SetInboxID(t *testing.T) { c := &ChannelTwilioSMS{} c.SetInboxID(99) assert.Equal(t, uint(99), c.InboxID) } // --- ChannelTwitter Tests --- func TestChannelTwitter_TableName(t *testing.T) { assert.Equal(t, "channel_twitter_profiles", ChannelTwitter{}.TableName()) } func TestChannelTwitter_GetChannelBase(t *testing.T) { c := ChannelTwitter{ Base: model.Base{ID: 8}, AccountID: 1, InboxID: 2, } cb := c.GetChannelBase() assert.Equal(t, uint(8), cb.ID) assert.Equal(t, uint(1), cb.AccountID) assert.Equal(t, uint(2), cb.InboxID) assert.Equal(t, "twitter", cb.ChannelType) } func TestChannelTwitter_GetChannelType(t *testing.T) { c := ChannelTwitter{} assert.Equal(t, "twitter", c.GetChannelType()) } // --- ChannelWebWidget Tests --- func TestChannelWebWidget_TableName(t *testing.T) { assert.Equal(t, "channel_web_widgets", ChannelWebWidget{}.TableName()) } // --- ChannelWhatsApp Tests --- func TestChannelWhatsApp_TableName(t *testing.T) { assert.Equal(t, "channel_whatsapps", ChannelWhatsApp{}.TableName()) } func TestChannelWhatsApp_GetChannelBase(t *testing.T) { c := &ChannelWhatsApp{ Base: model.Base{ID: 1}, AccountID: 10, InboxID: 20, } cb := c.GetChannelBase() assert.Equal(t, uint(1), cb.ID) assert.Equal(t, uint(10), cb.AccountID) assert.Equal(t, uint(20), cb.InboxID) assert.Equal(t, "whatsapp", cb.ChannelType) } func TestChannelWhatsApp_GetChannelType(t *testing.T) { c := &ChannelWhatsApp{} assert.Equal(t, "whatsapp", c.GetChannelType()) } func TestChannelWhatsApp_GetInboxID(t *testing.T) { c := &ChannelWhatsApp{InboxID: 42} assert.Equal(t, uint(42), c.GetInboxID()) } func TestChannelWhatsApp_IsCloudAPI_True(t *testing.T) { c := &ChannelWhatsApp{Provider: "whatsapp_cloud"} assert.True(t, c.IsCloudAPI()) } func TestChannelWhatsApp_IsCloudAPI_False(t *testing.T) { c := &ChannelWhatsApp{Provider: "360dialog"} assert.False(t, c.IsCloudAPI()) } func TestChannelWhatsApp_Is360Dialog_True(t *testing.T) { c := &ChannelWhatsApp{Provider: "360dialog"} assert.True(t, c.Is360Dialog()) } func TestChannelWhatsApp_Is360Dialog_False(t *testing.T) { c := &ChannelWhatsApp{Provider: "whatsapp_cloud"} assert.False(t, c.Is360Dialog()) } func TestChannelWhatsApp_IsCloudAPI_Empty(t *testing.T) { c := &ChannelWhatsApp{} assert.False(t, c.IsCloudAPI()) assert.False(t, c.Is360Dialog()) }