Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support create empty shared link #1241

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -943,6 +943,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
Loading