-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of UserFilter endpoint (#15)
Implementation of UserFilter endpoint
- Loading branch information
1 parent
1225364
commit a16a77f
Showing
11 changed files
with
573 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
Oops, something went wrong.