1
0
mirror of synced 2024-11-22 04:26:01 +03:00

Merge branch 'devel'

This commit is contained in:
DmitryZagorulko 2018-05-31 18:18:16 +03:00
commit 8a98432800
2 changed files with 10 additions and 45 deletions

View File

@ -180,22 +180,24 @@ func addBotHandler(w http.ResponseWriter, r *http.Request) {
},
}
var client = v1.New(cb.MGURL, cb.MGToken)
c := getConnectionById(b.ConnectionID)
var client = v1.New(c.MGURL, c.MGToken)
data, status, err := client.ActivateTransportChannel(ch)
if status != http.StatusCreated {
http.Error(w, localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "error_activating_channel"}), http.StatusBadRequest)
logger.Error(cb.APIURL, status, err.Error(), data)
logger.Error(c.APIURL, status, err.Error(), data)
return
}
b.Channel = data.ChannelID
b.Active = true
err = cb.createBot(b)
err = c.createBot(b)
if err != nil {
raven.CaptureErrorAndWait(err, nil)
http.Error(w, localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "error_adding_bot"}), http.StatusInternalServerError)
logger.Error(cb.APIURL, err.Error())
logger.Error(c.APIURL, err.Error())
return
}
@ -203,7 +205,7 @@ func addBotHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
raven.CaptureErrorAndWait(err, nil)
http.Error(w, localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "error_adding_bot"}), http.StatusInternalServerError)
logger.Error(cb.APIURL, err.Error())
logger.Error(c.APIURL, err.Error())
return
}

View File

@ -7,14 +7,12 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"sort"
"strings"
"testing"
"github.com/h2non/gock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
)
func init() {
@ -33,7 +31,7 @@ func init() {
}
c.createConnection()
orm.DB.Where("token = 123123:Qwerty").Delete(Bot{})
orm.DB.Delete(Bot{}, "token = ?", "123123:Qwerty")
}
func TestRouting_connectHandler(t *testing.T) {
@ -53,7 +51,7 @@ func TestRouting_connectHandler(t *testing.T) {
func TestRouting_addBotHandler(t *testing.T) {
defer gock.Off()
p := url.Values{"url": {"https://test.com/telegram/123123:Qwerty"}}
p := url.Values{"url": {"https://" + config.HTTPServer.Host + "/telegram/123123:Qwerty"}}
gock.New("https://api.telegram.org").
Post("/bot123123:Qwerty/getMe").
@ -70,7 +68,7 @@ func TestRouting_addBotHandler(t *testing.T) {
gock.New("https://api.telegram.org").
Post("/bot123123:Qwerty/getWebhookInfo").
Reply(200).
BodyString(`{"ok":true,"result":{"url":"https://test.com/telegram/123123:Qwerty","has_custom_certificate":false,"pending_update_count":0}}`)
BodyString(`{"ok":true,"result":{"url":"https://` + config.HTTPServer.Host + `/telegram/123123:Qwerty","has_custom_certificate":false,"pending_update_count":0}}`)
gock.New("https://test.retailcrm.pro").
Post("/api/v1/transport/channels").
@ -185,38 +183,3 @@ func TestRouting_activityHandler(t *testing.T) {
assert.Equal(t, http.StatusOK, rr.Code,
fmt.Sprintf("handler returned wrong status code: got %v want %v", rr.Code, http.StatusOK))
}
func TestRouting_TranslateLoader(t *testing.T) {
type m map[string]string
te := [][]string{}
dt := "translate"
files, err := ioutil.ReadDir(dt)
if err != nil {
t.Fatal(err)
}
for _, f := range files {
ms := m{}
if !f.IsDir() {
res, err := ioutil.ReadFile(fmt.Sprintf("%s/%s", dt, f.Name()))
if err != nil {
t.Fatal(err)
}
err = yaml.Unmarshal(res, &ms)
if err != nil {
t.Fatal(err)
}
keys := []string{}
for kms := range ms {
keys = append(keys, kms)
}
sort.Strings(keys)
te = append(te, keys)
}
}
}