|
| 1 | +package slack |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | +) |
| 10 | + |
| 11 | +func TestSHRoomJoinEventUnmarshal(t *testing.T) { |
| 12 | + raw := `{ |
| 13 | + "type": "sh_room_join", |
| 14 | + "room": { |
| 15 | + "id": "R01XXXBW", |
| 16 | + "name": null, |
| 17 | + "media_server": "", |
| 18 | + "created_by": "U12334", |
| 19 | + "date_start": 1607089008, |
| 20 | + "date_end": 0, |
| 21 | + "participants": ["U12334", "U56789"], |
| 22 | + "participant_history": ["U12334", "U56789"], |
| 23 | + "participants_camera_on": [], |
| 24 | + "participants_camera_off": [], |
| 25 | + "participants_screenshare_on": [], |
| 26 | + "participants_screenshare_off": [], |
| 27 | + "channels": ["C12334"], |
| 28 | + "is_dm_call": false, |
| 29 | + "was_rejected": false, |
| 30 | + "was_missed": false, |
| 31 | + "was_accepted": false, |
| 32 | + "has_ended": false, |
| 33 | + "media_backend_type": "free_willy", |
| 34 | + "external_unique_id": "8c92471f-test", |
| 35 | + "app_id": "A00" |
| 36 | + }, |
| 37 | + "user": "U12334", |
| 38 | + "event_ts": "1607089059.080900", |
| 39 | + "ts": "1607089059.080900" |
| 40 | + }` |
| 41 | + |
| 42 | + var ev SHRoomJoinEvent |
| 43 | + err := json.Unmarshal([]byte(raw), &ev) |
| 44 | + require.NoError(t, err) |
| 45 | + |
| 46 | + assert.Equal(t, "sh_room_join", ev.Type) |
| 47 | + assert.Equal(t, "U12334", ev.User) |
| 48 | + assert.Equal(t, "R01XXXBW", ev.Room.ID) |
| 49 | + assert.Nil(t, ev.Room.Name) |
| 50 | + assert.Equal(t, "U12334", ev.Room.CreatedBy) |
| 51 | + assert.Equal(t, int64(1607089008), ev.Room.DateStart) |
| 52 | + assert.Equal(t, []string{"U12334", "U56789"}, ev.Room.Participants) |
| 53 | + assert.Equal(t, []string{"C12334"}, ev.Room.Channels) |
| 54 | + assert.False(t, ev.Room.IsDMCall) |
| 55 | + assert.Equal(t, "free_willy", ev.Room.MediaBackendType) |
| 56 | + assert.Equal(t, "1607089059.080900", ev.EventTS) |
| 57 | +} |
| 58 | + |
| 59 | +func TestSHRoomLeaveEventUnmarshal(t *testing.T) { |
| 60 | + raw := `{ |
| 61 | + "type": "sh_room_leave", |
| 62 | + "room": { |
| 63 | + "id": "R01XXXBW", |
| 64 | + "name": null, |
| 65 | + "media_server": "", |
| 66 | + "created_by": "U12334", |
| 67 | + "date_start": 1607089008, |
| 68 | + "date_end": 0, |
| 69 | + "participants": ["U12334"], |
| 70 | + "participant_history": ["U12334", "U56789"], |
| 71 | + "participants_camera_on": [], |
| 72 | + "participants_camera_off": [], |
| 73 | + "participants_screenshare_on": [], |
| 74 | + "participants_screenshare_off": [], |
| 75 | + "channels": ["C12334"], |
| 76 | + "is_dm_call": false, |
| 77 | + "was_rejected": false, |
| 78 | + "was_missed": false, |
| 79 | + "was_accepted": false, |
| 80 | + "has_ended": false, |
| 81 | + "media_backend_type": "free_willy", |
| 82 | + "external_unique_id": "8c92471f-test", |
| 83 | + "app_id": "A00" |
| 84 | + }, |
| 85 | + "user": "U56789", |
| 86 | + "event_ts": "1607091086.081500", |
| 87 | + "ts": "1607091086.081500" |
| 88 | + }` |
| 89 | + |
| 90 | + var ev SHRoomLeaveEvent |
| 91 | + err := json.Unmarshal([]byte(raw), &ev) |
| 92 | + require.NoError(t, err) |
| 93 | + |
| 94 | + assert.Equal(t, "sh_room_leave", ev.Type) |
| 95 | + assert.Equal(t, "U56789", ev.User) |
| 96 | + assert.Equal(t, "R01XXXBW", ev.Room.ID) |
| 97 | + assert.Equal(t, []string{"U12334"}, ev.Room.Participants) |
| 98 | + assert.Equal(t, "1607091086.081500", ev.EventTS) |
| 99 | +} |
| 100 | + |
| 101 | +func TestSHRoomUpdateEventUnmarshal(t *testing.T) { |
| 102 | + raw := `{ |
| 103 | + "type": "sh_room_update", |
| 104 | + "room": { |
| 105 | + "id": "R0AQSG0Q859", |
| 106 | + "name": "A sort of topic", |
| 107 | + "media_server": "", |
| 108 | + "created_by": "U031L4VDD", |
| 109 | + "date_start": 1775402709, |
| 110 | + "date_end": 0, |
| 111 | + "participants": ["U031L4VDD"], |
| 112 | + "participant_history": ["U031L4VDD"], |
| 113 | + "participants_events": {"U031L4VDD": {"joined": true, "camera_on": false}}, |
| 114 | + "participants_camera_on": [], |
| 115 | + "participants_camera_off": [], |
| 116 | + "participants_screenshare_on": [], |
| 117 | + "participants_screenshare_off": [], |
| 118 | + "canvas_thread_ts": "1775402709.576349", |
| 119 | + "thread_root_ts": "1775402709.576349", |
| 120 | + "channels": ["C031L4VDP"], |
| 121 | + "is_dm_call": false, |
| 122 | + "was_rejected": false, |
| 123 | + "was_missed": false, |
| 124 | + "was_accepted": false, |
| 125 | + "has_ended": false, |
| 126 | + "background_id": "GRADIENT_02", |
| 127 | + "canvas_background": "GRADIENT_02", |
| 128 | + "is_prewarmed": true, |
| 129 | + "is_scheduled": false, |
| 130 | + "recording": {"can_record_summary": "unavailable"}, |
| 131 | + "locale": "en-US", |
| 132 | + "attached_file_ids": [], |
| 133 | + "media_backend_type": "free_willy", |
| 134 | + "display_id": "", |
| 135 | + "external_unique_id": "755e016f-aae1-4d4f-abcc-952b1b872713", |
| 136 | + "app_id": "A00", |
| 137 | + "call_family": "huddle", |
| 138 | + "huddle_link": "https://app.slack.com/huddle/T031L4VD9/C031L4VDP" |
| 139 | + }, |
| 140 | + "user": "U031L4VDD", |
| 141 | + "huddle": {"channel_id": "C031L4VDP"}, |
| 142 | + "event_ts": "1775402785.000200", |
| 143 | + "ts": "1775402785.000200" |
| 144 | + }` |
| 145 | + |
| 146 | + var ev SHRoomUpdateEvent |
| 147 | + err := json.Unmarshal([]byte(raw), &ev) |
| 148 | + require.NoError(t, err) |
| 149 | + |
| 150 | + assert.Equal(t, "sh_room_update", ev.Type) |
| 151 | + assert.Equal(t, "U031L4VDD", ev.User) |
| 152 | + assert.Equal(t, "R0AQSG0Q859", ev.Room.ID) |
| 153 | + assert.NotNil(t, ev.Room.Name) |
| 154 | + assert.Equal(t, "A sort of topic", *ev.Room.Name) |
| 155 | + assert.Equal(t, "huddle", ev.Room.CallFamily) |
| 156 | + assert.True(t, ev.Room.IsPrewarmed) |
| 157 | + assert.Equal(t, "1775402709.576349", ev.Room.CanvasThreadTS) |
| 158 | + assert.Equal(t, "GRADIENT_02", ev.Room.BackgroundID) |
| 159 | + assert.Equal(t, "en-US", ev.Room.Locale) |
| 160 | + assert.NotNil(t, ev.Room.Recording) |
| 161 | + assert.Equal(t, "unavailable", ev.Room.Recording.CanRecordSummary) |
| 162 | + assert.Equal(t, "https://app.slack.com/huddle/T031L4VD9/C031L4VDP", ev.Room.HuddleLink) |
| 163 | + assert.NotNil(t, ev.Huddle) |
| 164 | + assert.Equal(t, "C031L4VDP", ev.Huddle.ChannelID) |
| 165 | + assert.NotNil(t, ev.Room.ParticipantsEvents) |
| 166 | + assert.Contains(t, ev.Room.ParticipantsEvents, "U031L4VDD") |
| 167 | +} |
0 commit comments