Skip to content

Commit

Permalink
Merge pull request #33 from fac-14/express-routes-setup
Browse files Browse the repository at this point in the history
Express routes setup
  • Loading branch information
Armand-Lluka authored Sep 13, 2018
2 parents 3d0fa7a + e432241 commit a12d101
Show file tree
Hide file tree
Showing 18 changed files with 229 additions and 75 deletions.
3 changes: 3 additions & 0 deletions src/controllers/accepted-challenge-select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.get = (req, res) => {
res.render("accepted-challenge-select", { layout: "content-selected" });
};
4 changes: 2 additions & 2 deletions src/controllers/challSelect.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
exports.get = (req, res) => {
res.render("challSelect");
};
res.render("challSelect", { layout: "content-selected" });
};
30 changes: 26 additions & 4 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// boooo index.js
const express = require('express');
const express = require("express");
const router = express.Router();

const landing = require("./landing");
Expand All @@ -8,6 +8,11 @@ const login = require("./login");
const dashboard = require("./dashboard");
const challSelect = require("./challSelect");
const inventory = require("./inventory");
const learn = require("./learn");
const userStats = require("./user-stats");
const itemSelect = require("./item-select");
const acceptedChallSelect = require("./accepted-challenge-select");

const errorRoute = require("./error-route");
const error = require("./error");

Expand All @@ -17,12 +22,29 @@ router.get("/", landing.get);
// router.get("login", login.get);
// router.post("login", login.post);
router.get("/dashboard", dashboard.get);
router.get("/challSelect", challSelect.get);
router.get("/challenge", challSelect.get);
router.get("/inventory", inventory.get);
router.get("/make-error", errorRoute);
router.get("/learn", learn.get);
router.get("/stats", userStats.get);
router.get("/inventory-item", itemSelect.get);
router.get("/my-challenge/", acceptedChallSelect.get);

// accepting and completing challenges
router.post("/challenge/accepted", (req, res) => {
// insert query here to add accepted challenge to database
console.log("Challenge accepted!");
res.redirect(302, "/dashboard");
res.end();
});
router.post("/challenge/completed", (req, res) => {
// insert query here to add completed challenge to database
console.log("Challenge completed!");
res.redirect(302, "/dashboard");
res.end();
});

router.use(error.client);
// router.use(error.server);


module.exports = router;
module.exports = router;
3 changes: 3 additions & 0 deletions src/controllers/item-select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.get = (req, res) => {
res.render("item-select", { layout: "content-selected" });
};
4 changes: 2 additions & 2 deletions src/controllers/landing.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
exports.get = (req, res) => {
res.render("landing");
};
res.render("landing", { layout: "logged-out" });
};
3 changes: 3 additions & 0 deletions src/controllers/learn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.get = (req, res) => {
res.render("learn");
};
3 changes: 3 additions & 0 deletions src/controllers/user-stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.get = (req, res) => {
res.render("user-stats");
};
6 changes: 6 additions & 0 deletions src/views/accepted-challenge-select.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h2>User is viewing details of one of their accepted challenges</h2>

<form action="/challenge/completed" method="POST">
<h1>Challenge completed?</h1>
<button type="submit">Yes!</button>
</form>
7 changes: 6 additions & 1 deletion src/views/challSelect.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{{!-- hello again --}}

<h1>this is challange no 1</h1>
<h1>this is the selected challenge</h1>

<form action="/challenge/accepted" method="POST">
<h1>Accept challenge?</h1>
<button type="submit">Yes!</button>
</form>
2 changes: 2 additions & 0 deletions src/views/dashboard.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h2>This is home dashboard where user can see their challenges</h2>

<ul>
<li>Item 1</li>
<li>item 2</li>
Expand Down
2 changes: 2 additions & 0 deletions src/views/inventory.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h2>This is where the user can view suggested zero waste items to buy</h2>

<ul>
<li>1</li>
<li>2</li>
Expand Down
1 change: 1 addition & 0 deletions src/views/item-select.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2>The user has selected an inventory item to learn more</h2>
18 changes: 18 additions & 0 deletions src/views/layouts/content-selected.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{!-- hello again --}} {{!-- this is the layout for when item is selected e.g. challenge or inventory item --}}

<!DOCTYPE html>
<html lang="en">
{{> header}}

<body>
{{> navbar}}

<main>
<h1>Content Selected Layout!</h1>
{{{body}}}
</main>
{{> footer}}

</body>

