Skip to content

Commit

Permalink
Merge pull request #888 from Fanatics/container-thread-field
Browse files Browse the repository at this point in the history
add thread_ts to container
  • Loading branch information
kanata2 committed Jul 16, 2021
2 parents 62fceea + 5690e81 commit f5878c7
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions interactions.go
Expand Up @@ -121,6 +121,7 @@ type Container struct {
Type string `json:"type"`
ViewID string `json:"view_id"`
MessageTs string `json:"message_ts"`
ThreadTs string `json:"thread_ts,omitempty"`
AttachmentID json.Number `json:"attachment_id"`
ChannelID string `json:"channel_id"`
IsEphemeral bool `json:"is_ephemeral"`
Expand Down
84 changes: 84 additions & 0 deletions interactions_test.go
Expand Up @@ -454,3 +454,87 @@ func TestInteractionCallback_InteractionTypeBlockActions_Unmarshal(t *testing.T)
cb.BlockActionState.Values["section_block_id"]["multi_convos"].SelectedConversations,
[]string{"G12345"})
}

func TestInteractionCallback_Container_Marshal_And_Unmarshal(t *testing.T) {
// Contrived - you generally won't see all of the fields set in a single message
raw := []byte(
`
{
"container": {
"type": "message",
"view_id": "viewID",
"message_ts": "messageTS",
"attachment_id": "123",
"channel_id": "channelID",
"is_ephemeral": false,
"is_app_unfurl": false
}
}
`)

expected := &InteractionCallback{
Container: Container{
Type: "message",
ViewID: "viewID",
MessageTs: "messageTS",
AttachmentID: "123",
ChannelID: "channelID",
IsEphemeral: false,
IsAppUnfurl: false,
},
RawState: json.RawMessage(`{}`),
}

actual := new(InteractionCallback)
err := json.Unmarshal(raw, actual)
assert.NoError(t, err)
assert.Equal(t, expected.Container, actual.Container)

expectedJSON := []byte(`{"type":"message","view_id":"viewID","message_ts":"messageTS","attachment_id":123,"channel_id":"channelID","is_ephemeral":false,"is_app_unfurl":false}`)
actualJSON, err := json.Marshal(actual.Container)
assert.NoError(t, err)
assert.Equal(t, expectedJSON, actualJSON)
}

func TestInteractionCallback_In_Thread_Container_Marshal_And_Unmarshal(t *testing.T) {
// Contrived - you generally won't see all of the fields set in a single message
raw := []byte(
`
{
"container": {
"type": "message",
"view_id": "viewID",
"message_ts": "messageTS",
"thread_ts": "threadTS",
"attachment_id": "123",
"channel_id": "channelID",
"is_ephemeral": false,
"is_app_unfurl": false
}
}
`)

expected := &InteractionCallback{
Container: Container{
Type: "message",
ViewID: "viewID",
MessageTs: "messageTS",
ThreadTs: "threadTS",
AttachmentID: "123",
ChannelID: "channelID",
IsEphemeral: false,
IsAppUnfurl: false,
},
RawState: json.RawMessage(`{}`),
}

actual := new(InteractionCallback)
err := json.Unmarshal(raw, actual)
assert.NoError(t, err)
assert.Equal(t, expected.Container, actual.Container)

expectedJSON := []byte(`{"type":"message","view_id":"viewID","message_ts":"messageTS","thread_ts":"threadTS","attachment_id":123,"channel_id":"channelID","is_ephemeral":false,"is_app_unfurl":false}`)
actualJSON, err := json.Marshal(actual.Container)
assert.NoError(t, err)
assert.Equal(t, expectedJSON, actualJSON)
}

0 comments on commit f5878c7

Please sign in to comment.