feat(inboxes): deepen channel config parity
This commit is contained in:
@@ -243,6 +243,120 @@ func TestInboxHandler_ChatwootCreateUpdateRequestBinding(t *testing.T) {
|
||||
require.Len(t, inboxParityObject(t, showUpdated)["working_hours"].([]any), 7)
|
||||
}
|
||||
|
||||
func TestInboxHandler_ChatwootChannelSpecificConfigDepth(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
|
||||
db, err := gorm.Open(sqlite.Open("file:inbox_handler_channel_depth?mode=memory&cache=shared"), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Silent),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
sqlDB, dbErr := db.DB()
|
||||
if dbErr == nil {
|
||||
_ = sqlDB.Close()
|
||||
}
|
||||
})
|
||||
require.NoError(t, db.AutoMigrate(&model.Account{}, &model.Inbox{}, &model.WorkingHour{}))
|
||||
|
||||
account := &model.Account{Name: "Inbox Channel Depth", Locale: "en", Active: true}
|
||||
require.NoError(t, db.Create(account).Error)
|
||||
router := setupInboxParityRouter(db)
|
||||
|
||||
emailCreate := inboxParityRequest(t, router, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/inboxes/", account.ID), map[string]any{
|
||||
"name": "Email Support",
|
||||
"channel": map[string]any{
|
||||
"type": "email",
|
||||
"email": "support@example.com",
|
||||
"forward_to_email": "support+forward@example.test",
|
||||
"imap_enabled": true,
|
||||
"imap_login": "imap-user",
|
||||
"imap_password": "imap-secret",
|
||||
"imap_address": "imap.example.com",
|
||||
"imap_port": 993,
|
||||
"imap_enable_ssl": true,
|
||||
"imap_authentication": "plain",
|
||||
"smtp_enabled": true,
|
||||
"smtp_login": "smtp-user",
|
||||
"smtp_password": "smtp-secret",
|
||||
"smtp_address": "smtp.example.com",
|
||||
"smtp_port": 587,
|
||||
"smtp_domain": "example.com",
|
||||
"smtp_enable_starttls_auto": true,
|
||||
"smtp_enable_ssl_tls": false,
|
||||
"smtp_openssl_verify_mode": "none",
|
||||
"smtp_authentication": "login",
|
||||
},
|
||||
})
|
||||
require.Equal(t, http.StatusOK, emailCreate.Code, emailCreate.Body.String())
|
||||
emailData := inboxParityObject(t, emailCreate)
|
||||
require.Equal(t, "Channel::Email", emailData["channel_type"])
|
||||
require.Equal(t, "support@example.com", emailData["email"])
|
||||
require.Equal(t, "support+forward@example.test", emailData["forward_to_email"])
|
||||
require.Equal(t, true, emailData["forwarding_enabled"])
|
||||
require.Equal(t, "imap.example.com", emailData["imap_address"])
|
||||
require.Equal(t, float64(993), emailData["imap_port"])
|
||||
require.Equal(t, "smtp.example.com", emailData["smtp_address"])
|
||||
require.Equal(t, float64(587), emailData["smtp_port"])
|
||||
|
||||
emailID := uint(emailData["id"].(float64))
|
||||
smtpUpdate := inboxParityRequest(t, router, http.MethodPatch, fmt.Sprintf("/api/v1/accounts/%d/inboxes/%d", account.ID, emailID), map[string]any{
|
||||
"smtp_enabled": true,
|
||||
"smtp_address": "smtp2.example.com",
|
||||
"smtp_port": 465,
|
||||
"smtp_login": "smtp2-user",
|
||||
"smtp_password": "smtp2-secret",
|
||||
"smtp_domain": "example.org",
|
||||
"smtp_enable_ssl_tls": true,
|
||||
"smtp_enable_starttls_auto": false,
|
||||
"smtp_openssl_verify_mode": "peer",
|
||||
"smtp_authentication": "login",
|
||||
})
|
||||
require.Equal(t, http.StatusOK, smtpUpdate.Code, smtpUpdate.Body.String())
|
||||
smtpData := inboxParityObject(t, smtpUpdate)
|
||||
require.Equal(t, "smtp2.example.com", smtpData["smtp_address"])
|
||||
require.Equal(t, float64(465), smtpData["smtp_port"])
|
||||
require.Equal(t, true, smtpData["smtp_enable_ssl_tls"])
|
||||
require.Equal(t, false, smtpData["smtp_enable_starttls_auto"])
|
||||
|
||||
whatsappCreate := inboxParityRequest(t, router, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/inboxes/", account.ID), map[string]any{
|
||||
"name": "WhatsApp",
|
||||
"channel": map[string]any{
|
||||
"type": "whatsapp",
|
||||
"phone_number": "+1555010000",
|
||||
"provider": "whatsapp_cloud",
|
||||
"provider_config": map[string]any{
|
||||
"api_key": "wa-key",
|
||||
"phone_number_id": "phone-id",
|
||||
"business_account_id": "waba-id",
|
||||
},
|
||||
},
|
||||
})
|
||||
require.Equal(t, http.StatusOK, whatsappCreate.Code, whatsappCreate.Body.String())
|
||||
whatsappData := inboxParityObject(t, whatsappCreate)
|
||||
require.Equal(t, "Channel::Whatsapp", whatsappData["channel_type"])
|
||||
require.Equal(t, "+1555010000", whatsappData["phone_number"])
|
||||
providerConfig := whatsappData["provider_config"].(map[string]any)
|
||||
require.Equal(t, "wa-key", providerConfig["api_key"])
|
||||
require.Equal(t, "phone-id", providerConfig["phone_number_id"])
|
||||
require.NotEmpty(t, providerConfig["webhook_verify_token"])
|
||||
|
||||
lineCreate := inboxParityRequest(t, router, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/inboxes/", account.ID), map[string]any{
|
||||
"name": "LINE",
|
||||
"channel": map[string]any{
|
||||
"type": "line",
|
||||
"line_channel_id": "line-id",
|
||||
"line_channel_secret": "line-secret",
|
||||
"line_channel_token": "line-token",
|
||||
},
|
||||
})
|
||||
require.Equal(t, http.StatusOK, lineCreate.Code, lineCreate.Body.String())
|
||||
lineData := inboxParityObject(t, lineCreate)
|
||||
require.Equal(t, "Channel::Line", lineData["channel_type"])
|
||||
require.Equal(t, "line-id", lineData["line_channel_id"])
|
||||
require.Equal(t, "line-secret", lineData["line_channel_secret"])
|
||||
require.Equal(t, "line-token", lineData["line_channel_token"])
|
||||
}
|
||||
|
||||
func setupInboxParityRouter(db *gorm.DB) *gin.Engine {
|
||||
inboxSvc := service.NewInboxService(repository.NewInboxRepo(db), nil, nil, nil, nil, nil, nil)
|
||||
handler := NewInboxHandler(inboxSvc)
|
||||
|
||||
Reference in New Issue
Block a user