Skip to content

Commit

Permalink
Implementation of UserFilter endpoint (#15)
Browse files Browse the repository at this point in the history
Implementation of UserFilter endpoint
  • Loading branch information
vitali-sonchyk-epam authored and nvborisenko committed Sep 6, 2018
1 parent 1225364 commit a16a77f
Show file tree
Hide file tree
Showing 11 changed files with 573 additions and 0 deletions.
57 changes: 57 additions & 0 deletions ReportPortal.Client.Tests/Project/Project.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ReportPortal.Client.Models;
using ReportPortal.Client.Requests;
using Xunit;

namespace ReportPortal.Client.Tests.Project
{
public class ProjectFixture : BaseFixture
{
[Fact]
public async Task UpdatePreferences()
{
var filterEntity = new FilterEntity
{
UserFilterCondition = UserFilterCondition.Contains,
FilteringField = "name",
Value = "test value"
};

var order1 = new FilterOrder
{
Asc = true,
SortingColumn = "name",
};

var selectionParameters = new FilterSelectionParameter
{
Orders = new List<FilterOrder> { order1 },
PageNumber = 1
};

var filterElement = new FilterElement
{
Name = Guid.NewGuid().ToString(),
Description = "testDscr_1",
IsLink = false,
Share = true,
UserFilterType = UserFilterType.Launch,
Entities = new List<FilterEntity> { filterEntity },
SelectionParameters = selectionParameters
};

var userFilters = await Service.AddUserFilterAsync(new AddUserFilterRequest { FilterElements = new List<FilterElement> { filterElement } });

var message = await Service.UpdatePreferencesAsync(new UpdatePreferenceRequest { FilderIds = userFilters.Select(x => x.Id) }, Username);
Assert.Contains("updated", message.Info);

var allPreferences = await Service.GetAllPreferences(Username);
Assert.True(allPreferences.FilterIds.Intersect(userFilters.Select(x => x.Id)).Any());

userFilters.ForEach(async x => await Service.DeleteUserFilterAsync(x.Id));
}
}
}
98 changes: 98 additions & 0 deletions ReportPortal.Client.Tests/UserFilter/UserFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ReportPortal.Client.Filtering;
using ReportPortal.Client.Models;
using ReportPortal.Client.Requests;
using Xunit;

namespace ReportPortal.Client.Tests.UserFilter
{
public class UserFilterFixture : BaseFixture
{
[Fact]
public async Task GetUserFilters()
{
var filterEntity = new FilterEntity
{
UserFilterCondition = UserFilterCondition.Contains,
FilteringField = "name",
Value = "test value"
};

var order1 = new FilterOrder
{
Asc = true,
SortingColumn = "name",
};

var selectionParameters = new FilterSelectionParameter
{
Orders = new List<FilterOrder> { order1 },
PageNumber = 1
};

var filterElement = new FilterElement
{
Name = Guid.NewGuid().ToString(),
Description = "testDscr_1",
IsLink = false,
Share = true,
UserFilterType = UserFilterType.Launch,
Entities = new List<FilterEntity> { filterEntity },
SelectionParameters = selectionParameters
};

var userFilters = await Service.AddUserFilterAsync(new AddUserFilterRequest { FilterElements = new List<FilterElement> { filterElement } });

var userFilterContainer = await Service.GetUserFiltersAsync();
Assert.True(userFilterContainer.FilterElements.Any());
}

[Fact]
public async Task CreateDeleteUserFilter()
{
var filterEntity = new FilterEntity
{
UserFilterCondition = UserFilterCondition.Contains,
FilteringField = "name",
Value = "test value"
};

var order1 = new FilterOrder
{
Asc = true,
SortingColumn = "name",
};

var selectionParameters = new FilterSelectionParameter
{
Orders = new List<FilterOrder> { order1 },
PageNumber = 1
};

var filterElement = new FilterElement
{
Name = Guid.NewGuid().ToString(),
Description = "testDscr_1",
IsLink = false,
Share = true,
UserFilterType = UserFilterType.Launch,
Entities = new List<FilterEntity> { filterEntity },
SelectionParameters = selectionParameters
};

var userFilters = await Service.AddUserFilterAsync(new AddUserFilterRequest { FilterElements = new List<FilterElement> { filterElement } });

var userFilterContainer = await Service.GetUserFiltersAsync(new FilterOption
{
Paging = new Paging(1, 200)
});
Assert.Contains(userFilterContainer.FilterElements, f => f.Id.Equals(userFilters.First().Id));

var deleteMessage = await Service.DeleteUserFilterAsync(userFilters.First().Id);
Assert.Contains("success", deleteMessage.Info);
}
}
}
10 changes: 10 additions & 0 deletions ReportPortal.Client/Models/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ public class Page
[DataMember(Name = "number")]
public int Number { get; set; }
}

