1
0
mirror of synced 2024-11-21 20:16:02 +03:00

add migrations, correct tests

This commit is contained in:
DmitryZagorulko 2018-05-29 10:08:38 +03:00
parent 45a6b478d7
commit cd6c64e6da
4 changed files with 56 additions and 2 deletions

View 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
);

View 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;

View File

@ -283,6 +283,7 @@ func settingsHandler(w http.ResponseWriter, r *http.Request, uid string) {
p := getConnection(uid)
if p.ID == 0 {
http.Redirect(w, r, "/", http.StatusFound)
return
}
bots := Bots{}

View File

@ -12,6 +12,7 @@ import (
func init() {
c := Connection{
ID: 1,
ClientID: "123123",
APIKEY: "test",
APIURL: "https://test.retailcrm.ru",
@ -69,7 +70,7 @@ func TestRouting_addBotHandler(t *testing.T) {
Reply(201).
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 {
t.Fatal(err)
}
@ -95,7 +96,7 @@ func TestRouting_activityBotHandler(t *testing.T) {
Reply(200).
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 {
t.Fatal(err)
}
@ -127,6 +128,13 @@ func TestRouting_settingsHandler(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/",
strings.NewReader(
`{"clientId": "123123",