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

Testing workflow #522

Closed
wants to merge 10 commits into from
Closed
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
40 changes: 40 additions & 0 deletions .github/workflows/cypress-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Node.js CI with MongoDB and cypress

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
mongodb-version: ['6.0']

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.10.0
with:
mongodb-version: ${{ matrix.mongodb-version }}

- name: Cypress run
uses: cypress-io/github-action@v6
with:
build: npm run build --if-present
start: npm run start:test
wait-on: http://localhost:3030


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ It uses:

## Card wall

REPLACE THIS TEXT WITH A LINK TO YOUR CARD WALL
https://trello.com/b/LTthkPOI/acebook-bl

## Quickstart

Expand Down
2 changes: 1 addition & 1 deletion bin/www
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
/* eslint-disable no-process-exit */

/**
* Module dependencies.
Expand Down
2 changes: 1 addition & 1 deletion controllers/home.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const HomeController = {
Index: (req, res) => {
res.render("home/index", { title: "Acebook" });
res.render("home/index", { title: "Bassbook" });
},
};

Expand Down
4 changes: 3 additions & 1 deletion controllers/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const PostsController = {
res.render("posts/new", {});
},
Create: (req, res) => {
const post = new Post(req.body);
const message = req.body.message;
const author = req.session.user.username;
const post = new Post({message, author});
post.save((err) => {
if (err) {
throw err;
Expand Down
3 changes: 2 additions & 1 deletion controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ const User = require("../models/user");

const UsersController = {
New: (req, res) => {
res.render("users/new", {});
res.render("users/new", { title: "Acebook" });
},

Create: (req, res) => {
const user = new User(req.body);
console.log('user:', user)
user.save((err) => {
if (err) {
throw err;
Expand Down
1 change: 1 addition & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
video: true,
e2e: {
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/user_can_see_posts_count_on_post.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ describe("Timeline", () => {
it("can see likes count on a new post", () => {
// sign up
cy.visit("/users/new");
cy.get("#username").type("someone");
cy.get("#email").type("someone@example.com");
cy.get("#password").type("password");
cy.get("#submit").click();
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/user_can_sign_in.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ describe("Authentication", () => {
it("A user signs in and is redirected to /posts", () => {
// sign up
cy.visit("/users/new");
cy.get("#username").type("someone");
cy.get("#email").type("someone@example.com");
cy.get("#password").type("password");
cy.get("#submit").click();
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/user_can_sign_up.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ describe("Registration", () => {
it("A user signs up and is redirected to sign in", () => {
// sign up
cy.visit("/users/new");
cy.get("#username").type("someone");
cy.get("#email").type("someone@example.com");
cy.get("#password").type("password");
cy.get("#submit").click();
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/user_can_submit_posts.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ describe("Timeline", () => {
it("can submit posts, when signed in, and view them", () => {
// sign up
cy.visit("/users/new");
cy.get("#username").type("someone");
cy.get("#email").type("someone@example.com");
cy.get("#password").type("password");
cy.get("#submit").click();
Expand Down
1 change: 1 addition & 0 deletions models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const mongoose = require("mongoose");

const PostSchema = new mongoose.Schema({
message: String,
author: String,
likes: { type: Number, default: 0 }
});

Expand Down
1 change: 1 addition & 0 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mongoose = require("mongoose");

const UserSchema = new mongoose.Schema({
username: String,
email: String,
password: String,
});
Expand Down
Loading
Loading