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

fix: check if message.parent_id exists #156

Merged
merged 1 commit into from
Aug 1, 2023
Merged
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
3 changes: 3 additions & 0 deletions pkg/cmd/chat/imports/validator/items.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ func (m *messageItem) validateReferences(idx *index) error {
if idx.isReply(m.ParentID) {
return errors.New("only one level thread is supported")
}
if !idx.messageExist(m.ParentID) {
return fmt.Errorf("message parent_id %q doesn't exist", m.ParentID)
}
}
channelID, isDistinct := getChannelID(m.ChannelID, m.ChannelMemberIDs)
if !idx.channelExist(m.ChannelType, channelID) {
Expand Down
11 changes: 11 additions & 0 deletions pkg/cmd/chat/imports/validator/testdata/invalid-messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@
"deleted_at": "2022-02-14T12:34:30+00:00"
}
},
{
"type": "message",
"item": {
"id": "thread",
"channel_type": "messaging",
"channel_id": "channelA",
"user": "userA",
"text": "reply!",
"parent_id": "parentID"
}
},
{
"type": "channel",
"item": {
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/chat/imports/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestValidator_Validate(t *testing.T) {
},
}},
{name: "Invalid messages", filename: "invalid-messages.json", want: &Results{
Stats: map[string]int{"channels": 2, "devices": 0, "members": 2, "messages": 0, "reactions": 0, "users": 1},
Stats: map[string]int{"channels": 2, "devices": 0, "members": 2, "messages": 1, "reactions": 0, "users": 1},
Errors: []error{
errors.New(`validation error: message.id max length exceeded (255)`),
errors.New(`validation error: message.channel_type required`),
Expand All @@ -93,6 +93,7 @@ func TestValidator_Validate(t *testing.T) {
errors.New(`reference error: channel ":channelA" doesn't exist`),
errors.New(`reference error: distinct channel with type "messaging" and members:[] doesn't exist`),
errors.New(`reference error: user "" doesn't exist (message_id messageA)`),
errors.New(`reference error: message parent_id "parentID" doesn't exist`),
},
}},
{name: "Invalid devices", filename: "invalid-devices.json", want: &Results{
Expand Down
Loading