[DataContract]
public class UserFilterContainer
{
[DataMember(Name = "content")]
public IEnumerable<UserFilter> FilterElements { get; set; }

[DataMember(Name = "page")]
public Page Page { get; set; }
}
}
17 changes: 17 additions & 0 deletions ReportPortal.Client/Models/EntryCreated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace ReportPortal.Client.Models
{
[DataContract]
public class EntryCreated
{
/// <summary>
/// ID of crated entry
/// </summary>
[DataMember(Name= "id")]
public string Id { get; set; }
}
}
22 changes: 22 additions & 0 deletions ReportPortal.Client/Models/Enum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,26 @@ public enum AnalyzerItemsMode
[DataMember(Name = "MANUALLY_ANALYZED")]
ManuallyAnalyzed
}

public enum UserFilterType
{
[DataMember(Name = "launch")]
Launch,
[DataMember(Name = "testitem")]
TestItem,
[DataMember(Name = "log")]
Log
}

public enum UserFilterCondition
{
[DataMember(Name = "cnt")]
Contains,
[DataMember(Name = "!cnt")]
NotContains,
[DataMember(Name = "eq")]
Equals,
[DataMember(Name = "!eq")]
NotEquals,
}
}
26 changes: 26 additions & 0 deletions ReportPortal.Client/Models/Preference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace ReportPortal.Client.Models
{
[DataContract]
public class Preference
{
[DataMember(Name = "userRef")]
public string UserRef { get; set; }

[DataMember(Name = "projectRef")]
public string ProjectRef { get; set; }

[DataMember(Name = "active")]
public string Active { get; set; }

/// <summary>
/// list of filters in a preference
/// </summary>
[DataMember(Name = "filters")]
public List<string> FilterIds { get; set; }
}
}
74 changes: 74 additions & 0 deletions ReportPortal.Client/Models/UserFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using ReportPortal.Client.Converters;
using ReportPortal.Client.Requests;

namespace ReportPortal.Client.Models
{
[DataContract]
public class UserFilter
{
/// <summary>
/// description of user filter
/// </summary>
[DataMember(Name = "description")]
public string Description { get; set; }

/// <summary>
/// list of entities
/// </summary>
[DataMember(Name = "entities")]
public IEnumerable<FilterEntity> Entities { get; set; }

/// <summary>
/// id of user filter
/// </summary>
[DataMember(Name = "id")]
public string Id { get; set; }

[DataMember(Name = "is_link")]
public bool IsLink { get; set; }

/// <summary>
/// name of user filter
/// </summary>
[DataMember(Name = "name")]
public string Name { get; set; }

/// <summary>
/// list of parameters of selection
/// </summary>
[DataMember(Name = "selection_parameters")]
public IEnumerable<FilterSelectionParameter> SelectionParameters { get; set; }

/// <summary>
/// is filter shared
/// </summary>
[DataMember(Name = "share")]
public bool Share { get; set; }

/// <summary>
/// filter type
/// </summary>
[DataMember(Name = "type")]
public string TypeStr { get; set; }

/// <summary>
/// user filter type enum
/// </summary>
public UserFilterType UserFilterType
{
get => EnumConverter.ConvertTo<UserFilterType>(TypeStr);
set => TypeStr = EnumConverter.ConvertFrom(UserFilterType);

}

/// <summary>
/// owner of user filter
/// </summary>
[DataMember(Name = "owner")]
public string Owner { get; set; }
}
}
Loading

0 comments on commit a16a77f

Please sign in to comment.