Small fixes around the searching

pull/1488/head
Jamie.Rees 8 years ago
parent 974cb1ebb3
commit 1c6ddc74cb

@ -1,13 +1,11 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using Ombi.Core.Models.Requests;
using Ombi.Core.Models.Requests.Movie;
using Ombi.Core.Models.Search;
using Ombi.Core.Requests.Models;
using Ombi.Core.Rule.Rules.Search;
using Ombi.Store.Context;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
using Xunit;
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<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()
{
var list = DbHelper.GetQueryableMockDbSet(new MovieRequestModel
var list = new List<MovieRequestModel>{new MovieRequestModel
{
ProviderId = 123,
Approved = true
});
MovieMock.Setup(x => x.GetAllQueryable()).Returns(list);
}};
MovieMock.Setup(x => x.GetAllAsync()).ReturnsAsync(list);
var search = new SearchMovieViewModel
{
Id = 123,
};
var result = await Rule.Execute(search);
@ -46,6 +44,66 @@ namespace Ombi.Core.Tests.Rule.Search
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
};
}
// If there are no providers then it's successful but movie has not been sent
}
return await AddMovieRequest(requestModel, /*settings,*/

@ -5,7 +5,6 @@ namespace Ombi.Core.Models.Search
{
public class SearchTvShowViewModel : SearchViewModel
{
public int Id { get; set; }
public string Title { get; set; }
public List<string> Aliases { get; set; }
public string Banner { get; set; }

@ -45,9 +45,8 @@ namespace Ombi.Core
return new MovieSenderResult
{
Success = false,
Success = true,
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 Ombi.Core.Models.Requests;
using Ombi.Core.Models.Requests.Movie;
@ -21,8 +22,8 @@ namespace Ombi.Core.Rule.Rules.Search
public async Task<RuleResult> Execute(SearchViewModel obj)
{
var movieRequests = Movie.GetAllQueryable();
var existing = await movieRequests.FirstOrDefaultAsync(x => x.ProviderId == obj.Id);
var movieRequests = await Movie.GetAllAsync();
var existing = movieRequests.FirstOrDefault(x => x.ProviderId == obj.Id);
if (existing != null) // Do we already have a request for this?
{
@ -33,14 +34,14 @@ namespace Ombi.Core.Rule.Rules.Search
return Success();
}
var tvRequests = Tv.GetAllQueryable();
var movieExisting = await tvRequests.FirstOrDefaultAsync(x => x.ProviderId == obj.Id);
if (movieExisting != null) // Do we already have a request for this?
var tvRequests = await Tv.GetAllAsync();
var tv = tvRequests.FirstOrDefault(x => x.ProviderId == obj.Id);
if (tv != null) // Do we already have a request for this?
{
obj.Requested = true;
obj.Approved = movieExisting.Approved;
obj.Available = movieExisting.Available;
obj.Approved = tv.Approved;
obj.Available = tv.Available;
return Success();
}

@ -59,12 +59,7 @@ export class MovieRequestsComponent implements OnInit, OnDestroy {
loadMore() {
this.requestService.getMovieRequests(this.amountToLoad, this.currentlyLoaded + 1)
.takeUntil(this.subscriptions)
.subscribe(x => {
this.movieRequests.push.apply(this.movieRequests, x);
this.currentlyLoaded = this.currentlyLoaded + this.amountToLoad;
});
this.loadRequests(this.amountToLoad, this.currentlyLoaded);
}
search(text: any) {
@ -74,6 +69,7 @@ export class MovieRequestsComponent implements OnInit, OnDestroy {
removeRequest(request: IMovieRequestModel) {
this.requestService.removeMovieRequest(request);
this.removeRequestFromUi(request);
this.loadRequests(1, this.currentlyLoaded);
}
changeAvailability(request: IMovieRequestModel, available: boolean) {
@ -94,6 +90,15 @@ export class MovieRequestsComponent implements OnInit, OnDestroy {
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) {
this.requestService.updateMovieRequest(request)
.takeUntil(this.subscriptions)

@ -5,6 +5,7 @@ import { Message } from 'primeng/components/common/api';
export class NotificationService {
messages: Message[] = [];
public addMessage(message: Message) {
this.clearMessages();
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
}

Loading…
Cancel
Save