mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 23:42:36 -07:00
Small fixes around the searching
This commit is contained in:
parent
974cb1ebb3
commit
1c6ddc74cb
7 changed files with 91 additions and 27 deletions
|
@ -1,13 +1,11 @@
|
||||||
using System.Threading.Tasks;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Ombi.Core.Models.Requests;
|
using Ombi.Core.Models.Requests;
|
||||||
using Ombi.Core.Models.Requests.Movie;
|
using Ombi.Core.Models.Requests.Movie;
|
||||||
using Ombi.Core.Models.Search;
|
using Ombi.Core.Models.Search;
|
||||||
using Ombi.Core.Requests.Models;
|
using Ombi.Core.Requests.Models;
|
||||||
using Ombi.Core.Rule.Rules.Search;
|
using Ombi.Core.Rule.Rules.Search;
|
||||||
using Ombi.Store.Context;
|
|
||||||
using Ombi.Store.Entities;
|
|
||||||
using Ombi.Store.Repository;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Ombi.Core.Tests.Rule.Search
|
namespace Ombi.Core.Tests.Rule.Search
|
||||||
|
@ -25,20 +23,20 @@ namespace Ombi.Core.Tests.Rule.Search
|
||||||
private Mock<IRequestService<MovieRequestModel>> MovieMock { get; }
|
private Mock<IRequestService<MovieRequestModel>> MovieMock { get; }
|
||||||
private Mock<IRequestService<TvRequestModel>> TvMock { get; }
|
private Mock<IRequestService<TvRequestModel>> TvMock { get; }
|
||||||
|
|
||||||
// TODO continue tests
|
|
||||||
// https://stackoverflow.com/questions/27483709/testing-ef-async-methods-with-sync-methods-with-moq
|
[Fact]
|
||||||
public async Task ShouldBe_Requested_WhenExisitngMovie()
|
public async Task ShouldBe_Requested_WhenExisitngMovie()
|
||||||
{
|
{
|
||||||
var list = DbHelper.GetQueryableMockDbSet(new MovieRequestModel
|
var list = new List<MovieRequestModel>{new MovieRequestModel
|
||||||
{
|
{
|
||||||
ProviderId = 123,
|
ProviderId = 123,
|
||||||
Approved = true
|
Approved = true
|
||||||
});
|
}};
|
||||||
MovieMock.Setup(x => x.GetAllQueryable()).Returns(list);
|
MovieMock.Setup(x => x.GetAllAsync()).ReturnsAsync(list);
|
||||||
var search = new SearchMovieViewModel
|
var search = new SearchMovieViewModel
|
||||||
{
|
{
|
||||||
Id = 123,
|
Id = 123,
|
||||||
|
|
||||||
};
|
};
|
||||||
var result = await Rule.Execute(search);
|
var result = await Rule.Execute(search);
|
||||||
|
|
||||||
|
@ -46,6 +44,66 @@ namespace Ombi.Core.Tests.Rule.Search
|
||||||
Assert.Equal(search.Approved, true);
|
Assert.Equal(search.Approved, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ShouldBe_NotRequested_WhenNewMovie()
|
||||||
|
{
|
||||||
|
var list = new List<MovieRequestModel>{new MovieRequestModel
|
||||||
|
{
|
||||||
|
ProviderId = 123,
|
||||||
|
Approved = true
|
||||||
|
}};
|
||||||
|
MovieMock.Setup(x => x.GetAllAsync()).ReturnsAsync(list);
|
||||||
|
var search = new SearchMovieViewModel
|
||||||
|
{
|
||||||
|
Id = 999,
|
||||||
|
|
||||||
|
};
|
||||||
|
var result = await Rule.Execute(search);
|
||||||
|
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.Equal(search.Approved, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ShouldBe_Requested_WhenExisitngTv()
|
||||||
|
{
|
||||||
|
var list = new List<TvRequestModel>{new TvRequestModel
|
||||||
|
{
|
||||||
|
ProviderId = 123,
|
||||||
|
Approved = true
|
||||||
|
}};
|
||||||
|
TvMock.Setup(x => x.GetAllAsync()).ReturnsAsync(list);
|
||||||
|
var search = new SearchTvShowViewModel
|
||||||
|
{
|
||||||
|
Id = 123,
|
||||||
|
|
||||||
|
};
|
||||||
|
var result = await Rule.Execute(search);
|
||||||
|
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.Equal(search.Approved, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ShouldBe_NotRequested_WhenNewTv()
|
||||||
|
{
|
||||||
|
var list = new List<TvRequestModel>{new TvRequestModel
|
||||||
|
{
|
||||||
|
ProviderId = 123,
|
||||||
|
Approved = true
|
||||||
|
}};
|
||||||
|
TvMock.Setup(x => x.GetAllAsync()).ReturnsAsync(list);
|
||||||
|
var search = new SearchTvShowViewModel()
|
||||||
|
{
|
||||||
|
Id = 999,
|
||||||
|
|
||||||
|
};
|
||||||
|
var result = await Rule.Execute(search);
|
||||||
|
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.Equal(search.Approved, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -132,6 +132,7 @@ namespace Ombi.Core.Engine
|
||||||
RequestAdded = false
|
RequestAdded = false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
// If there are no providers then it's successful but movie has not been sent
|
||||||
}
|
}
|
||||||
|
|
||||||
return await AddMovieRequest(requestModel, /*settings,*/
|
return await AddMovieRequest(requestModel, /*settings,*/
|
||||||
|
|
|
@ -5,7 +5,6 @@ namespace Ombi.Core.Models.Search
|
||||||
{
|
{
|
||||||
public class SearchTvShowViewModel : SearchViewModel
|
public class SearchTvShowViewModel : SearchViewModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public List<string> Aliases { get; set; }
|
public List<string> Aliases { get; set; }
|
||||||
public string Banner { get; set; }
|
public string Banner { get; set; }
|
||||||
|
|
|
@ -45,9 +45,8 @@ namespace Ombi.Core
|
||||||
|
|
||||||
return new MovieSenderResult
|
return new MovieSenderResult
|
||||||
{
|
{
|
||||||
Success = false,
|
Success = true,
|
||||||
MovieSent = false,
|
MovieSent = false,
|
||||||
Message = "There are no movie providers enabled!"
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Threading.Tasks;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Ombi.Core.Models.Requests;
|
using Ombi.Core.Models.Requests;
|
||||||
using Ombi.Core.Models.Requests.Movie;
|
using Ombi.Core.Models.Requests.Movie;
|
||||||
|
@ -21,8 +22,8 @@ namespace Ombi.Core.Rule.Rules.Search
|
||||||
|
|
||||||
public async Task<RuleResult> Execute(SearchViewModel obj)
|
public async Task<RuleResult> Execute(SearchViewModel obj)
|
||||||
{
|
{
|
||||||
var movieRequests = Movie.GetAllQueryable();
|
var movieRequests = await Movie.GetAllAsync();
|
||||||
var existing = await movieRequests.FirstOrDefaultAsync(x => x.ProviderId == obj.Id);
|
var existing = movieRequests.FirstOrDefault(x => x.ProviderId == obj.Id);
|
||||||
if (existing != null) // Do we already have a request for this?
|
if (existing != null) // Do we already have a request for this?
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -33,14 +34,14 @@ namespace Ombi.Core.Rule.Rules.Search
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
var tvRequests = Tv.GetAllQueryable();
|
var tvRequests = await Tv.GetAllAsync();
|
||||||
var movieExisting = await tvRequests.FirstOrDefaultAsync(x => x.ProviderId == obj.Id);
|
var tv = tvRequests.FirstOrDefault(x => x.ProviderId == obj.Id);
|
||||||
if (movieExisting != null) // Do we already have a request for this?
|
if (tv != null) // Do we already have a request for this?
|
||||||
{
|
{
|
||||||
|
|
||||||
obj.Requested = true;
|
obj.Requested = true;
|
||||||
obj.Approved = movieExisting.Approved;
|
obj.Approved = tv.Approved;
|
||||||
obj.Available = movieExisting.Available;
|
obj.Available = tv.Available;
|
||||||
|
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,12 +59,7 @@ export class MovieRequestsComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
|
|
||||||
loadMore() {
|
loadMore() {
|
||||||
this.requestService.getMovieRequests(this.amountToLoad, this.currentlyLoaded + 1)
|
this.loadRequests(this.amountToLoad, this.currentlyLoaded);
|
||||||
.takeUntil(this.subscriptions)
|
|
||||||
.subscribe(x => {
|
|
||||||
this.movieRequests.push.apply(this.movieRequests, x);
|
|
||||||
this.currentlyLoaded = this.currentlyLoaded + this.amountToLoad;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
search(text: any) {
|
search(text: any) {
|
||||||
|
@ -74,6 +69,7 @@ export class MovieRequestsComponent implements OnInit, OnDestroy {
|
||||||
removeRequest(request: IMovieRequestModel) {
|
removeRequest(request: IMovieRequestModel) {
|
||||||
this.requestService.removeMovieRequest(request);
|
this.requestService.removeMovieRequest(request);
|
||||||
this.removeRequestFromUi(request);
|
this.removeRequestFromUi(request);
|
||||||
|
this.loadRequests(1, this.currentlyLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeAvailability(request: IMovieRequestModel, available: boolean) {
|
changeAvailability(request: IMovieRequestModel, available: boolean) {
|
||||||
|
@ -94,6 +90,15 @@ export class MovieRequestsComponent implements OnInit, OnDestroy {
|
||||||
this.updateRequest(request);
|
this.updateRequest(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private loadRequests(amountToLoad: number, currentlyLoaded: number) {
|
||||||
|
this.requestService.getMovieRequests(amountToLoad, currentlyLoaded + 1)
|
||||||
|
.takeUntil(this.subscriptions)
|
||||||
|
.subscribe(x => {
|
||||||
|
this.movieRequests.push.apply(this.movieRequests, x);
|
||||||
|
this.currentlyLoaded = currentlyLoaded + amountToLoad;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private updateRequest(request: IMovieRequestModel) {
|
private updateRequest(request: IMovieRequestModel) {
|
||||||
this.requestService.updateMovieRequest(request)
|
this.requestService.updateMovieRequest(request)
|
||||||
.takeUntil(this.subscriptions)
|
.takeUntil(this.subscriptions)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { Message } from 'primeng/components/common/api';
|
||||||
export class NotificationService {
|
export class NotificationService {
|
||||||
messages: Message[] = [];
|
messages: Message[] = [];
|
||||||
public addMessage(message: Message) {
|
public addMessage(message: Message) {
|
||||||
|
this.clearMessages();
|
||||||
this.messages.push(message);
|
this.messages.push(message);
|
||||||
this.messages = JSON.parse(JSON.stringify(this.messages)); // NOTE: THIS IS A HACK AROUND A BUG https://github.com/primefaces/primeng/issues/2943
|
this.messages = JSON.parse(JSON.stringify(this.messages)); // NOTE: THIS IS A HACK AROUND A BUG https://github.com/primefaces/primeng/issues/2943
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue