add migrations, correct tests
This commit is contained in:
parent
45a6b478d7
commit
cd6c64e6da
26
migrations/1527515265_app.down.sql
Normal file
26
migrations/1527515265_app.down.sql
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
alter table connection
|
||||||
|
drop constraint connection_client_id_key,
|
||||||
|
drop constraint connection_api_key_key,
|
||||||
|
drop constraint connection_api_url_key,
|
||||||
|
drop constraint connection_mg_url_key;
|
||||||
|
alter table connection
|
||||||
|
alter column client_id drop not null,
|
||||||
|
alter column api_key drop not null,
|
||||||
|
alter column api_url drop not null;
|
||||||
|
|
||||||
|
alter table bot
|
||||||
|
alter column connection_id type varchar(70),
|
||||||
|
alter column token drop not null,
|
||||||
|
drop constraint bot_token_key;
|
||||||
|
|
||||||
|
alter table bot
|
||||||
|
rename column connection_id to client_id;
|
||||||
|
|
||||||
|
create table mapping
|
||||||
|
(
|
||||||
|
id serial not null
|
||||||
|
constraint mapping_pkey
|
||||||
|
primary key,
|
||||||
|
site_code text,
|
||||||
|
bot_id text
|
||||||
|
);
|
19
migrations/1527515265_app.up.sql
Normal file
19
migrations/1527515265_app.up.sql
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
alter table connection
|
||||||
|
add constraint connection_client_id_key unique (api_key),
|
||||||
|
add constraint connection_api_key_key unique (api_url),
|
||||||
|
add constraint connection_api_url_key unique (mg_url),
|
||||||
|
add constraint connection_mg_url_key unique (mg_token);
|
||||||
|
alter table connection
|
||||||
|
alter column client_id set not null,
|
||||||
|
alter column api_key set not null,
|
||||||
|
alter column api_url set not null;
|
||||||
|
|
||||||
|
alter table bot
|
||||||
|
alter column client_id type integer using client_id::integer,
|
||||||
|
alter column token set not null,
|
||||||
|
add constraint bot_token_key unique (token);
|
||||||
|
|
||||||
|
alter table bot
|
||||||
|
rename column client_id to connection_id;
|
||||||
|
|
||||||
|
drop table mapping;
|
@ -283,6 +283,7 @@ func settingsHandler(w http.ResponseWriter, r *http.Request, uid string) {
|
|||||||
p := getConnection(uid)
|
p := getConnection(uid)
|
||||||
if p.ID == 0 {
|
if p.ID == 0 {
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
bots := Bots{}
|
bots := Bots{}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
c := Connection{
|
c := Connection{
|
||||||
|
ID: 1,
|
||||||
ClientID: "123123",
|
ClientID: "123123",
|
||||||
APIKEY: "test",
|
APIKEY: "test",
|
||||||
APIURL: "https://test.retailcrm.ru",
|
APIURL: "https://test.retailcrm.ru",
|
||||||
@ -69,7 +70,7 @@ func TestRouting_addBotHandler(t *testing.T) {
|
|||||||
Reply(201).
|
Reply(201).
|
||||||
BodyString(`{"id": 1}`)
|
BodyString(`{"id": 1}`)
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "/add-bot/", strings.NewReader(`{"token": "123123:Qwerty", "clientId": "123123"}`))
|
req, err := http.NewRequest("POST", "/add-bot/", strings.NewReader(`{"token": "123123:Qwerty", "connectionId": 1}`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -95,7 +96,7 @@ func TestRouting_activityBotHandler(t *testing.T) {
|
|||||||
Reply(200).
|
Reply(200).
|
||||||
BodyString(`{"id": 1}`)
|
BodyString(`{"id": 1}`)
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "/activity-bot/", strings.NewReader(`{"token": "123123:Qwerty", "active": false, "clientId": "123123"}`))
|
req, err := http.NewRequest("POST", "/activity-bot/", strings.NewReader(`{"token": "123123:Qwerty", "active": false, "connectionId": 1}`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -127,6 +128,13 @@ func TestRouting_settingsHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRouting_saveHandler(t *testing.T) {
|
func TestRouting_saveHandler(t *testing.T) {
|
||||||
|
defer gock.Off()
|
||||||
|
|
||||||
|
gock.New("https://test.retailcrm.ru").
|
||||||
|
Get("/api/credentials").
|
||||||
|
Reply(200).
|
||||||
|
BodyString(`{"success": true, "credentials": ["/api/integration-modules/{code}", "/api/integration-modules/{code}/edit"]}`)
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "/save/",
|
req, err := http.NewRequest("POST", "/save/",
|
||||||
strings.NewReader(
|
strings.NewReader(
|
||||||
`{"clientId": "123123",
|
`{"clientId": "123123",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user