Skip to content

Commit e23b066

Browse files
committed
test: confirm content can be uploaded with blocks to a channel
1 parent edad10c commit e23b066

1 file changed

Lines changed: 53 additions & 7 deletions

File tree

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

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,11 +1190,7 @@ describe('WebClient', () => {
11901190
file_id: 'F0123456789',
11911191
upload_url: 'https://files.slack.com/upload/v1/abcdefghijklmnopqrstuvwxyz',
11921192
})
1193-
.post('/api/files.completeUploadExternal', {
1194-
blocks: '[{"type":"section","text":{"type":"plain_text","text":"Hello"}}]',
1195-
channel_id: 'C010101010',
1196-
files: '[{"id":"F0123456789","title":"test-txt.txt"}]',
1197-
})
1193+
.post('/api/files.completeUploadExternal', { files: '[{"id":"F0123456789","title":"test-txt.txt"}]' })
11981194
.reply(200, {
11991195
ok: true,
12001196
files: [
@@ -1208,8 +1204,6 @@ describe('WebClient', () => {
12081204
const uploader = nock('https://files.slack.com').post('/upload/v1/abcdefghijklmnopqrstuvwxyz').reply(200);
12091205
const client = new WebClient(token);
12101206
const response = await client.filesUploadV2({
1211-
blocks: [{ type: 'section', text: { type: 'plain_text', text: 'Hello' } }],
1212-
channel_id: 'C010101010',
12131207
file: fs.createReadStream('./test/fixtures/test-txt.txt'),
12141208
filename: 'test-txt.txt',
12151209
});
@@ -1234,6 +1228,58 @@ describe('WebClient', () => {
12341228
uploader.done();
12351229
});
12361230

1231+
it('uploads content', async () => {
1232+
const scope = nock('https://slack.com')
1233+
.post('/api/files.getUploadURLExternal', { filename: 'content.txt', length: 42 })
1234+
.reply(200, {
1235+
ok: true,
1236+
file_id: 'F0101010101',
1237+
upload_url: 'https://files.slack.com/upload/v1/abcdefghijklmnopqrstuvwxyz',
1238+
})
1239+
.post('/api/files.completeUploadExternal', {
1240+
blocks: '[{"type":"section","text":{"type":"plain_text","text":"Hello"}}]',
1241+
channel_id: 'C010101010',
1242+
files: '[{"id":"F0101010101","title":"content.txt"}]',
1243+
})
1244+
.reply(200, {
1245+
ok: true,
1246+
files: [
1247+
{
1248+
id: 'F0101010101',
1249+
name: 'content.txt',
1250+
permalink: 'https://my-workspace.slack.com/files/U0123456789/F0101010101/content.txt',
1251+
},
1252+
],
1253+
});
1254+
const uploader = nock('https://files.slack.com').post('/upload/v1/abcdefghijklmnopqrstuvwxyz').reply(200);
1255+
const client = new WebClient(token);
1256+
const response = await client.filesUploadV2({
1257+
blocks: [{ type: 'section', text: { type: 'plain_text', text: 'Hello' } }],
1258+
channel_id: 'C010101010',
1259+
content: 'Words from another variable might go here!',
1260+
filename: 'content.txt',
1261+
});
1262+
const expected = {
1263+
ok: true,
1264+
files: [
1265+
{
1266+
ok: true,
1267+
files: [
1268+
{
1269+
id: 'F0101010101',
1270+
name: 'content.txt',
1271+
permalink: 'https://my-workspace.slack.com/files/U0123456789/F0101010101/content.txt',
1272+
},
1273+
],
1274+
response_metadata: {},
1275+
},
1276+
],
1277+
};
1278+
assert.deepEqual(response, expected);
1279+
scope.done();
1280+
uploader.done();
1281+
});
1282+
12371283
it('uploads multiple files', async () => {
12381284
const scope = nock('https://slack.com')
12391285
.post('/api/files.getUploadURLExternal', { filename: 'test-png.png', length: 55292 })

0 commit comments

Comments
 (0)