From 6120f0b6b9d4c6ec3f8c469dbd24b5d43e3eea6e Mon Sep 17 00:00:00 2001 From: DmitryZagorulko Date: Thu, 31 May 2018 18:17:19 +0300 Subject: [PATCH 1/2] tests --- routing.go | 12 +++++++----- routing_test.go | 43 +++---------------------------------------- 2 files changed, 10 insertions(+), 45 deletions(-) diff --git a/routing.go b/routing.go index edc4a8d..6802706 100644 --- a/routing.go +++ b/routing.go @@ -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 } diff --git a/routing_test.go b/routing_test.go index ef1bb12..7959441 100644 --- a/routing_test.go +++ b/routing_test.go @@ -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) - } - } - -} From bb4724d4654afbaf59c0ebf0283aefec6b362728 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Thu, 31 May 2018 18:21:10 +0300 Subject: [PATCH 2/2] minor fixes --- docker-compose-test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose-test.yml b/docker-compose-test.yml index 7233b5c..60c96e9 100644 --- a/docker-compose-test.yml +++ b/docker-compose-test.yml @@ -21,4 +21,3 @@ services: - postgres_test ports: - ${MG_TELEGRAM_ADDRESS:-3002}:3002 -# command: make migrate_test