mirror of
https://github.com/mattermost/focalboard.git
synced 2025-01-26 18:48:15 +02:00
Sharing integration tests
This commit is contained in:
parent
2f71295275
commit
1048c009c3
@ -184,3 +184,30 @@ func (c *Client) GetSubtree(blockID string) ([]model.Block, *Response) {
|
|||||||
|
|
||||||
return model.BlocksFromJSON(r.Body), BuildResponse(r)
|
return model.BlocksFromJSON(r.Body), BuildResponse(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sharing
|
||||||
|
|
||||||
|
func (c *Client) GetSharingRoute(rootID string) string {
|
||||||
|
return fmt.Sprintf("/sharing/%s", rootID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) GetSharing(rootID string) (*model.Sharing, *Response) {
|
||||||
|
r, err := c.DoApiGet(c.GetSharingRoute(rootID), "")
|
||||||
|
if err != nil {
|
||||||
|
return nil, BuildErrorResponse(r, err)
|
||||||
|
}
|
||||||
|
defer closeBody(r)
|
||||||
|
|
||||||
|
sharing := model.SharingFromJSON(r.Body)
|
||||||
|
return &sharing, BuildResponse(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) PostSharing(sharing model.Sharing) (bool, *Response) {
|
||||||
|
r, err := c.DoApiPost(c.GetSharingRoute(sharing.ID), toJSON(sharing))
|
||||||
|
if err != nil {
|
||||||
|
return false, BuildErrorResponse(r, err)
|
||||||
|
}
|
||||||
|
defer closeBody(r)
|
||||||
|
|
||||||
|
return true, BuildResponse(r)
|
||||||
|
}
|
||||||
|
46
server/integrationtests/sharing_test.go
Normal file
46
server/integrationtests/sharing_test.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package integrationtests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-octo-tasks/server/model"
|
||||||
|
"github.com/mattermost/mattermost-octo-tasks/server/utils"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSharing(t *testing.T) {
|
||||||
|
th := SetupTestHelper().InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
rootID := utils.CreateGUID()
|
||||||
|
token := utils.CreateGUID()
|
||||||
|
|
||||||
|
t.Run("Check no initial sharing", func(t *testing.T) {
|
||||||
|
sharing, resp := th.Client.GetSharing(rootID)
|
||||||
|
require.NoError(t, resp.Error)
|
||||||
|
require.Empty(t, sharing.ID)
|
||||||
|
require.False(t, sharing.Enabled)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("POST sharing", func(t *testing.T) {
|
||||||
|
sharing := model.Sharing{
|
||||||
|
ID: rootID,
|
||||||
|
Token: token,
|
||||||
|
Enabled: true,
|
||||||
|
UpdateAt: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
success, resp := th.Client.PostSharing(sharing)
|
||||||
|
require.True(t, success)
|
||||||
|
require.NoError(t, resp.Error)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("GET sharing", func(t *testing.T) {
|
||||||
|
sharing, resp := th.Client.GetSharing(rootID)
|
||||||
|
require.NoError(t, resp.Error)
|
||||||
|
require.NotNil(t, sharing)
|
||||||
|
require.Equal(t, sharing.ID, rootID)
|
||||||
|
require.True(t, sharing.Enabled)
|
||||||
|
require.Equal(t, sharing.Token, token)
|
||||||
|
})
|
||||||
|
}
|
@ -1,5 +1,10 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
type Sharing struct {
|
type Sharing struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
@ -7,3 +12,9 @@ type Sharing struct {
|
|||||||
ModifiedBy string `json:"modifiedBy"`
|
ModifiedBy string `json:"modifiedBy"`
|
||||||
UpdateAt int64 `json:"update_at,omitempty"`
|
UpdateAt int64 `json:"update_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SharingFromJSON(data io.Reader) Sharing {
|
||||||
|
var sharing Sharing
|
||||||
|
json.NewDecoder(data).Decode(&sharing)
|
||||||
|
return sharing
|
||||||
|
}
|
||||||
|
@ -27,7 +27,7 @@ func (s *SQLStore) UpsertSharing(sharing model.Sharing) error {
|
|||||||
sharing.ModifiedBy,
|
sharing.ModifiedBy,
|
||||||
now,
|
now,
|
||||||
).
|
).
|
||||||
Suffix("ON CONFLICT (id) DO SET enabled = EXCLUDED.enabled, token = EXCLUDED.token, modified_by = EXCLUDED.modified_by, update_at = EXCLUDED.update_at")
|
Suffix("ON CONFLICT (id) DO UPDATE SET enabled = EXCLUDED.enabled, token = EXCLUDED.token, modified_by = EXCLUDED.modified_by, update_at = EXCLUDED.update_at")
|
||||||
|
|
||||||
_, err := query.Exec()
|
_, err := query.Exec()
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user