1
0
mirror of synced 2024-11-26 21:56:02 +03:00

update for order & products, minor fixes

This commit is contained in:
Alex Lushpai 2018-09-19 16:34:13 +03:00
parent 286591e98e
commit cc6407c000
4 changed files with 4 additions and 116 deletions

1
Jenkinsfile vendored
View File

@ -17,7 +17,6 @@ pipeline {
steps { steps {
sh 'cp config_test.yml.dist config_test.yml' sh 'cp config_test.yml.dist config_test.yml'
compose 'up -d --build postgres_test' compose 'up -d --build postgres_test'
compose 'run --rm mg_telegram_test make migrate_test'
} }
} }

View File

@ -19,7 +19,7 @@ test: deps fmt
@echo "==> Running tests" @echo "==> Running tests"
@cd $(ROOT_DIR) && go test ./... -v -cpu 2 @cd $(ROOT_DIR) && go test ./... -v -cpu 2
jenkins_test: deps jenkins_test: migrate_test
@echo "==> Running tests (result in test-report.xml)" @echo "==> Running tests (result in test-report.xml)"
@go get -v -u github.com/jstemmer/go-junit-report @go get -v -u github.com/jstemmer/go-junit-report
@go test ./... -v -cpu 2 -race | /go/bin/go-junit-report -set-exit-code > ./test-report.xml @go test ./... -v -cpu 2 -race | /go/bin/go-junit-report -set-exit-code > ./test-report.xml

View File

