Skip to content

Commit fc5ed1a

Browse files
committed
test: update charStream tests to support chunks
1 parent 0e553a7 commit fc5ed1a

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

packages/web-api/src/WebClient.spec.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,11 @@ describe('WebClient', () => {
12281228
ok: true,
12291229
ts: '123.123',
12301230
})
1231-
.post('/api/chat.stopStream', { channel: 'C0123456789', ts: '123.123', markdown_text: 'nice!' })
1231+
.post('/api/chat.stopStream', {
1232+
channel: 'C0123456789',
1233+
ts: '123.123',
1234+
chunks: JSON.stringify([{ type: 'markdown_text', text: 'nice!' }]),
1235+
})
12321236
.reply(200, {
12331237
ok: true,
12341238
});
@@ -1279,7 +1283,7 @@ describe('WebClient', () => {
12791283
const scope = nock('https://slack.com')
12801284
.post('/api/chat.startStream', {
12811285
channel: 'C0123456789',
1282-
markdown_text: '**this messag',
1286+
chunks: JSON.stringify([{ type: 'markdown_text', text: '**this messag' }]),
12831287
recipient_team_id: 'T0123456789',
12841288
recipient_user_id: 'U0123456789',
12851289
thread_ts: '123.000',
@@ -1290,7 +1294,7 @@ describe('WebClient', () => {
12901294
})
12911295
.post('/api/chat.appendStream', {
12921296
channel: 'C0123456789',
1293-
markdown_text: 'e is bold!',
1297+
chunks: JSON.stringify([{ type: 'markdown_text', text: 'e is bold!' }]),
12941298
token: 'xoxb-updated-1',
12951299
ts: '123.123',
12961300
})
@@ -1300,7 +1304,7 @@ describe('WebClient', () => {
13001304
.post('/api/chat.stopStream', {
13011305
blocks: JSON.stringify([contextActionsBlock]),
13021306
channel: 'C0123456789',
1303-
markdown_text: '**',
1307+
chunks: JSON.stringify([{ type: 'markdown_text', text: '**' }]),
13041308
token: 'xoxb-updated-2',
13051309
ts: '123.123',
13061310
})
@@ -1370,7 +1374,11 @@ describe('WebClient', () => {
13701374
ok: true,
13711375
ts: '123.123',
13721376
})
1373-
.post('/api/chat.stopStream', { channel: 'C0123456789', ts: '123.123', markdown_text: 'nice!' })
1377+
.post('/api/chat.stopStream', {
1378+
channel: 'C0123456789',
1379+
ts: '123.123',
1380+
chunks: JSON.stringify([{ type: 'markdown_text', text: 'nice!' }]),
1381+
})
13741382
.reply(200, {
13751383
ok: true,
13761384
});

packages/web-api/src/chat-stream.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class ChatStreamer {
9292
}
9393
if (args?.markdown_text) {
9494
this.buffer += args.markdown_text;
95+
args.markdown_text = undefined;
9596
}
9697
if (this.buffer.length >= this.options.buffer_size || args?.chunks) {
9798
return await this.flushBuffer(args);
@@ -135,6 +136,7 @@ export class ChatStreamer {
135136
}
136137
if (args?.markdown_text) {
137138
this.buffer += args.markdown_text;
139+
args.markdown_text = undefined;
138140
}
139141
if (!this.streamTs) {
140142
const response = await this.client.chat.startStream({
@@ -165,6 +167,7 @@ export class ChatStreamer {
165167
channel: this.streamArgs.channel,
166168
ts: this.streamTs,
167169
chunks: flushings,
170+
...args,
168171
});
169172
this.state = 'completed';
170173
return response;
@@ -190,6 +193,7 @@ export class ChatStreamer {
190193
...this.streamArgs,
191194
token: this.token,
192195
chunks: flushings,
196+
...args,
193197
});
194198
this.buffer = '';
195199
this.streamTs = response.ts;
@@ -201,6 +205,7 @@ export class ChatStreamer {
201205
channel: this.streamArgs.channel,
202206
ts: this.streamTs,
203207
chunks: flushings,
208+
...args,
204209
});
205210
this.buffer = '';
206211
return response;

0 commit comments

Comments
 (0)