From 11f77c514c386293896f183f7b21094797b24804 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Thu, 29 Nov 2018 12:18:28 +0300 Subject: [PATCH] Update routing_test.go --- src/routing_test.go | 177 -------------------------------------------- 1 file changed, 177 deletions(-) diff --git a/src/routing_test.go b/src/routing_test.go index 0171c77..d33e5cb 100644 --- a/src/routing_test.go +++ b/src/routing_test.go @@ -50,183 +50,6 @@ func TestRouting_connectHandler(t *testing.T) { fmt.Sprintf("handler returned wrong status code: got %v want %v", rr.Code, http.StatusOK)) } -<<<<<<< 299f73925e7dbf69e9f07f3d3d064176c999664f -func TestRouting_addBotHandler(t *testing.T) { - defer gock.Off() - - ch := v1.Channel{ - Type: "telegram", - Name: "@TestBot", - 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, - }, - File: v1.ChannelSettingsFilesBase{ - Creating: v1.ChannelFeatureBoth, - Editing: v1.ChannelFeatureBoth, - Quoting: v1.ChannelFeatureBoth, - Deleting: v1.ChannelFeatureReceive, - Max: 1, - }, - Image: v1.ChannelSettingsFilesBase{ - Creating: v1.ChannelFeatureBoth, - Editing: v1.ChannelFeatureBoth, - Quoting: v1.ChannelFeatureBoth, - Deleting: v1.ChannelFeatureReceive, - Max: 10, - }, - }, - } - - 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"]) -} -======= -// 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) { defer gock.Off()