Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@

/vote/target
/vote/.idea
/vote/vote.iml
/vote/vote.iml

node_modules
screenshots
6 changes: 6 additions & 0 deletions .oktetoignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
.github
.idea
.vscode
node_modules
screenshots
33 changes: 33 additions & 0 deletions e2e/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const pgp = require('pg-promise');

const dbConfig = {
dbHost: `postgresql.${process.env.OKTETO_NAMESPACE}`,
dbLogin: 'okteto',
dbPassword: 'okteto',
dbName: 'votes',
dbPort: 5432,
};

const connectionString = `postgres://${dbConfig.dbLogin}:${dbConfig.dbPassword}@${dbConfig.dbHost}:${dbConfig.dbPort}/${dbConfig.dbName}`;
const db = pgp()(connectionString);

module.exports = {
'projectId': 'okteto',
e2e: {
voteUrl: 'https://vote.example.com',
resultUrl: 'https://result.example.com',
setupNodeEvents(on, config) {
on('task', {
getVotesForA() {
const query = "SELECT COUNT(id) AS count FROM votes WHERE vote='a'"; // any query you want to check
return db.oneOrNone(query);
},
getVotesForB() {
const query = "SELECT COUNT(id) AS count FROM votes WHERE vote='b'"; // any query you want to check
return db.oneOrNone(query);
},
});
},
defaultCommandTimeout: 20000,
},
}
56 changes: 56 additions & 0 deletions e2e/cypress/e2e/check-if-online/spec.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/// <reference types="cypress" />

it('check that vote has the right title', () => {
cy.visit(Cypress.env('voteUrl'))
cy.title().should('eq', 'Burritos vs Tacos!')
})

it('i love burritos', () => {
cy.visit(Cypress.env('voteUrl'))
cy.title().should('eq', 'Burritos vs Tacos!')

// get the current votes
cy.task('getVotesForA').then((votesForA) => {
cy.task('getVotesForB').then((votesForB) => {
expect(votesForA.count).to.not.be.null
expect(votesForB.count).to.not.be.null

// vote for option A
cy.get('#a').click();

// Assert that the button is disabled
cy.get('#a').should('be.disabled');

// Assert that checkmark was displayed after voting
cy.get('#a')
.find('i')
.should('exist')
.and('have.class', 'fa')
.and('have.class', 'fa-check-circle');

cy.task('getVotesForA').then((votesForAAfter) => {
cy.task('getVotesForB').then((votesForBAfter) => {
expect(votesForAAfter.count).to.not.be.null
expect(votesForBAfter.count).to.not.be.null

// verify that the votes are updated in the database
const expectedVotesForA = parseInt(votesForA.count) + 1
const actualVotesForA = parseInt(votesForAAfter.count)
expect(expectedVotesForA).to.be.equal(actualVotesForA)
expect(votesForBAfter.count).to.be.equal(votesForB.count)

const totalVotes = actualVotesForA + parseInt(votesForBAfter.count)
cy.visit(Cypress.env('resultUrl'))
cy.origin(Cypress.env('resultUrl'), {args: {totalVotes}}, ({totalVotes}) => {
// verify that the votes are updated in the results service
cy.title().should('eq', 'Burritos vs Tacos -- Result')
cy.get('#result')
.find('span')
.should('exist')
.and('have.text', `${totalVotes} votes`)
})
})
})
})
})
})
6 changes: 6 additions & 0 deletions e2e/cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
Loading