</html>
18 changes: 18 additions & 0 deletions src/views/layouts/logged-out.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{!-- hello again --}} {{!-- layout for when the user isn't logged in --}}

<!DOCTYPE html>
<html lang="en">
{{> header}}

<body>
{{> navbar}}

<main>
<h1>Logged-out layout!</h1>
{{{body}}}
</main>
{{> footer}}

</body>

</html>
20 changes: 10 additions & 10 deletions src/views/layouts/main.hbs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{{!-- hello again --}}
{{!-- hello again --}} {{!-- this is the main layout for when you're logged in --}}

<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
{{> header}}
{{> header}}

<body>
{{> navbar}}
<body>
{{> navbar}}

<main>
{{{body}}}
</main>
{{> footer}}
<main>
{{{body}}}
</main>
{{> footer}}

</body>
</body>

</html>
1 change: 1 addition & 0 deletions src/views/learn.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2>This is where the user can learn about zero waste</h2>
1 change: 1 addition & 0 deletions src/views/user-stats.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2>This is where the user can view their stats</h2>
178 changes: 122 additions & 56 deletions test/routes.test.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,136 @@
/* eslint-disable */

const supertest = require('supertest');
const app = require("../src/app.js")
const supertest = require("supertest");
const app = require("../src/app.js");

describe("Test the root", () => {
test("It should respond to the GET method", done => {
supertest(app)
.get('/')
.then(response => {
expect(response.statusCode).toBe(200);
done();
})
})
})
test("It should respond to the GET method", done => {
supertest(app)
.get("/")
.then(response => {
expect(response.statusCode).toBe(200);
done();
});
});
});

describe("Test the dashboard page", () => {
test("Expecting a 200 status return", done =>{
supertest(app)
.get('/dashboard/')
.then(response => {
expect(response.statusCode).toBe(200);
done();
})
})
})
test("Expecting a 200 status return", done => {
supertest(app)
.get("/dashboard/")
.then(response => {
expect(response.statusCode).toBe(200);
done();
});
});
});

describe("Test the challSelect page", () => {
test("Expecting a 200 status return", done =>{
supertest(app)
.get('/challSelect/')
.then(response => {
expect(response.statusCode).toBe(200);
done();
})
})
})
test("Expecting a 200 status return", done => {
supertest(app)
.get("/challenge/")
.then(response => {
expect(response.statusCode).toBe(200);
done();
});
});
});

describe("Test the inventory page", () => {
test("Expecting a 200 status return", done =>{
supertest(app)
.get('/inventory/')
.then(response => {
expect(response.statusCode).toBe(200);
done();
})
})
})
test("Expecting a 200 status return", done => {
supertest(app)
.get("/inventory/")
.then(response => {
expect(response.statusCode).toBe(200);
done();
});
});
});

describe("Test the learn page", () => {
test("Expecting a 200 status return", done => {
supertest(app)
.get("/learn/")
.then(response => {
expect(response.statusCode).toBe(200);
done();
});
});
});

describe("Test the accepted challenge page", () => {
test("Expecting a 200 status return", done => {
supertest(app)
.get("/my-challenge/")
.then(response => {
expect(response.statusCode).toBe(200);
done();
});
});
});

describe("Test the stats page", () => {
test("Expecting a 200 status return", done => {
supertest(app)
.get("/stats/")
.then(response => {
expect(response.statusCode).toBe(200);
done();
});
});
});

describe("Test the inventory item page", () => {
test("Expecting a 200 status return", done => {
supertest(app)
.get("/inventory-item/")
.then(response => {
expect(response.statusCode).toBe(200);
done();
});
});
});

describe("Test challenge accepted", () => {
test("Expecting a 302 status return", done => {
supertest(app)
.post("/challenge/accepted/")
.then(response => {
expect(response.statusCode).toBe(302);
done();
});
});
});

describe("Test challenge completed", () => {
test("Expecting a 302 status return", done => {
supertest(app)
.post("/challenge/completed/")
.then(response => {
expect(response.statusCode).toBe(302);
done();
});
});
});

describe("Test the error-route page", () => {
test("Expecting a 500 status return", done =>{
supertest(app)
.get('/make-error/')
.then(response => {
expect(response.statusCode).toBe(500);
done();
})
})
})
test("Expecting a 500 status return", done => {
supertest(app)
.get("/make-error/")
.then(response => {
expect(response.statusCode).toBe(500);
done();
});
});
});

describe("Test an incorrect route for 404", () => {
test("Expecting a 404 status return", done =>{
supertest(app)
.get('/armandisgreat/')
.then(response => {
expect(response.statusCode).toBe(404);
done();
})
})
})
test("Expecting a 404 status return", done => {
supertest(app)
.get("/armandisgreat/")
.then(response => {
expect(response.statusCode).toBe(404);
done();
});
});
});

0 comments on commit a12d101

Please sign in to comment.