From 2d0c48a8678684d2b3c48f108c55288a44c5bf06 Mon Sep 17 00:00:00 2001 From: TidusJar Date: Wed, 10 Oct 2018 22:29:30 +0100 Subject: [PATCH] Added automation tests for the voting feature --- .../ClientApp/app/vote/vote.component.html | 6 +- .../cypress/integration/vote.feature.spec.js | 86 +++++++++++++++++++ src/Ombi/cypress/support/commands.js | 6 +- src/Ombi/cypress/support/index.js | 3 +- src/Ombi/cypress/support/request.commands.js | 40 +++++++++ 5 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 src/Ombi/cypress/integration/vote.feature.spec.js create mode 100644 src/Ombi/cypress/support/request.commands.js diff --git a/src/Ombi/ClientApp/app/vote/vote.component.html b/src/Ombi/ClientApp/app/vote/vote.component.html index 6d8f8a797..625bb986d 100644 --- a/src/Ombi/ClientApp/app/vote/vote.component.html +++ b/src/Ombi/ClientApp/app/vote/vote.component.html @@ -65,10 +65,10 @@ - - @@ -76,7 +76,7 @@ height: auto; width: 100%;" (click)="toggle($event, vm.image)" src="{{vm.image}}" alt="poster"> - {{vm.title}} + {{vm.title}} diff --git a/src/Ombi/cypress/integration/vote.feature.spec.js b/src/Ombi/cypress/integration/vote.feature.spec.js new file mode 100644 index 000000000..479d4dd1e --- /dev/null +++ b/src/Ombi/cypress/integration/vote.feature.spec.js @@ -0,0 +1,86 @@ +/// + +describe('Voting Feature', function () { + beforeEach(function () { + cy.login('automation', 'password').then(() => { + + + cy.createUser('basicUser', 'password', [{ + value: "requestmovie", + Enabled: "true", + }, { + value: "requesttv", + Enabled: "true", + }, { + value: "requestmusic", + Enabled: "true", + }, + ]); + + cy.createUser('basicUser2', 'password', [{ + value: "requestmovie", + Enabled: "true", + }, { + value: "requesttv", + Enabled: "true", + }, { + value: "requestmusic", + Enabled: "true", + }, + ]); + // Enable voting + cy.request({ + method: 'POST', + url: '/api/v1/Settings/vote', + body: { + Enabled: true, + MovieVoteMax: 2, + MusicVoteMax: 2, + TvShowVoteMax: 2, + }, + headers: { + 'Authorization': 'Bearer ' + window.localStorage.getItem('id_token'), + } + }); + + // Login as the regular user now + cy.clearLocalStorage(); + + cy.login('basicUser', 'password').then(() => { + + cy.visit('/vote'); + }); + + }); + }); + + it('Loads votes page', function () { + // cy.login('basicUser','password'); + cy.contains("Vote"); + }); + + it('Request Movie automatically upvotes when I am the requestor', function () { + cy.requestMovie(335983).then(() => { + cy.visit('/vote'); + cy.get('#completedVotes').click(); + cy.contains('Venom').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('Request TV automatically upvotes when I am the requestor', function () { + cy.requestAllTv(305288).then(() => { + cy.visit('/vote'); + cy.get('#completedVotes').click(); + cy.contains('Stranger Things').should('have.attr', 'data-test').then(($id) => { + cy.get('#' + $id + 'upvote').should('have.attr', 'disabled'); + cy.get('#' + $id + 'downvote').should('not.have.attr', 'disabled'); + }); + }); + }); + + +}); \ No newline at end of file diff --git a/src/Ombi/cypress/support/commands.js b/src/Ombi/cypress/support/commands.js index b44a1e2b5..4e223d54e 100644 --- a/src/Ombi/cypress/support/commands.js +++ b/src/Ombi/cypress/support/commands.js @@ -34,9 +34,12 @@ Cypress.Commands.add('login', (username, password) => { } }) .then((resp) => { - window.localStorage.setItem('id_token', resp.body.access_token) + window.localStorage.setItem('id_token', resp.body.access_token); }); }); +Cypress.Commands.add('removeLogin', () => { + window.localStorage.removeItem('id_token'); +}); Cypress.Commands.add('createUser', (username, password, claims) => { cy.request({ @@ -57,3 +60,4 @@ 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/index.js b/src/Ombi/cypress/support/index.js index d68db96df..38ca34f83 100644 --- a/src/Ombi/cypress/support/index.js +++ b/src/Ombi/cypress/support/index.js @@ -14,7 +14,8 @@ // *********************************************************** // Import commands.js using ES2015 syntax: -import './commands' +import './commands'; +import './request.commands'; // Alternatively you can use CommonJS syntax: // require('./commands') diff --git a/src/Ombi/cypress/support/request.commands.js b/src/Ombi/cypress/support/request.commands.js new file mode 100644 index 000000000..ab4222cbf --- /dev/null +++ b/src/Ombi/cypress/support/request.commands.js @@ -0,0 +1,40 @@ + +Cypress.Commands.add('requestGenericMovie', () => { + cy.request({ + method: 'POST', + url: '/api/v1/request/movie', + body: { + TheMovieDbId: 299536 + }, + headers: { + 'Authorization': 'Bearer ' + window.localStorage.getItem('id_token'), + } + }) +}) + +Cypress.Commands.add('requestMovie', (movieId) => { + cy.request({ + method: 'POST', + url: '/api/v1/request/movie', + body: { + TheMovieDbId: movieId + }, + headers: { + 'Authorization': 'Bearer ' + window.localStorage.getItem('id_token'), + } + }) +}) + +Cypress.Commands.add('requestAllTv', (tvId) => { + cy.request({ + method: 'POST', + url: '/api/v1/request/tv', + body: { + TvDbId: tvId, + RequestAll: true + }, + headers: { + 'Authorization': 'Bearer ' + window.localStorage.getItem('id_token'), + } + }) +}) \ No newline at end of file