Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amended integration tests, added dropDatabase function, added new tests #16

Merged
merged 1 commit into from
Jun 15, 2023
Merged
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
34 changes: 34 additions & 0 deletions cypress/CICD_Info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# CI/CD Pipeline Information

This project utilises Cypress, Github Actions and Cypress Cloud.

- Cypress is used to run the integration tests, including some end-to-end testing.

- Github Actions runs these tests on every successful pull request.

- Cypress Cloud stores the test data and allows for tracking and analytics in our bug reporting.

At the moment, the project is not deployed in production, We aim to implement continuos development once this has been achieved.


## Pipeline steps:

1. A pull request is made and successfully merged with main branch.
2. Github Actions triggers and installs Node.js.
3. Github Actions installs a MongoDB, installs the project dependencies and makes a build.
4. Unit tests are run using Jest.
5. The test server starts and Cypress begins its test run.
6. The Cypress test begins by attempting a signup and creating an admin profile, which is then used for later tests.
7. At the end of the tests, the test database is dropped.
8The test run completes and test data is stored in Cypress Cloud for analysis.

At this point we aim to implement the automatic deployment to Render.

## Test Scope

As written in the test plan, we aim for the Cypress Integration tests to have total coverage of functionality,
as well as some coverage for performance if we have time.

We utilise random data generation for login, as well as


28 changes: 0 additions & 28 deletions cypress/integration/user_can_create_post.js

This file was deleted.

28 changes: 23 additions & 5 deletions cypress/integration/user_can_login.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,36 @@
// And be able to enter my account details, So that I can be taken to my homepage


describe("Login - this test fails without an admin user", () => {
describe("Login", () => {


it("A user signs in and is redirected to /posts", () => {

// sign in
cy.signIn();

cy.url().should("include", "/posts");

});




it("A user attempts to sign in with incorrect details", () => {

// sign in
cy.visit("/");
cy.get('a.global-button[href="/sessions/new"]').click()
cy.get("#email").type("admin@example.com");
cy.get('a.global-button[href="/sessions/new"]').click();
cy.get("#email").type("wrongemail@example.com");
cy.get("#password").type("Password!123");
cy.get("#submit").click();
cy.url().should("include", "/posts");

cy.url().should("not.include", "/posts");

});





});
9 changes: 3 additions & 6 deletions cypress/integration/user_can_logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ describe("Logout", () => {


// sign in
cy.visit("/");
cy.get('a.global-button[href="/sessions/new"]').click()
cy.get("#email").type("[email protected]");
cy.get("#password").type("Password!123");
cy.get("#submit").click();
cy.signIn();

cy.url().should("include", "/posts");


cy.get("#logout").click();
cy.get('input[type="submit"][value="Log Out"].global-button.logout').click();

cy.url().should("not.include", "/posts");

});
Expand Down
71 changes: 71 additions & 0 deletions cypress/integration/user_can_see_and_create_post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Feature: Posts Page

// As a logged-in user,
// I want to be able to see posts, See comments on posts, and number of likes, So that I can connect with friends.



describe("Posts", () => {




it("A signed in user can create a post and see it displayed", () => {


// sign in
cy.signIn();

cy.url().should("include", "/posts");

//create a new post
cy.get('a.global-button.new-post-link[href="/posts/new"]').click();
cy.get('#message').type('Hello, World!');
cy.get('input[type="submit"][value="Submit"]').click();

cy.get(".posts").should("contain", "Hello, world!");
});





it("A signed in user cannot create an empty post", () => {


// sign in
cy.signIn();

cy.url().should("include", "/posts");

cy.get('a.global-button.new-post-link[href="/posts/new"]').click();

//submit without typing anything
cy.get('input[type="submit"][value="Submit"]').click();

//should not take you back to posts at this point
cy.url().should("not.include", "/posts");
});







it("A signed in user can see the like count on a post", () => {


// sign in
cy.signIn();

cy.url().should("include", "/posts");

cy.get('ul.posts li').should('contain', '0 Likes');

});




});
28 changes: 0 additions & 28 deletions cypress/integration/user_can_see_posts.js

This file was deleted.

33 changes: 0 additions & 33 deletions cypress/integration/user_can_see_posts_count_on_post.js

This file was deleted.

46 changes: 44 additions & 2 deletions cypress/integration/user_can_sign_up_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,63 @@ const chance = new Chance();


describe("Signup", () => {


it("A user navigates from homepage to signup and creates a new account", () => {
const new_email = chance.email();

// sign up
cy.visit("/");
cy.get('a.global-button[href="/users/new"]').click()
cy.get("#email").type(new_email);
cy.get("#password").type("password!234");
cy.get("#confirm-password").type("password!234");
cy.get("#password").type("Password!234");
cy.get("#confirm-password").type("Password!234");
cy.get("#first-name").type("Mrtest")
cy.get("#last-name").type("Testtest")
cy.get("#submit").click();

cy.url().should("include", "/posts");
});



it("A user navigates from homepage to signup and creates a new account with mismatched passwords", () => {
const new_email = chance.email();

// sign up
cy.visit("/");
cy.get('a.global-button[href="/users/new"]').click();
cy.get("#email").type(new_email);
cy.get("#password").type("Password!234");
cy.get("#confirm-password").type("Password!345");
cy.get("#first-name").type("Mrtest")
cy.get("#last-name").type("Testtest")
cy.get("#submit").click();

cy.url().should("not.include", "/posts");
});



it("A user navigates from homepage to signup and creates a new account with an email that already exists", () => {
const new_email = chance.email();

// sign up
cy.visit("/");
cy.get('a.global-button[href="/users/new"]').click();
cy.get("#email").type("[email protected]");
cy.get("#password").type("Password!234");
cy.get("#confirm-password").type("Password!345");
cy.get("#first-name").type("Mrtest")
cy.get("#last-name").type("Testtest")
cy.get("#submit").click();

cy.url().should("not.include", "/posts");
});




});


Expand Down
22 changes: 18 additions & 4 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,24 @@
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

module.exports = function() {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
//module.exports = function() {
// // `on` is used to hook into various events Cypress emits
// // `config` is the resolved Cypress config
//}


const mongoose = require('mongoose');

module.exports = (on) => {
on('task', {
async clearDb() {
await mongoose.connect('mongodb://0.0.0.0/acebook_test');
await mongoose.connection.db.dropDatabase();
await mongoose.connection.close();
return null;
}
});
};



21 changes: 21 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,24 @@
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })


const mongoose = require('mongoose');

Cypress.Commands.add('clearDb', () => {
return cy.task('clearDb').then(() => {
return new Promise((resolve) => {
mongoose.connection.once('open', () => {
resolve();
});
});
});
});

Cypress.Commands.add('signIn', () => {
cy.visit("/");
cy.get('a.global-button[href="/sessions/new"]').click();
cy.get("#email").type("[email protected]");
cy.get("#password").type("Password!123");
cy.get("#submit").click();
});
Loading