Skip to content

Commit 2fb3e82

Browse files
authored
Fix #802 Add files.upload integration tests using private channels (#804)
1 parent 4a9f597 commit 2fb3e82

File tree

3 files changed

+100
-3
lines changed

3 files changed

+100
-3
lines changed

json-logs/samples/api/files.info.json

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,41 @@
5959
"share_user_id": "U00000000"
6060
}
6161
]
62+
},
63+
"private": {
64+
"C00000000": [
65+
{
66+
"reply_users": [
67+
""
68+
],
69+
"reply_users_count": 12345,
70+
"reply_count": 12345,
71+
"ts": "0000000000.000000",
72+
"channel_name": "",
73+
"team_id": "T00000000",
74+
"share_user_id": "U00000000"
75+
}
76+
],
77+
"C00000001": [
78+
{
79+
"reply_users": [
80+
""
81+
],
82+
"reply_users_count": 12345,
83+
"reply_count": 12345,
84+
"ts": "0000000000.000000",
85+
"channel_name": "",
86+
"team_id": "T00000000",
87+
"share_user_id": "U00000000"
88+
}
89+
]
6290
}
6391
},
6492
"channels": [
6593
"C00000000"
6694
],
6795
"groups": [
68-
""
96+
"C00000000"
6997
],
7098
"ims": [
7199
""

json-logs/samples/api/files.upload.json

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,41 @@
6363
"latest_reply": "0000000000.000000"
6464
}
6565
]
66+
},
67+
"private": {
68+
"C00000000": [
69+
{
70+
"reply_users": [
71+
""
72+
],
73+
"reply_users_count": 12345,
74+
"reply_count": 12345,
75+
"ts": "0000000000.000000",
76+
"channel_name": "",
77+
"team_id": "T00000000",
78+
"share_user_id": "U00000000"
79+
}
80+
],
81+
"C00000001": [
82+
{
83+
"reply_users": [
84+
""
85+
],
86+
"reply_users_count": 12345,
87+
"reply_count": 12345,
88+
"ts": "0000000000.000000",
89+
"channel_name": "",
90+
"team_id": "T00000000",
91+
"share_user_id": "U00000000"
92+
}
93+
]
6694
}
6795
},
6896
"channels": [
6997
"C00000000"
7098
],
7199
"groups": [
72-
""
100+
"C00000000"
73101
],
74102
"ims": [
75103
""

slack-api-client/src/test/java/test_with_remote_apis/methods/files_Test.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import com.slack.api.methods.response.chat.ChatPostMessageResponse;
1515
import com.slack.api.methods.response.chat.ChatUpdateResponse;
1616
import com.slack.api.methods.response.files.*;
17+
import com.slack.api.methods.response.users.UsersConversationsResponse;
1718
import com.slack.api.model.Conversation;
19+
import com.slack.api.model.ConversationType;
1820
import config.Constants;
1921
import config.SlackTestConfig;
2022
import lombok.extern.slf4j.Slf4j;
@@ -31,6 +33,7 @@
3133

3234
import static org.hamcrest.CoreMatchers.*;
3335
import static org.hamcrest.MatcherAssert.assertThat;
36+
import static org.hamcrest.Matchers.greaterThan;
3437

3538
@Slf4j
3639
public class files_Test {
@@ -434,7 +437,7 @@ public void issue523_image_no_filename() throws IOException, SlackApiException {
434437
}
435438

436439
@Test
437-
public void uploadAndPostMessage() throws IOException, SlackApiException {
440+
public void uploadAndPostMessage() throws IOException, SlackApiException, InterruptedException {
438441
MethodsClient slackMethods = slack.methods(userToken);
439442

440443
ChatPostMessageResponse message = slackMethods.chatPostMessage(r -> r
@@ -445,6 +448,14 @@ public void uploadAndPostMessage() throws IOException, SlackApiException {
445448

446449
String channelId = message.getChannel();
447450

451+
// Share the file in a private channel
452+
UsersConversationsResponse userPrivateChannels = slackMethods.usersConversations(r -> r
453+
.types(Arrays.asList(ConversationType.PRIVATE_CHANNEL)));
454+
assertThat(userPrivateChannels.getError(), is(nullValue()));
455+
assertThat(userPrivateChannels.getChannels().size(), is(greaterThan(0)));
456+
457+
String privateChannelId = userPrivateChannels.getChannels().get(0).getId();
458+
448459
File file = new File("src/test/resources/sample.txt");
449460
com.slack.api.model.File fileObj;
450461
{
@@ -477,6 +488,36 @@ public void uploadAndPostMessage() throws IOException, SlackApiException {
477488
.build());
478489
assertThat(newMessage.getError(), is(nullValue()));
479490
}
491+
492+
{
493+
ChatPostMessageResponse newMessage = slackMethods.chatPostMessage(ChatPostMessageRequest.builder()
494+
.channel(privateChannelId)
495+
.text(fileObj.getPermalink())
496+
.unfurlLinks(true)
497+
.unfurlMedia(true)
498+
.build());
499+
assertThat(newMessage.getError(), is(nullValue()));
500+
}
501+
502+
Thread.sleep(2_000L);
503+
504+
// verify if the shares is expected
505+
FilesInfoResponse fileInfo = slackMethods.filesInfo(r -> r.file(fileObj.getId()));
506+
assertThat(fileInfo.getError(), is(nullValue()));
507+
assertThat(fileInfo.getFile().getShares().getPublicChannels(), is(notNullValue()));
508+
assertThat(fileInfo.getFile().getShares().getPrivateChannels(), is(notNullValue()));
509+
510+
FilesUploadResponse uploadAndSharedInTwoTypesOfChannels = slackMethods.filesUpload(r -> r
511+
.file(file)
512+
.initialComment("test")
513+
.filetype("text")
514+
.filename("sample.txt")
515+
.title("file title")
516+
.channels(Arrays.asList(channelId, privateChannelId))
517+
);
518+
assertThat(uploadAndSharedInTwoTypesOfChannels.getError(), is(nullValue()));
519+
assertThat(uploadAndSharedInTwoTypesOfChannels.getFile().getShares().getPublicChannels(), is(notNullValue()));
520+
assertThat(uploadAndSharedInTwoTypesOfChannels.getFile().getShares().getPrivateChannels(), is(notNullValue()));
480521
}
481522

482523
@Test

0 commit comments

Comments
 (0)