Skip to content

Commit

Permalink
[tests] improve test cases for marshaled params
Browse files Browse the repository at this point in the history
  • Loading branch information
ProjectBarks authored and nlopes committed Feb 14, 2025
1 parent d26493c commit 2ede2bf
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion slackevents/inner_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,20 @@ func TestFunctionExecutedEvent(t *testing.T) {
"description": "Message recipient",
"title": "User",
"is_required": true
},
{
"type": "integer",
"name": "timestamp",
"description": "Timestamp of the event",
"title": "Timestamp",
"is_required": true
},
{
"type": "boolean",
"name": "enabled",
"description": "Indicates if the feature is enabled",
"title": "Enabled",
"is_required": true
}
],
"output_parameters": [
Expand All @@ -2577,8 +2591,10 @@ func TestFunctionExecutedEvent(t *testing.T) {
},
"inputs": {
"user_id": "USER12345678",
"timestamp": 1698947481,
"enabled": true,
"message_context": {
"channel_id": "C07H1ER7U66",
"channel_id": "C0123456789",
"message_ts": "1733331835.871019"
}
},
Expand All @@ -2588,6 +2604,17 @@ func TestFunctionExecutedEvent(t *testing.T) {
"bot_access_token": "abcd-1325532282098-1322446258629-6123648410839-527a1cab3979cad288c9e20330d212cf"
}`

type MessageContext struct {
ChannelId string `json:"channel_id"`
MessageTs string `json:"message_ts"`
}
type TestInputs struct {
UserId string `json:"user_id"`
Timestamp int `json:"timestamp"`
Enabled bool `json:"enabled"`
Context MessageContext `json:"message_context"`
}

var event FunctionExecutedEvent
if err := json.Unmarshal([]byte(jsonStr), &event); err != nil {
t.Errorf("Failed to unmarshal FunctionExecutedEvent: %v", err)
Expand All @@ -2604,6 +2631,21 @@ func TestFunctionExecutedEvent(t *testing.T) {
if event.FunctionExecutionID != "Fx1234567O9L" {
t.Fail()
}

inputStr, err := json.Marshal(event.Inputs)
if err != nil {
t.Errorf("Failed to marshal Inputs of FunctionExecutedEvent: %v", err)
}
testInputs := new(TestInputs)
err = json.Unmarshal(inputStr, testInputs)
if err != nil {
t.Errorf("Failed to unmarshal Inputs of FunctionExecutedEvent: %v", err)
}
assert.Equal(t, "USER12345678", testInputs.UserId)
assert.Equal(t, 1698947481, testInputs.Timestamp)
assert.True(t, testInputs.Enabled)
assert.Equal(t, "C0123456789", testInputs.Context.ChannelId)
assert.Equal(t, "1733331835.871019", testInputs.Context.MessageTs)
}

func TestInviteRequestedEvent(t *testing.T) {
Expand Down

0 comments on commit 2ede2bf

Please sign in to comment.