Skip to content

Commit

Permalink
add deserialization for file unshared event
Browse files Browse the repository at this point in the history
  • Loading branch information
andyhaskell committed Oct 12, 2022
1 parent 7b80668 commit c395f84
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
11 changes: 11 additions & 0 deletions slackevents/inner_events.go
Expand Up @@ -182,6 +182,14 @@ type FileSharedEvent struct {
EventTimestamp string `json:"event_ts"`
}

// FileUnsharedEvent represents the information associated with the File
// unshared event.
type FileUnsharedEvent struct {
Type string `json:"type"`
FileID string `json:"file_id"`
File FileEventFile `json:"file"`
}

// FileEventFile represents information on the specific file being shared in a
// file-related Slack event.
type FileEventFile struct {
Expand Down Expand Up @@ -555,6 +563,8 @@ const (
FileDeleted = EventsAPIType("file_deleted")
// FileShared is sent when a file is shared.
FileShared = EventsAPIType("file_shared")
// FileUnshared is sent when a file is unshared.
FileUnshared = EventsAPIType("file_unshared")
// GridMigrationFinished An enterprise grid migration has finished on this workspace.
GridMigrationFinished = EventsAPIType("grid_migration_finished")
// GridMigrationStarted An enterprise grid migration has started on this workspace.
Expand Down Expand Up @@ -607,6 +617,7 @@ var EventsAPIInnerEventMapping = map[EventsAPIType]interface{}{
FileChange: FileChangeEvent{},
FileDeleted: FileDeletedEvent{},
FileShared: FileSharedEvent{},
FileUnshared: FileUnsharedEvent{},
GroupDeleted: GroupDeletedEvent{},
GroupArchive: GroupArchiveEvent{},
GroupUnarchive: GroupUnarchiveEvent{},
Expand Down
26 changes: 26 additions & 0 deletions slackevents/inner_events_test.go
Expand Up @@ -126,6 +126,32 @@ func TestFileSharedEvent(t *testing.T) {
}
}

func TestFileUnsharedEvent(t *testing.T) {
rawE := []byte(`
{
"type": "file_unshared",
"file_id": "F1234567890",
"file": {
"id": "F1234567890"
}
}
`)

var e FileUnsharedEvent
if err := json.Unmarshal(rawE, &e); err != nil {
t.Fatal(err)
}
if e.Type != "file_unshared" {
t.Errorf("type should be file_shared, was %s", e.Type)
}
if e.FileID != "F1234567890" {
t.Errorf("file ID should be F1234567890, was %s", e.FileID)
}
if e.File.ID != "F1234567890" {
t.Errorf("file.id should be F1234567890, was %s", e.File.ID)
}
}

func TestGridMigrationFinishedEvent(t *testing.T) {
rawE := []byte(`
{
Expand Down

0 comments on commit c395f84

Please sign in to comment.