Skip to content

Commit

Permalink
Fix folder support
Browse files Browse the repository at this point in the history
  • Loading branch information
mfilippov committed Apr 9, 2023
1 parent 819746f commit b75fc44
Show file tree
Hide file tree
Showing 8 changed files with 9,657 additions and 55 deletions.
119 changes: 93 additions & 26 deletions src/VimeoDotNet.Tests/FolderTest.cs
Original file line number Diff line number Diff line change
@@ -1,58 +1,125 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Shouldly;
using VimeoDotNet.Enums;
using VimeoDotNet.Models;
using VimeoDotNet.Parameters;
using Xunit;

namespace VimeoDotNet.Tests
{

public class FolderTest : BaseTest
{
private const int TotalFoldersCount = 7;
private const int RootFoldersCount = 2;

[Fact]
public async Task ShouldCorrectlyGetFolderList()
public async Task ShouldCorrectlyGetFolderListForMe()
{
MockHttpRequest(new RequestSettings
{
UrlSuffix = "/me/folders",
ResponseJsonFile = "Folder.user-folder-list.json"
});
var client = CreateAuthenticatedClient();
var folders = await client.GetUserFolders(UserId.Me);
folders.Total.ShouldBeGreaterThan(1);
folders.Total.ShouldBe(12);
folders.PerPage.ShouldBe(25);
folders.Data.Count.ShouldBeGreaterThan(1);
folders.Data.Count.ShouldBeLessThanOrEqualTo(12);
AssertPagingNext(folders);
folders.Paging.Previous.ShouldBeNull();
}

[Fact]
public async Task ShouldCorrectlyGetFolderListForUserId()
{
const long userId = 2433258;
MockHttpRequest(new RequestSettings
{
UrlSuffix = $"/users/{userId}/folders",
ResponseJsonFile = "Folder.user-folder-list.json"
});
var client = CreateAuthenticatedClient();
Paginated<Folder> folders = await client.GetUserFolders(null);
var folders = await client.GetUserFolders(userId);
folders.Total.ShouldBeGreaterThan(1);
folders.Total.ShouldBe(TotalFoldersCount);
folders.Total.ShouldBe(12);
folders.PerPage.ShouldBe(25);
folders.Data.Count.ShouldBeGreaterThan(1);
folders.Data.Count.ShouldBeLessThanOrEqualTo(TotalFoldersCount);
folders.Data.Count.ShouldBeLessThanOrEqualTo(12);
AssertPagingNext(folders);
folders.Paging.Previous.ShouldBeNull();
}


[Fact]
public async Task ShouldCorrectlyGetFolderItemsListForMe()
{
const long folderId = 15721523;
MockHttpRequest(new RequestSettings
{
UrlSuffix = "/me/projects/15721523/items",
ResponseJsonFile = "Folder.folder-15721523-items.json"
});
MockHttpRequest(new RequestSettings
{
UrlSuffix = "/me/projects/15721574/items",
ResponseJsonFile = "Folder.folder-15721574-items.json"
});
var client = CreateAuthenticatedClient();
var rootItems = await client.GetFolderItems(UserId.Me, folderId);
var folder = rootItems.Data.OrderBy(x => x.IsFolder ? x.Folder.Name : x.Video.Name).First(x => x.IsFolder);
folder.Folder.Id.ShouldNotBeNull();
var folderItems = await client.GetFolderItems(UserId.Me, folder.Folder.Id.Value);
folderItems.Total.ShouldBe(1);
}

[Fact]
public async Task ShouldCorrectlyGetFolderItemsListForUserId()
{
const long userId = 2433258;
const long folderId = 15721523;
MockHttpRequest(new RequestSettings
{
UrlSuffix = $"/users/{userId}/projects/15721523/items",
ResponseJsonFile = "Folder.folder-15721523-items.json"
});
MockHttpRequest(new RequestSettings
{
UrlSuffix = $"/users/{userId}/projects/15721574/items",
ResponseJsonFile = "Folder.folder-15721574-items.json"
});
var client = CreateAuthenticatedClient();
var rootItems = await client.GetFolderItems(userId, folderId);
var folder = rootItems.Data.OrderBy(x => x.IsFolder ? x.Folder.Name : x.Video.Name).First(x => x.IsFolder);
folder.Folder.Id.ShouldNotBeNull();
var folderItems = await client.GetFolderItems(userId, folder.Folder.Id.Value);
folderItems.Total.ShouldBe(1);
}

[Fact]
public async Task ShouldCorrectlyGetRootItemsList()
public async Task ShouldCorrectlyCreateFolder()
{
var client = CreateAuthenticatedClient();
Paginated<Item> items = await client.GetUserRootItems(VimeoSettings.UserId);

items.Total.ShouldBeGreaterThan(1);
items.Total.ShouldBeLessThan(7);
items.PerPage.ShouldBe(25);
items.Data.Where(x=>x.IsVideo).Count().ShouldBe(1);
items.Data.Where(x => x.IsFolder).Count().ShouldBe(1);
items.Data.Count.ShouldBe(RootFoldersCount);
AssertPagingNext<Item>(items);
items.Paging.Previous.ShouldBeNull();
MockHttpRequest(new RequestSettings
{
UrlSuffix = "/me/folders",
Method = RequestSettings.HttpMethod.Post,
RequestTextBody = "name=Test+folder",
ResponseJsonFile = "Folder.post-folder.json"
});
await client.CreateFolder(UserId.Me, "Test folder");
}

[Fact]
public async Task ShouldCorrectlyGetFolderItemsList()
public async Task ShouldCorrectlyDeleteFolder()
{
const long folderId = 15721704;
MockHttpRequest(new RequestSettings
{
UrlSuffix = $"/me/projects/{folderId}",
Method = RequestSettings.HttpMethod.Delete,
StatusCode = 204
});
var client = CreateAuthenticatedClient();
Paginated<Item> rootItems = await client.GetUserRootItems(VimeoSettings.UserId);
var folder = rootItems.Data.First(x => x.IsFolder);
Paginated<Item> folderItems = await client.GetFolderItems(VimeoSettings.UserId, folder.Folder.Id.Value);
folderItems.Total.ShouldBe(7);
await client.DeleteFolder(UserId.Me, folderId);
}

private static void AssertPagingNext<T>(Paginated<T> paginated) where T:class
Expand Down
Loading

0 comments on commit b75fc44

Please sign in to comment.