@@ -137,6 +137,62 @@ func TestInboxNotification_Watch(t *testing.T) {
137
137
require .Equal (t , memberClient .ID , notif .Notification .UserID )
138
138
})
139
139
140
+ t .Run ("OK - change format" , func (t * testing.T ) {
141
+ t .Parallel ()
142
+
143
+ ctx := testutil .Context (t , testutil .WaitLong )
144
+ logger := testutil .Logger (t )
145
+
146
+ db , ps := dbtestutil .NewDB (t )
147
+
148
+ firstClient , _ , _ := coderdtest .NewWithAPI (t , & coderdtest.Options {
149
+ Pubsub : ps ,
150
+ Database : db ,
151
+ })
152
+ firstUser := coderdtest .CreateFirstUser (t , firstClient )
153
+ member , memberClient := coderdtest .CreateAnotherUser (t , firstClient , firstUser .OrganizationID , rbac .RoleTemplateAdmin ())
154
+
155
+ u , err := member .URL .Parse ("/api/v2/notifications/inbox/watch?format=plaintext" )
156
+ require .NoError (t , err )
157
+
158
+ // nolint:bodyclose
159
+ wsConn , resp , err := websocket .Dial (ctx , u .String (), & websocket.DialOptions {
160
+ HTTPHeader : http.Header {
161
+ "Coder-Session-Token" : []string {member .SessionToken ()},
162
+ },
163
+ })
164
+ if err != nil {
165
+ if resp .StatusCode != http .StatusSwitchingProtocols {
166
+ err = codersdk .ReadBodyAsError (resp )
167
+ }
168
+ require .NoError (t , err )
169
+ }
170
+ defer wsConn .Close (websocket .StatusNormalClosure , "done" )
171
+
172
+ inboxHandler := dispatch .NewInboxHandler (logger , db , ps )
173
+ dispatchFunc , err := inboxHandler .Dispatcher (types.MessagePayload {
174
+ UserID : memberClient .ID .String (),
175
+ NotificationTemplateID : notifications .TemplateWorkspaceOutOfMemory .String (),
176
+ }, "# Notification Title" , "This is the __content__." , nil )
177
+ require .NoError (t , err )
178
+
179
+ _ , err = dispatchFunc (ctx , uuid .New ())
180
+ require .NoError (t , err )
181
+
182
+ _ , message , err := wsConn .Read (ctx )
183
+ require .NoError (t , err )
184
+
185
+ var notif codersdk.GetInboxNotificationResponse
186
+ err = json .Unmarshal (message , & notif )
187
+ require .NoError (t , err )
188
+
189
+ require .Equal (t , 1 , notif .UnreadCount )
190
+ require .Equal (t , memberClient .ID , notif .Notification .UserID )
191
+
192
+ require .Equal (t , "Notification Title" , notif .Notification .Title )
193
+ require .Equal (t , "This is the content." , notif .Notification .Content )
194
+ })
195
+
140
196
t .Run ("OK - filters on templates" , func (t * testing.T ) {
141
197
t .Parallel ()
142
198
0 commit comments