Skip to content

Commit

Permalink
Tests for Approve/DeclineChatJoinRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
pengrad committed Nov 19, 2021
1 parent 2dd9fd6 commit 514fab8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public User creator() {
return creator;
}

public Boolean createsJoinReqeust() {
public Boolean createsJoinRequest() {
return creates_join_request;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
* 10/21/15.
*/
public enum ChatAction {
typing,
upload_photo,
record_video,
upload_video,
record_audio,
upload_audio,
upload_document,
choose_sticker,
typing,
upload_photo,
record_video,
upload_video,
record_voice,
upload_voice,
upload_document,
choose_sticker,
find_location,
record_video_note,
record_video_note,
upload_video_note
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public CreateChatInviteLink(Object chatId) {
/**
*
* @param name Invite link name; 0-32 characters
* @return
*/
public CreateChatInviteLink name(String name) {
return add("name", name);
Expand All @@ -33,7 +32,6 @@ public CreateChatInviteLink memberLimit(Integer memberLimit) {
/**
*
* @param createsJoinRequest True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can't be specified
* @return
*/
public CreateChatInviteLink createsJoinRequest(Boolean createsJoinRequest) {
return add("creates_join_request", createsJoinRequest);
Expand Down
36 changes: 23 additions & 13 deletions library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1931,31 +1931,41 @@ public void inviteLinks() {
assertTrue(link.creator().isBot());
assertEquals(name, link.name());

response = bot.execute(new CreateChatInviteLink(groupId)
.expireDate(expireDate)
.createsJoinRequest(true)
.name(name));
link = response.chatInviteLink();
assertEquals(expireDate, link.expireDate().intValue());
assertTrue(link.createsJoinReqeust());
assertEquals(0, link.pendingJoinRequestCount().intValue());
assertFalse(link.isRevoked());
assertTrue(link.creator().isBot());
assertEquals(name, link.name());

int editMemberLimit = 3;
int editExpireDate = (int) (System.currentTimeMillis() / 1000) + 1500;
String editName = name + "edit";
response = bot.execute(new EditChatInviteLink(groupId, link.inviteLink())
.expireDate(editExpireDate)
.memberLimit(editMemberLimit));
.memberLimit(editMemberLimit)
.name(editName));
link = response.chatInviteLink();
assertEquals(editExpireDate, link.expireDate().intValue());
assertEquals(editMemberLimit, link.memberLimit().intValue());
assertEquals(editName, link.name());
assertFalse(link.isRevoked());

response = bot.execute(new RevokeChatInviteLink(groupId, link.inviteLink()));
link = response.chatInviteLink();
assertTrue(link.isRevoked());
assertFalse(link.isPrimary());

response = bot.execute(new CreateChatInviteLink(groupId).createsJoinRequest(true));
link = response.chatInviteLink();
assertTrue(link.createsJoinRequest());
assertNull(link.pendingJoinRequestCount());

response = bot.execute(new EditChatInviteLink(groupId, link.inviteLink()).createsJoinRequest(false));
assertFalse(response.chatInviteLink().createsJoinRequest());
}

@Test
public void chatJoinRequest() {
BaseResponse response = bot.execute(new ApproveChatJoinRequest(groupId, memberBot));
assertFalse(response.isOk());
assertEquals("Bad Request: USER_ALREADY_PARTICIPANT", response.description());

response = bot.execute(new DeclineChatJoinRequest(groupId, memberBot));
assertFalse(response.isOk());
assertEquals("Bad Request: USER_ALREADY_PARTICIPANT", response.description());
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
<version>2.8.6</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit 514fab8

Please sign in to comment.