Skip to content

Commit

Permalink
fix: Support create empty shared link (#1241)
Browse files Browse the repository at this point in the history
  • Loading branch information
congminh1254 authored Mar 29, 2024
1 parent 7e7af3f commit 0c86487
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/intTest/java/com/box/sdk/BoxFileIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,21 @@ public void setsVanityNameOnASharedLink() {
}
}

@Test
public void createDefaultSharedLink() {
BoxAPIConnection api = jwtApiForServiceAccount();
BoxFile uploadedFile = null;
try {
uploadedFile = uploadFileToUniqueFolderWithSomeContent(api, "file_to_share.txt");
BoxSharedLinkRequest request = new BoxSharedLinkRequest();
uploadedFile.createSharedLink(request);
BoxSharedLink sharedLink = uploadedFile.getInfo().getSharedLink();
assertThat(sharedLink, is(notNullValue()));
} finally {
deleteFile(uploadedFile);
}
}

@Test
public void setsAndRetrievesDispositionAt() throws ParseException {
BoxAPIConnection api = jwtApiForServiceAccount();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/box/sdk/BoxJSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void update(JsonObject jsonObject) {
*
* @return a JsonObject containing the pending changes.
*/
private JsonObject getPendingJSONObject() {
protected JsonObject getPendingJSONObject() {
for (Map.Entry<String, BoxJSONObject> entry : this.children.entrySet()) {
BoxJSONObject child = entry.getValue();
JsonObject jsonObject = child.getPendingJSONObject();
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/box/sdk/BoxSharedLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ private Access parseAccessValue(JsonValue value) {
return Access.valueOf(accessString);
}

@Override
protected JsonObject getPendingJSONObject() {
JsonObject result = super.getPendingJSONObject();
if (result == null) {
result = new JsonObject();
}
return result;
}

@Override
void parseJSONMember(JsonObject.Member member) {
JsonValue value = member.getValue();
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/box/sdk/BoxFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,30 @@ public String getJSON() {
file.createSharedLink(sharedLink);
}

@Test
public void createDefaultSharedLink() {
//given
BoxAPIConnection api = new BoxAPIConnectionForTests("");
api.setRequestInterceptor(
request -> {
//then
String requestString = request.bodyToString();
assertThat(requestString, is("{\"shared_link\":{}}"));
return new BoxJSONResponse() {
@Override
public String getJSON() {
return "{}";
}
};
}
);
BoxSharedLinkRequest sharedLink = new BoxSharedLinkRequest();

//when
BoxFile file = new BoxFile(api, "12345");
file.createSharedLink(sharedLink);
}

@Test
public void setMetadataWorksWhenNoChangesSubmittedAndConflictOccured() {
// given
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/box/sdk/BoxSharedLinkTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.box.sdk;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertThrows;

Expand Down Expand Up @@ -43,7 +42,7 @@ public void doNotStorePendingChangeWhenPermissionsNotChanged() {
link.setPermissions(this.permissions(true, false));

assertThat(link.getPermissions(), is(permissions(true, false)));
assertThat(link.getPendingChangesAsJsonObject(), is(nullValue()));
assertThat(link.getPendingChangesAsJsonObject().toString(), is("{}"));
}

@Test
Expand Down

0 comments on commit 0c86487

Please sign in to comment.