Skip to content

Commit

Permalink
mark as complete feature and some styling
Browse files Browse the repository at this point in the history
  • Loading branch information
AnveshNalimela committed Feb 3, 2024
1 parent 7051e94 commit 17ff0ec
Show file tree
Hide file tree
Showing 13 changed files with 439 additions and 86 deletions.
2 changes: 1 addition & 1 deletion __tests__/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('Test LMS Application', () => {

expect(response.statusCode).toBe(302); // Redirect after successful login
});
});

});

});
33 changes: 29 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const app = express();
const path = require("path");
const { User, Course, Chapter, Page, Enrollment, Completed } = require("./models");
const bodyParser = require("body-parser");

const passport = require('passport');
const connectEnsureLogin = require('connect-ensure-login');
const session = require('express-session');
Expand All @@ -14,7 +15,6 @@ const flash = require('connect-flash');




app.use(bodyParser.json());
app.use(express.urlencoded({ extended: false }));
app.set("views", path.join(__dirname, "views"));
Expand Down Expand Up @@ -82,14 +82,20 @@ app.get("/", (request, response) => {
return response.redirect("/page");
}
else {
return response.render("index.ejs");
return response.render("index.ejs", {
})

}
});



//route to signup page
app.get("/signup", async (request, response) => { response.render('signup.ejs') })
app.get("/signup", async (request, response) => {
response.render('signup.ejs', {

})
})


//route for new user signup "user"
Expand Down Expand Up @@ -125,6 +131,7 @@ app.post("/user", async (request, response) => {
app.get("/login", async (request, response) => {
console.log("login failed")
response.render('login.ejs', {

message: request.flash('error')
});
});
Expand Down Expand Up @@ -399,6 +406,22 @@ app.get('/schapter/:chapterId', connectEnsureLogin.ensureLoggedIn(), async (requ

})

})
app.get("/spage/:pageId", connectEnsureLogin.ensureLoggedIn(), async (request, response) => {

const page = await Page.findByPk(request.params.pageId)
const chapter = await Chapter.findByPk(page.chapterId)
const course = await Course.findByPk(chapter.courseId)
const enrollment = await Enrollment.findOne({ where: { userId: request.user.id, courseId: course.id } })
const CompletedStatus = await Completed.findOne({ where: { userId: request.user.id, courseId: course.id, chapterId: chapter.id, pageId: page.id } })
await response.render("spage.ejs", {
page: page,
chapter: chapter,
course: course,
CompletedStatus: CompletedStatus,
})


})
//================Routes-related-to-completion-of-page================
app.post("/completePage/:pageId", connectEnsureLogin.ensureLoggedIn(), async (request, response) => {
Expand All @@ -413,6 +436,8 @@ app.post("/completePage/:pageId", connectEnsureLogin.ensureLoggedIn(), async (re
console.log("Page already marked as Compeleted")




} else {
const completePage = await Completed.create({
userId: request.user.id,
Expand All @@ -428,7 +453,7 @@ app.post("/completePage/:pageId", connectEnsureLogin.ensureLoggedIn(), async (re
request.flash('info', 'Page marked as Compeleted.');

}
response.redirect(`/schapter/${chapter.id}`)
response.redirect(`/spage/${page.id}`)
})


Expand Down
29 changes: 28 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
"bcryptjs": "^2.4.3",
"connect-ensure-login": "^0.1.1",
"connect-flash": "^0.1.1",
"cookie-parser": "^1.4.6",
"ejs": "^3.1.9",
"express": "^4.18.2",
"express-session": "^1.17.3",
"mysql2": "^3.7.1",
"passport": "^0.7.0",
"passport-local": "^1.0.0",
"pg": "^8.11.3",
"sequelize": "^6.35.2"
"sequelize": "^6.35.2",
"tiny-csrf": "^1.1.4"
}
}
123 changes: 123 additions & 0 deletions sample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// __tests__/app.test.js
const { sequelize } = require('../models');
const request = require('supertest');
const app = require('../app'); // Adjust the path based on your project structure
const { User, Educator, Student, Enrollments, Course, Chapter, Page } = require('../models');
const bcrypt = require('bcryptjs');

describe('Test LMS Application', () => {
beforeAll(async () => {
await sequelize.sync({ force: true });
// Setup: Create a test user, educator, and course for testing
const hashedPwd = await bcrypt.hash('password123', 10);

await User.create({
name: 'Test User',
email: 'testuser@example.com',
password: hashedPwd,
role: 'student',
});

await Course.create({
name: 'Test Course',
description: 'Test Course Description',
educatorId: 1, // Assuming the test educator has id 1
});
});

afterAll(async () => {
// Teardown: Cleanup the database after testing
await User.destroy({ where: {} });
await Course.destroy({ where: {} });
});

describe('Signup and Login', () => {
test('should allow a user to sign up ', async () => {
const response = await request(app)
.post('/user')
.send({
name: 'John Doe',
email: 'john.doe@example.com',
password: 'password123',
role: 'student',
});

expect(response.statusCode).toBe(302); // Redirect after successful signup
});
});
describe('Signup and Login', () => {
test('should allow a user to log in', async () => {
const loginResponse = await request(app)
.post('/session')
.send({
email: 'john.doe@example.com',
password: 'password123',
});

expect(loginResponse.statusCode).toBe(302); // Redirect after successful login
});
});

describe('Password Change', () => {
test('should allow a user to change password', async () => {
const agent = request.agent(app);

// Log in as an existing user
await agent.post('/session').send({
email: 'testuser@example.com',
password: 'password123',
});

const response = await agent
.post('/password ')
.send({
newPassword: 'newpassword123',
confirmPassword: 'newpassword123',
});

expect(response.statusCode).toBe(302);

// Log in with the new password
const loginResponse = await agent.post('/session').send({
email: 'testuser@example.com',
password: 'newpassword123',
});

expect(loginResponse.statusCode).toBe(302);
});
});
describe('Educator features Test Suite', () => {
test('should allow educator to create course', async () => {
const response = await request(app)
.post('/course')
.send({
courseName: 'Test Course',
courseDescription: 'Test Course Description',
})

expect(response.statusCode).toBe(302); // Redirect after successful login
});
test('should allow educator to create chapter', async () => {
const response = await request(app)
.post('/chapter')
.send({
chapterName: 'Test Chapter',

})

expect(response.statusCode).toBe(302); // Redirect after successful login
});
test('should allow educator to create Page', async () => {
const response = await request(app)
.post('/page')
.send({
pageName: 'Test Page',

})

expect(response.statusCode).toBe(302); // Redirect after successful login
});

});

});
Loading

0 comments on commit 17ff0ec

Please sign in to comment.