From 1b13d6e6b7a469565371012e4d99c60bcbcc5139 Mon Sep 17 00:00:00 2001 From: TidusJar Date: Thu, 11 Oct 2018 14:25:28 +0100 Subject: [PATCH] More UI tests !wip --- .../Engine/Interfaces/IMovieRequestEngine.cs | 1 + src/Ombi.Core/Engine/MovieRequestEngine.cs | 6 ++ .../ClientApp/app/vote/vote.component.html | 6 +- src/Ombi/Controllers/RequestController.cs | 12 ++++ src/Ombi/cypress/fixtures/login.json | 4 ++ .../cypress/integration/vote.feature.spec.js | 64 +++++++++++++++++-- src/Ombi/cypress/integration/wizard.spec.js | 6 +- src/Ombi/cypress/support/commands.js | 2 +- src/Ombi/cypress/support/request.commands.js | 12 +++- 9 files changed, 101 insertions(+), 12 deletions(-) create mode 100644 src/Ombi/cypress/fixtures/login.json diff --git a/src/Ombi.Core/Engine/Interfaces/IMovieRequestEngine.cs b/src/Ombi.Core/Engine/Interfaces/IMovieRequestEngine.cs index 152a1d923..bb8b9e64d 100644 --- a/src/Ombi.Core/Engine/Interfaces/IMovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/IMovieRequestEngine.cs @@ -12,6 +12,7 @@ namespace Ombi.Core.Engine.Interfaces Task> SearchMovieRequest(string search); Task RemoveMovieRequest(int requestId); + Task RemoveAllMovieRequests(); Task UpdateMovieRequest(MovieRequests request); Task ApproveMovie(MovieRequests request); diff --git a/src/Ombi.Core/Engine/MovieRequestEngine.cs b/src/Ombi.Core/Engine/MovieRequestEngine.cs index 2185c9cb6..16fd7667b 100644 --- a/src/Ombi.Core/Engine/MovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/MovieRequestEngine.cs @@ -416,6 +416,12 @@ namespace Ombi.Core.Engine await MovieRepository.Delete(request); } + public async Task RemoveAllMovieRequests() + { + var request = MovieRepository.GetAll(); + await MovieRepository.DeleteRange(request); + } + public async Task UserHasRequest(string userId) { return await MovieRepository.GetAll().AnyAsync(x => x.RequestedUserId == userId); diff --git a/src/Ombi/ClientApp/app/vote/vote.component.html b/src/Ombi/ClientApp/app/vote/vote.component.html index 625bb986d..d91ce85bd 100644 --- a/src/Ombi/ClientApp/app/vote/vote.component.html +++ b/src/Ombi/ClientApp/app/vote/vote.component.html @@ -32,16 +32,16 @@ - - poster - {{vm.title}} + {{vm.title}} diff --git a/src/Ombi/Controllers/RequestController.cs b/src/Ombi/Controllers/RequestController.cs index bd2793061..9e13e1c90 100644 --- a/src/Ombi/Controllers/RequestController.cs +++ b/src/Ombi/Controllers/RequestController.cs @@ -117,6 +117,18 @@ namespace Ombi.Controllers await MovieRequestEngine.RemoveMovieRequest(requestId); } + /// + /// Deletes the specified movie request. + /// + /// The request identifier. + /// + [HttpDelete("movie/all")] + [PowerUser] + public async Task DeleteAllRequests() + { + await MovieRequestEngine.RemoveAllMovieRequests(); + } + /// /// Updates the specified movie request. /// diff --git a/src/Ombi/cypress/fixtures/login.json b/src/Ombi/cypress/fixtures/login.json new file mode 100644 index 000000000..0b653fdfc --- /dev/null +++ b/src/Ombi/cypress/fixtures/login.json @@ -0,0 +1,4 @@ +{ + "username": "automation", + "password": "password" +} \ No newline at end of file diff --git a/src/Ombi/cypress/integration/vote.feature.spec.js b/src/Ombi/cypress/integration/vote.feature.spec.js index 479d4dd1e..8953a430c 100644 --- a/src/Ombi/cypress/integration/vote.feature.spec.js +++ b/src/Ombi/cypress/integration/vote.feature.spec.js @@ -4,6 +4,7 @@ describe('Voting Feature', function () { beforeEach(function () { cy.login('automation', 'password').then(() => { + cy.removeAllMovieRequests(); cy.createUser('basicUser', 'password', [{ value: "requestmovie", @@ -28,6 +29,7 @@ describe('Voting Feature', function () { Enabled: "true", }, ]); + // Enable voting cy.request({ method: 'POST', @@ -43,22 +45,26 @@ describe('Voting Feature', function () { } }); - // Login as the regular user now - cy.clearLocalStorage(); - + // Login as regular user cy.login('basicUser', 'password').then(() => { - cy.visit('/vote'); + cy.visit('/vote'); }); }); }); + /// + /// Make sure we can load the page + /// it('Loads votes page', function () { // cy.login('basicUser','password'); cy.contains("Vote"); }); + /// + /// Make sure that when we request a movie it automatically get's upvoted + /// it('Request Movie automatically upvotes when I am the requestor', function () { cy.requestMovie(335983).then(() => { cy.visit('/vote'); @@ -70,7 +76,9 @@ describe('Voting Feature', function () { }); }); - + /// + /// Make sure that when we request a tv show it automatically get's upvoted + /// it('Request TV automatically upvotes when I am the requestor', function () { cy.requestAllTv(305288).then(() => { cy.visit('/vote'); @@ -82,5 +90,51 @@ describe('Voting Feature', function () { }); }); + /// + /// Upvotes a movie with a different user, the votes should eq 2 + /// Meaning it should be approved now + /// + it.only('Upvote Movie to be approved', function () { + cy.login('basicUser2', 'password').then(() => { + cy.requestMovie(439079).then(() => { + cy.login('basicUser', 'password').then(() => { + + cy.visit('/vote'); + cy.contains('The Nun').should('have.attr', 'data-test').then(($id) => { + cy.get('#' + $id + 'upvote').click(); + cy.verifyNotification('Voted!'); + + // Verify it's in the completed panel + cy.get('#completedVotes').click(); cy.contains('The Nun').should('have.attr', 'data-test').then(($id) => { + cy.get('#' + $id + 'upvote').should('have.attr', 'disabled'); + cy.get('#' + $id + 'downvote').should('not.have.attr', 'disabled'); + }); + }); + }); + }); + }); + }); + + it.only('Downvote Movie', function () { + cy.login('basicUser2', 'password').then(() => { + cy.requestMovie(439079).then(() => { + cy.login('basicUser', 'password').then(() => { + + cy.visit('/vote'); + cy.contains('The Nun').should('have.attr', 'data-test').then(($id) => { + cy.get('#' + $id + 'downvote').click(); + cy.verifyNotification('Voted!'); + + // Verify it's in the completed panel + cy.get('#completedVotes').click(); cy.contains('The Nun').should('have.attr', 'data-test').then(($id) => { + cy.get('#' + $id + 'upvote').should('not.have.attr', 'disabled'); + cy.get('#' + $id + 'downvote').should('have.attr', 'disabled'); + }); + }); + }); + }); + }); + }); + }); \ No newline at end of file diff --git a/src/Ombi/cypress/integration/wizard.spec.js b/src/Ombi/cypress/integration/wizard.spec.js index d1487c8ca..253922496 100644 --- a/src/Ombi/cypress/integration/wizard.spec.js +++ b/src/Ombi/cypress/integration/wizard.spec.js @@ -1,7 +1,9 @@ +/// + describe('Wizard Setup Tests', function() { it('Setup Wizard User', function() { - cy.visit('http://localhost:3577/'); - cy.url().should('include', '/Wizard') + cy.visit('/'); + cy.url().should('include', 'Wizard') cy.get('[data-test=nextbtn]').click(); diff --git a/src/Ombi/cypress/support/commands.js b/src/Ombi/cypress/support/commands.js index 4e223d54e..f4e4bfb4e 100644 --- a/src/Ombi/cypress/support/commands.js +++ b/src/Ombi/cypress/support/commands.js @@ -25,6 +25,7 @@ // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) Cypress.Commands.add('login', (username, password) => { + cy.clearLocalStorage(); cy.request({ method: 'POST', url: '/api/v1/token', @@ -60,4 +61,3 @@ Cypress.Commands.add('verifyNotification', (text) => { cy.get('.ui-growl-title').should('be.visible'); cy.get('.ui-growl-title').next().contains(text) }); - diff --git a/src/Ombi/cypress/support/request.commands.js b/src/Ombi/cypress/support/request.commands.js index ab4222cbf..4c936a4bc 100644 --- a/src/Ombi/cypress/support/request.commands.js +++ b/src/Ombi/cypress/support/request.commands.js @@ -36,5 +36,15 @@ Cypress.Commands.add('requestAllTv', (tvId) => { headers: { 'Authorization': 'Bearer ' + window.localStorage.getItem('id_token'), } - }) + }); +}) + +Cypress.Commands.add('removeAllMovieRequests', () => { + cy.request({ + method: 'DELETE', + url: '/api/v1/request/movie/all', + headers: { + 'Authorization': 'Bearer ' + window.localStorage.getItem('id_token'), + } + }); }) \ No newline at end of file