diff --git a/__tests__/app.js b/__tests__/app.js index 6fe50fb..ec605e7 100644 --- a/__tests__/app.js +++ b/__tests__/app.js @@ -119,5 +119,62 @@ describe('Test LMS Application', () => { }); }); + describe('Student Features Test Suite', () => { + test('should student 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 + }); + test('should student allow enroll in a course', async () => { + const courseId = 'your-course-id'; + const response = await request(app) + .post(`/enrollCourse/${courseId}`) + + expect(response.statusCode).toBe(302); // Redirect after successful signup + + }); + test('should student allow mark a page as completed ', async () => { + const pageId = 1; + const response = await request(app) + .post(`/completePage/${pageId}`) + + expect(response.statusCode).toBe(302); + + }); + test('User can signout of application ', async () => { + + const response = await request(app) + .get('/signout') + + expect(response.statusCode).toBe(302); + + }); + }); }); + + + + + + + + + + + + + + + + + + + diff --git a/app.js b/app.js index d06c4cc..27b015d 100644 --- a/app.js +++ b/app.js @@ -491,7 +491,10 @@ app.get("/signout", (request, response, next) => { request.logout((err) => { if (err) { return next(err); } console.log("Sign out Successfully") - response.render('signOut.ejs'); + response.redirect('/signOut-success'); }); }); +app.get("/signOut-success", async (request, response) => { + await response.render("signOut.ejs") +}) module.exports = app; \ No newline at end of file diff --git a/sample copy.html b/sample copy.html deleted file mode 100644 index e69de29..0000000 diff --git a/sample.html b/sample.html deleted file mode 100644 index f53d3fd..0000000 --- a/sample.html +++ /dev/null @@ -1,123 +0,0 @@ -// __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 -}); - -}); - -}); \ No newline at end of file diff --git a/sample.txt b/sample.txt deleted file mode 100644 index 6fe50fb..0000000 --- a/sample.txt +++ /dev/null @@ -1,123 +0,0 @@ -// __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 - }); - - }); - -}); diff --git a/views/course.ejs b/views/course.ejs index 9b673b6..75ad23a 100644 --- a/views/course.ejs +++ b/views/course.ejs @@ -15,7 +15,7 @@
-