Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add parse channel context and host for shared channel #1353

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Conversation struct {
ConnectedTeamIDs []string `json:"connected_team_ids,omitempty"`
SharedTeamIDs []string `json:"shared_team_ids,omitempty"`
InternalTeamIDs []string `json:"internal_team_ids,omitempty"`
ContextTeamID string `json:"context_team_id,omitempty"`
ConversationHostID string `json:"conversation_host_id,omitempty"`

// TODO support pending_shared
// TODO support previous_names
Expand Down
86 changes: 86 additions & 0 deletions conversation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,92 @@ func TestCreateSimpleChannel(t *testing.T) {
assertSimpleChannel(t, channel)
}

// Shared Channel
var sharedChannel = `{
"id": "C024BE91L",
"name": "fun",
"is_channel": true,
"created": 1360782804,
"creator": "U024BE7LH",
"is_archived": false,
"is_general": false,
"members": [
"U024BE7LH"
],
"is_shared": true,
"context_team_id": "T1ABCD2E12",
"is_ext_shared": true,
"shared_team_ids": [
"T07XY8FPJ5C"
],
"internal_team_ids": [],
"connected_team_ids": [
"T07XY8FPJ5C",
"T1ABCD2E12"
],
"connected_limited_team_ids": [],
"pending_connected_team_ids": [],
"conversation_host_id": "T07XY8FPJ5C",
"topic": {
"value": "Fun times",
"creator": "U024BE7LV",
"last_set": 1369677212
},
"purpose": {
"value": "This channel is for fun",
"creator": "U024BE7LH",
"last_set": 1360782804
},
"is_member": true,
"last_read": "1401383885.000061",
"unread_count": 0,
"unread_count_display": 0
}`

func unmarshalSharedChannel(j string) (*Channel, error) {
channel := &Channel{}
if err := json.Unmarshal([]byte(j), &channel); err != nil {
return nil, err
}
return channel, nil
}

func TestSharedChannel(t *testing.T) {
channel, err := unmarshalSharedChannel(sharedChannel)
assert.Nil(t, err)
assertSharedChannel(t, channel)
}

func assertSharedChannel(t *testing.T, channel *Channel) {
assertSimpleChannel(t, channel)
assert.Equal(t, true, channel.IsShared)
assert.Equal(t, true, channel.IsExtShared)
assert.Equal(t, "T1ABCD2E12", channel.ContextTeamID)
assert.Equal(t, "T07XY8FPJ5C", channel.ConversationHostID)
if !reflect.DeepEqual([]string{"T07XY8FPJ5C"}, channel.SharedTeamIDs) {
t.Fatal(ErrIncorrectResponse)
}
if !reflect.DeepEqual([]string{"T07XY8FPJ5C", "T1ABCD2E12"}, channel.ConnectedTeamIDs) {
t.Fatal(ErrIncorrectResponse)
}
}

func TestCreateSharedChannel(t *testing.T) {
channel := &Channel{}
channel.ID = "C024BE91L"
channel.Name = "fun"
channel.IsChannel = true
channel.Created = JSONTime(1360782804)
channel.Creator = "U024BE7LH"
channel.IsArchived = false
channel.IsGeneral = false
channel.IsMember = true
channel.LastRead = "1401383885.000061"
channel.UnreadCount = 0
channel.UnreadCountDisplay = 0
assertSharedChannel(t, channel)
}

// Group
var simpleGroup = `{
"id": "G024BE91L",
Expand Down