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

Test: share a file, favorite it and search then for favorites #942

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ public static File extractAsset(String fileName, Context context) throws IOExcep

@After
public void after() {
removeOnClient(client);
removeOnClient(client2);
}

private void removeOnClient(OwnCloudClient client) {
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
assertTrue(result.getLogMessage(), result.isSuccess());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.GetCapabilitiesRemoteOperation;
import com.owncloud.android.lib.resources.status.OCCapability;

Expand Down Expand Up @@ -180,6 +182,48 @@ public void oneFavorite() {
assertEquals(path, remoteFile.getRemotePath());
}

@Test
public void favoriteFiles() throws IOException {
// share a file by second user to test user
String sharedFile = createFile("sharedFavoriteImage.jpg");
String sharedRemotePath = "/sharedFavoriteImage.jpg";
assertTrue(new UploadFileRemoteOperation(sharedFile, sharedRemotePath, "image/jpg", RANDOM_MTIME)
.execute(client2).isSuccess());

// share
assertTrue(new CreateShareRemoteOperation(sharedRemotePath,
ShareType.USER,
client.getUserId(),
false,
"",
31).execute(client2)
.isSuccess()
);

// test user: favorite it
assertTrue(new ToggleFavoriteRemoteOperation(true, sharedRemotePath).execute(client).isSuccess());

String filePath = createFile("favoriteImage.jpg");
String remotePath = "/favoriteImage.jpg";
assertTrue(new UploadFileRemoteOperation(filePath, remotePath, "image/jpg", RANDOM_MTIME)
.execute(client).isSuccess());

assertTrue(new ToggleFavoriteRemoteOperation(true, remotePath).execute(client).isSuccess());

SearchRemoteOperation sut = new SearchRemoteOperation("",
SearchRemoteOperation.SearchType.FAVORITE_SEARCH,
false,
capability);
RemoteOperationResult<List<RemoteFile>> result = sut.execute(client);

// test
assertTrue(result.isSuccess());
assertEquals(2, result.getResultData().size());

assertEquals(remotePath, result.getResultData().get(0).getRemotePath());
assertEquals(sharedRemotePath, result.getResultData().get(1).getRemotePath());
}

/**
* shows just all files, but sorted by date
*/
Expand Down