@ -507,7 +507,6 @@ func mgWebhookHandler(c *gin.Context) {
) )
} }
<<<<<<< 01b5fb405bad7411afb6523c9308deaf25e20f6f
if msg.Data.Product.Url != "" { if msg.Data.Product.Url != "" {
mb += msg.Data.Product.Url mb += msg.Data.Product.Url
} else { } else {
@ -531,43 +530,12 @@ func mgWebhookHandler(c *gin.Context) {
} }
} }
=======
if msg.Data.Product.Img != "" {
mb = fmt.Sprintf("\n%s", msg.Data.Product.Img)
}
} else if msg.Data.Type == v1.MsgTypeOrder {
mb = "**Заказ"
if msg.Data.Order.Number != ""{
mb += " " + msg.Data.Order.Number
}
if msg.Data.Order.Date != "" {
mb += fmt.Sprintf(" (%s)", msg.Data.Order.Date)
}
mb += "**\n"
if len(msg.Data.Order.Items) > 0 {
for _, v := range msg.Data.Order.Items {
mb += fmt.Sprintf("%s %v x %v %s\n", v.Name, v.Quantity.Value, v.Price.Value, currency[strings.ToLower(v.Price.Currency)])
}
}
>>>>>>> orders & products
mb += fmt.Sprintf("Сумма: %v %s", msg.Data.Order.Cost.Value, currency[strings.ToLower(msg.Data.Order.Cost.Currency)]) mb += fmt.Sprintf("Сумма: %v %s", msg.Data.Order.Cost.Value, currency[strings.ToLower(msg.Data.Order.Cost.Currency)])
} else { } else {
mb = msg.Data.Content mb = msg.Data.Content
} }
m := tgbotapi.NewMessage(cid, mb) m := tgbotapi.NewMessage(cid, mb)
<<<<<<< 01b5fb405bad7411afb6523c9308deaf25e20f6f
=======
if msg.Data.Type == v1.MsgTypeProduct || msg.Data.Type == v1.MsgTypeOrder {
m.ParseMode = "Markdown"
}
>>>>>>> orders & products
if msg.Data.QuoteExternalID != "" { if msg.Data.QuoteExternalID != "" {
qid, err := strconv.Atoi(msg.Data.QuoteExternalID) qid, err := strconv.Atoi(msg.Data.QuoteExternalID)
if err != nil { if err != nil {

View File

@ -1,7 +1,9 @@
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
@ -13,6 +15,7 @@ import (
"github.com/h2non/gock" "github.com/h2non/gock"
"github.com/retailcrm/mg-transport-api-client-go/v1" "github.com/retailcrm/mg-transport-api-client-go/v1"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
var router *gin.Engine var router *gin.Engine
@ -50,7 +53,6 @@ func TestRouting_connectHandler(t *testing.T) {
fmt.Sprintf("handler returned wrong status code: got %v want %v", rr.Code, http.StatusOK)) fmt.Sprintf("handler returned wrong status code: got %v want %v", rr.Code, http.StatusOK))
} }
<<<<<<< 299f73925e7dbf69e9f07f3d3d064176c999664f
func TestRouting_addBotHandler(t *testing.T) { func TestRouting_addBotHandler(t *testing.T) {
defer gock.Off() defer gock.Off()
@ -130,87 +132,6 @@ func TestRouting_addBotHandler(t *testing.T) {
assert.Equal(t, "123123:Qwerty", res["token"]) assert.Equal(t, "123123:Qwerty", res["token"])
} }
=======
// func TestRouting_addBotHandler(t *testing.T) {
// defer gock.Off()
//
// ch := v1.Channel{
// Type: "telegram",
// Settings: v1.ChannelSettings{
// SpamAllowed: false,
// Status: v1.Status{
// Delivered: v1.ChannelFeatureSend,
// Read: v1.ChannelFeatureNone,
// },
// Text: v1.ChannelSettingsText{
// Creating: v1.ChannelFeatureBoth,
// Editing: v1.ChannelFeatureBoth,
// Quoting: v1.ChannelFeatureBoth,
// Deleting: v1.ChannelFeatureReceive,
// },
// Product: v1.Product{
// Creating: v1.ChannelFeatureReceive,
// Editing: v1.ChannelFeatureReceive,
// },
// Order: v1.Order{
// Creating: v1.ChannelFeatureReceive,
// Editing: v1.ChannelFeatureReceive,
// },
// },
// }
//
// outgoing, _ := json.Marshal(ch)
// p := url.Values{"url": {"https://" + config.HTTPServer.Host + "/telegram/123123:Qwerty"}}
//
// gock.New("https://api.telegram.org").
// Post("/bot123123:Qwerty/getMe").
// Reply(200).
// BodyString(`{"ok":true,"result":{"id":123,"is_bot":true,"first_name":"Test","username":"TestBot"}}`)
//
// gock.New("https://api.telegram.org").
// Post("/bot123123:Qwerty/setWebhook").
// MatchType("url").
// BodyString(p.Encode()).
// Reply(201).
// BodyString(`{"ok":true}`)
//
// gock.New("https://api.telegram.org").
// Post("/bot123123:Qwerty/getWebhookInfo").
// Reply(200).
// 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/transport/v1/channels").
// JSON([]byte(outgoing)).
// MatchHeader("Content-Type", "application/json").
// MatchHeader("X-Transport-Token", "test-token").
// Reply(201).
// BodyString(`{"id": 1}`)
//
// req, err := http.NewRequest("POST", "/add-bot/", strings.NewReader(`{"token": "123123:Qwerty", "connectionId": 1}`))
// if err != nil {
// t.Fatal(err)
// }
// rr := httptest.NewRecorder()
// router.ServeHTTP(rr, req)
// require.Equal(t, http.StatusCreated, rr.Code,
// fmt.Sprintf("handler returned wrong status code: got %v want %v", rr.Code, http.StatusCreated))
//
// bytes, err := ioutil.ReadAll(rr.Body)
// if err != nil {
// t.Fatal(err)
// }
//
// var res map[string]interface{}
//
// err = json.Unmarshal(bytes, &res)
// if err != nil {
// t.Fatal(err)
// }
//
// assert.Equal(t, "123123:Qwerty", res["token"])
// }
>>>>>>> tests
func TestRouting_deleteBotHandler(t *testing.T) { func TestRouting_deleteBotHandler(t *testing.T) {
defer gock.Off() defer gock.Off()