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

Dev merge #59

Merged
merged 153 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
deb145b
Create workspace.xml
sofiiagran Sep 19, 2023
424e294
fix
sofiiagran Sep 19, 2023
6ed01ca
Merge remote-tracking branch 'origin/Cert' into offline
sofiiagran Sep 21, 2023
e3c9e51
Renamed to config/.env
ITPini Sep 21, 2023
446c4b0
back-end subscriptions
sofiiagran Sep 21, 2023
3a39037
.gitignore update
Donhusum Sep 22, 2023
65851b6
Added dummy course route
PrometheusBork Sep 22, 2023
d339a4b
Test route
Donhusum Sep 22, 2023
c689c90
Made route to get all subscribed courses of logged in user
Donhusum Sep 23, 2023
107a120
Added a comment to the route
Donhusum Sep 23, 2023
7b15adf
route fix
sofiiagran Sep 25, 2023
2ca5727
Merge branch 'OAT1.1dev' into offline
PrometheusBork Sep 25, 2023
26e3acd
work
sofiiagran Sep 25, 2023
1d1d51f
fix
sofiiagran Sep 25, 2023
bc0281d
Subscribe fix
sofiiagran Sep 25, 2023
5858576
Update User.js model
sofiiagran Sep 25, 2023
5e6c119
course fix
sofiiagran Sep 25, 2023
fd9e323
course fix
sofiiagran Sep 26, 2023
bee52f9
course fix
sofiiagran Sep 26, 2023
5618b64
fix
sofiiagran Sep 26, 2023
090ef21
Merge branch 'dev' into offline
sofiiagran Sep 26, 2023
3694f9a
Rename
sofiiagran Sep 26, 2023
4612d7f
courseRoute fix
sofiiagran Sep 27, 2023
540afd3
Merge branch 'offline' into offline-subscriptions
sofiiagran Sep 27, 2023
976b851
route fix
sofiiagran Sep 27, 2023
ec7451e
routefix
sofiiagran Sep 29, 2023
eff3d57
Merge branch 'offline-subscriptions' into offline-2-subscribe
sofiiagran Oct 2, 2023
59cdeb5
fix login
sofiiagran Oct 2, 2023
a355865
Update courseRoutes.js
sofiiagran Oct 3, 2023
b365658
Update courseRoutes.js
sofiiagran Oct 3, 2023
e29e5f2
Update courseRoutes.js
sofiiagran Oct 4, 2023
0622dcb
Update courseRoutes.js
sofiiagran Oct 4, 2023
225f987
yesb
sofiiagran Oct 4, 2023
8a1285d
Merge branch 'dev' into offline-2-merge
sofiiagran Oct 5, 2023
6e3cfd2
fix
sofiiagran Oct 5, 2023
8af3d23
some fix
sofiiagran Oct 5, 2023
9a0725e
Change a component route to match the app call
Donhusum Oct 7, 2023
fadfdaa
Change URL from plural to singular
Donhusum Oct 7, 2023
9f3e430
Fixed a plural to singular
Donhusum Oct 7, 2023
851fe92
route fix
sofiiagran Oct 9, 2023
4514f87
Back to plural
Donhusum Oct 9, 2023
3c8849d
Update courseRoutes.js
PrometheusBork Oct 9, 2023
76ad10e
Merge branch 'offline-2-merge' of https://github.com/Educado-App/educ…
PrometheusBork Oct 9, 2023
3266ffa
Merge branch 'offline-2-merge' of https://github.com/Educado-App/educ…
sofiiagran Oct 9, 2023
8ac002f
route fix
sofiiagran Oct 9, 2023
775a470
course fix
sofiiagran Oct 10, 2023
47450d0
set up local database
sofiiagran Oct 10, 2023
7a46252
Update coursesTest.js
sofiiagran Oct 10, 2023
9f76b23
Update userRoutes.js
Mafusn Sep 26, 2023
11c9da7
Update README.md
Mafusn Sep 26, 2023
06a3b1d
Update README.md
Mafusn Sep 26, 2023
2e920f3
Update .gitignore
Mafusn Sep 27, 2023
b7dcc1f
More tests work now
Mafusn Sep 27, 2023
d69f8b4
All tests passes
Mafusn Sep 27, 2023
f1e5d5e
update name and email now tested
Mafusn Sep 27, 2023
690683c
Skipped test case is commented out
Mafusn Sep 27, 2023
e9fd47e
Update userList.js
Mafusn Sep 28, 2023
23ba890
First & last name added to user
Mafusn Sep 29, 2023
7a9f628
Update first & last name tested
Mafusn Sep 29, 2023
6c26e6e
Tests a update functions in userRoute
Mafusn Oct 2, 2023
2535c19
All tests passes
Mafusn Oct 2, 2023
ec1494d
Update userRoutes.js
Mafusn Oct 3, 2023
1a02c2a
Slettet comments
Mafusn Oct 3, 2023
7899459
Delete user unit testing
Mafusn Oct 3, 2023
9567d69
Better covered tests
Mafusn Oct 4, 2023
059899f
Revert "Resolved conflicts"
Mafusn Oct 10, 2023
08fc24d
Fix: user route names
Mafusn Oct 10, 2023
9290bbd
Fix: tests moved
Mafusn Oct 10, 2023
6075347
model fix
sofiiagran Oct 10, 2023
47a59ae
Fix of test
Mafusn Oct 10, 2023
c17f1d4
Update userRoutes.spec.js
Mafusn Oct 10, 2023
f9378d0
Small fixes
Mafusn Oct 10, 2023
441c6a7
ESlint fixes
Mafusn Oct 10, 2023
fb6765e
Merge pull request #38 from Educado-App/gamified_temporary
Mafusn Oct 10, 2023
a64cf26
Update README.md
Mafusn Oct 10, 2023
efe9f5b
fix: updated an url to fit format and mobile
Donhusum Oct 10, 2023
a02f81f
Merge remote-tracking branch 'origin/offline-2-merge' into offline-2-…
Donhusum Oct 10, 2023
d6e7fe2
Update keys.js
Mafusn Oct 10, 2023
7791ef0
Update keys.js
Mafusn Oct 10, 2023
f261b9a
fix
sofiiagran Oct 10, 2023
3967544
Use of patterns
Mafusn Oct 10, 2023
0993259
Update User.js
Mafusn Oct 10, 2023
df83981
Merge branch 'dev' into offline-2-fix
sofiiagran Oct 10, 2023
83093bd
Added ErroCodes functionality
Mafusn Oct 10, 2023
640741d
Update userList.js
Mafusn Oct 10, 2023
e6b9478
feat(api): added GET routes for courses
Jatewo Oct 10, 2023
476d446
Tests for deleteUser created
Mafusn Oct 11, 2023
5df739b
Fix of update last name
Mafusn Oct 11, 2023
b428e60
test!
sofiiagran Oct 11, 2023
2cbcc2d
Fix of duplicate code in userRoutes.spec.js
Mafusn Oct 11, 2023
18a43fd
Update globalConfigMongo.json
sofiiagran Oct 11, 2023
bd6c29b
fix(api): Added tests and fixed course model
Jatewo Oct 11, 2023
adba280
fix
sofiiagran Oct 11, 2023
26265fa
feat(api): Added routes for resetting password
Jatewo Oct 11, 2023
b2dfadc
test!! final
sofiiagran Oct 11, 2023
8ddd367
fix model
sofiiagran Oct 11, 2023
d6e4fcf
email case insensitive
MaizeHH Oct 11, 2023
d161d61
Using patch instead of put for updating
Mafusn Oct 12, 2023
49fde30
Last cleanup before merge
Mafusn Oct 12, 2023
fa65699
Merge pull request #39 from Educado-App/gamified_merge
Mafusn Oct 12, 2023
68ca732
Merge branch 'dev' into offline-3-merge
sofiiagran Oct 12, 2023
f0eda5a
model fix
sofiiagran Oct 12, 2023
405835a
fix
sofiiagran Oct 12, 2023
903e90e
route fix
sofiiagran Oct 12, 2023
bfe7e4b
test: Tests added for email helper and authRoutes
Jatewo Oct 12, 2023
4c6a807
renamed to avoid unused tests to fail
sofiiagran Oct 12, 2023
9bc3d6f
format fix
sofiiagran Oct 12, 2023
a6c681a
added specific error messages
sofiiagran Oct 12, 2023
51005cd
removed console log
sofiiagran Oct 12, 2023
ab95d15
removed idea and fixed 404 to 204
sofiiagran Oct 12, 2023
c0ca1d8
fix(router): fixed problem with the router in authRouter
Jatewo Oct 12, 2023
3f60361
fix(router): more fixes to the authRoutes
Jatewo Oct 12, 2023
02e1880
refactor(test): refactored some duplicated code
Jatewo Oct 12, 2023
3391ab2
Merge branch 'cert-reset-password' into cert
Jatewo Oct 12, 2023
dd99df7
Merge branch 'cert' into cert-reset-password-cert
Jatewo Oct 12, 2023
ae89f2c
fix console.log error
sofiiagran Oct 12, 2023
5b1c18f
feat(api): Added safeguard to limit reset password attempts
Jatewo Oct 12, 2023
edda904
test(api): added testing of reset attempts resetting
Jatewo Oct 12, 2023
dd8d226
fix: Removed leftover console.logs
Jatewo Oct 12, 2023
049b10f
fix(tests): fixed some deprecation warning in tests
Jatewo Oct 12, 2023
268808d
damn, many tests and error handling fix
sofiiagran Oct 12, 2023
9a03ac4
fix: Remove package-lock and keys.js from gitignore
Havkost Oct 12, 2023
c691628
fix route and error message
sofiiagran Oct 13, 2023
d44a98a
update tests in route
sofiiagran Oct 13, 2023
236b12b
wopsi, route fix in all tests
sofiiagran Oct 13, 2023
350852f
Merge pull request #44 from Educado-App/offline-3-merge
sofiiagran Oct 13, 2023
4ca2427
fix
sofiiagran Oct 13, 2023
e08b1cf
only removed the out-commented code
sofiiagran Oct 13, 2023
f89a359
fix: Delete __tests__/setup/globalConfigMongo.json
Jatewo Oct 13, 2023
e60c906
feat: added endpoint for reset password code
JackSMunn Oct 13, 2023
88764ac
Merge branch 'dev' into cert-reset-password-merge
JackSMunn Oct 13, 2023
51eb7af
fix: added missing awaits and missing comma in model
Jatewo Oct 13, 2023
25a9a74
Merge pull request #45 from Educado-App/cert-reset-password-merge
Jatewo Oct 13, 2023
d8eb050
fix(test): fixed some errors in signupRoute test
Jatewo Oct 13, 2023
61431de
Merge branch 'cert' into cert-get-courses-merge
Jatewo Oct 13, 2023
dd2993f
feat(api): Added routes for getting courses
Jatewo Oct 15, 2023
52af068
fix: Updated course model
Jatewo Oct 16, 2023
cbb8d49
fix(model): added missing import in course model
Jatewo Oct 16, 2023
aadd64f
fix: Sections field redundancy
JackSMunn Oct 16, 2023
ac13926
fix(model): type of "creator" to contentcreator
JackSMunn Oct 16, 2023
3ee4f00
fix(model): updated possible categories
JackSMunn Oct 16, 2023
3020bb0
feat(api): added edit password functionality
JackSMunn Oct 16, 2023
abe2c55
Merge pull request #47 from Educado-App/cert-get-courses-merge
Jatewo Oct 16, 2023
b4ae575
fix(test): Changed name of test files
JackSMunn Oct 16, 2023
496c43c
Merge branch 'cert-update-password' into cert-update-password-merge
Jatewo Oct 16, 2023
babfacc
test(api): Added test of user PATCH route
Jatewo Oct 16, 2023
1ececf8
Merge pull request #49 from Educado-App/cert-update-password-merge
JackSMunn Oct 17, 2023
29c2185
fix(test): Fixed some duplicated and deprecated tests
Jatewo Oct 17, 2023
e0a4ff2
Merge pull request #54 from Educado-App/dev-test-fix
Mafusn Oct 17, 2023
824af2a
Merge branch 'staging' into dev-merge
Jatewo Oct 17, 2023
6f6674f
fix(test): Deleted some leftover commented-out code
Jatewo Oct 18, 2023
e8738ef
fix: updated to new error messages and fixed auth route types
Jatewo Oct 18, 2023
4ed06ff
fix(api): deleted some leftover duplicate code
Jatewo Oct 18, 2023
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
node_modules
config/dev.js
config/educado-*.json
config/gcp_service.json

*.DS_Store
package-lock.json
dev.js
config/.env
*.idea
.idea

# enviroment
.env
Expand Down
29 changes: 15 additions & 14 deletions __tests__/fixtures/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ const mongoose = require('mongoose');
let connection, db;

module.exports = async function connectDb() {

connection =
connection ||
await mongoose.connect(
global.__MONGO_URI__,
{
useNewUrlParser: true,
useFindAndModify: false
}
);
//db = db || connection.db(global.MONGO_DB_NAME)
db = db || connection.connection.db; // Assign the database object
connection =
connection ||
await mongoose.connect(
global.__MONGO_URI__,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
}
)
//db = db || connection.db(global.__MONGO_DB_NAME__)
db = db || connection.connection.db; // Assign the database object

return db; // Return the database object
};
return db; // Return the database object
Jatewo marked this conversation as resolved.
Show resolved Hide resolved
}
13 changes: 13 additions & 0 deletions __tests__/fixtures/fakeCourse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = function makeFakeCourse() {

return {
sections: [],
title: 'test course',
category: 'test',
difficulty: 1,
hours: 10,
description: "This course is a test course",
dateCreated: new Date(),
dateUpdated: new Date()
};
};
72 changes: 72 additions & 0 deletions __tests__/fixtures/fakeCourses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const courses = [
{
"title": 'fakeCourse1',
"description": 'fakeCourse1 description',
"dateCreated": new Date().toJSON(),
"dateUpdated": new Date().toJSON(),
"category": 'mathematics',
"published": false,
"sections": [],
"creator": [],
"difficulty": 1,
"time": 1,
"rating": 5,
},
{
"title": 'fakeCourse2',
"description": 'fakeCourse2 description',
"dateCreated": new Date().toJSON(),
"dateUpdated": new Date().toJSON(),
"category": 'language',
"published": false,
"sections": [],
"creator": ['1234567891011'],
"difficulty": 1,
"time": 1,
"rating": 5,
},
{
"title": 'fakeCourse3',
"description": 'fakeCourse3 description',
"dateCreated": new Date().toJSON(),
"dateUpdated": new Date().toJSON(),
"category": 'programming',
"published": true,
"sections": [],
"creator": [],
"difficulty": 2,
"time": 3,
"rating": 5,
},
{
"title": 'fakeCourse4',
"description": 'fakeCourse4 description',
"dateCreated": new Date().toJSON(),
"dateUpdated": new Date().toJSON(),
"category": 'music',
"published": true,
"sections": [],
"creator": ['1234567891011'],
"difficulty": 6,
"time": 2,
"rating": 3,
}
];

/**
* @returns {Array} Array of fake courses
*/
function getFakeCourses() {
return courses;
}

/**
* @param {Number} creatorId
* @returns {Array} Array of fake courses created by the creator with the given id
*/
function getFakeCoursesByCreator(creatorId) {
const res = courses.filter(course => course.creator.includes(creatorId));
return res;
}

module.exports = { getFakeCourses, getFakeCoursesByCreator };
8 changes: 8 additions & 0 deletions __tests__/fixtures/fakeResetPasswordToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const mongoose = require('mongoose');

module.exports = function makeFakeResetPasswordToken(token='1234') {
return {
token: token,
expiresAt: new Date() + 1000 * 60 * 60 * 24 * 7,
}
}
14 changes: 14 additions & 0 deletions __tests__/fixtures/fakeSection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = function makeFakeSection() {

return {
exercises: [],
title: 'test section',
description: 'this is a test section',
sectionNumber: 1,
createdAt: Date,
modifiedAt: Date,
totalPoints: 100,
components: [],
parentCourse: '',
};
};
24 changes: 14 additions & 10 deletions __tests__/fixtures/fakeUser.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
const { encrypt } = require('../../helpers/password');
const mongoose = require('mongoose');

module.exports = function makeFakeUser() {

return {
email: 'fake@gmail.com',
password: encrypt('ABC123456!'),
googleID: '1234567891011',
joinedAt: new Date(),
modifiedAt: new Date()
};
};
module.exports = function makeFakeUser(email = 'fake@gmail.com', attempts = []) {
return {
email: email,
password: encrypt('ABC123456!'),
googleID: '1234567891011',
joinedAt: new Date(),
modifiedAt: new Date(),
firstName: 'Fake first name',
lastName: 'Fake last name',
resetAttempts: attempts,
subscriptions: []
}
}
78 changes: 78 additions & 0 deletions __tests__/helpers/email.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const exp = require('constants');
const emailHelper = require('../../helpers/email');
const nodemailer = require('nodemailer');

jest.mock('nodemailer', () => {
return {
createTransport: jest.fn(() => {
return {
sendMail: jest.fn(),
};
}),
};
});

jest.mock('../../config/keys', () => {
return {
GMAIL_USER: 'educadotest4@gmail.com',
GMAIL_APP_PASSWORD: 'test',
};
});

describe('sendResetPasswordEmail', () => {

it('should return email if email is sent', async () => {
const user = {
firstName: 'John',
email: 'test@email.com',
}
const token = '1234';

const expectedMailOptions = {
subject: 'Reset password request for Educado',
from: 'educadotest4@gmail.com',
to: user.email,
text: `Hi ${user.firstName},\n\nYou have requested to reset your password. Please enter the following code in the app to reset your password:\n\n${token}` +
`\n\nThis code will expire in 5 minutes.\n\nIf you did not request to reset your password, please ignore this email. Your password will remain unchanged.` +
`\n\nBest regards,\nThe Educado team`,
html: `<p>Hi ${user.firstName},</p>\n` +
`<p>You have requested to reset your password. Please enter the following code in the app to reset your password:</p>\n` +
`<p><strong>${token}</strong></p>\n` +
`<p>This code will expire in 5 minutes.</p>\n` +
`<p>If you did not request this, please ignore this email and your password will remain unchanged.</p>\n` +
`<p>Best regards,</p>\n` +
`<p>The Educado team</p>`
};

const result = await emailHelper.sendResetPasswordEmail(user, token);
expect(result).toMatchObject(expectedMailOptions);
});
});

describe('sendMail', () => {

it('should return email if email is sent', async () => {
const mailOptions = {
subject: 'Test email',
from: 'educadotest4@gmail.com',
to: 'test@user.com',
text: 'This is a test email',
html: '<p>This is a test email</p>'
};

const result = await emailHelper.sendMail(mailOptions);
expect(result).toMatchObject(mailOptions);
});

it('should throw error if email is invalid', async () => {
const mailOptions = {
subject: 'Test email',
from: 'invalid',
to: '',
text: 'This is a test email',
html: '<p>This is a test email</p>'
};

await expect(emailHelper.sendMail(mailOptions)).rejects.toThrow('Invalid email');
});
});
67 changes: 67 additions & 0 deletions __tests__/middleware/adminOnly.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const request = require('supertest');
const express = require('express');
const router = require('../../routes/testRoutes'); // Import your router file here
const connectDb = require('../fixtures/db');
const { signAccessToken } = require('../../helpers/token');
const mongoose = require('mongoose');

const app = express();
app.use(express.json());
app.use('/api/test', router); // Mount the router under '/api' path

// Start the Express app on a specific port for testing
const PORT = 5022; // Choose a port for testing
const server = app.listen(PORT);

// Mocked token secret
const TOKEN_SECRET = 'test';

// Mock token secret
jest.mock('../../config/keys', () => {
return {
TOKEN_SECRET
};
});

describe('Admin token verify', () => {
let db;

beforeAll(done => {
done();
db = connectDb(); // Connect to the database
});

it('Return an error if no valid admin token is present on private route', async () => {
const token = 'ImAnInvalidToken';
const response = await request(`http://localhost:${PORT}`)
.get('/api/test/adminOnly')
.set('token', token)

console.log(response.body.error)

expect(response.body.error).toBeDefined();
});

it('Return success if an admin token is valid on a private route', async () => {
const token = signAccessToken({ id: 'srdfet784y2uioejqr' });

// mock that token is valid
const response = await request(`http://localhost:${PORT}`)
.get('/api/test/adminOnly')
.set('token', token)
.expect(200);
});

it('Test for non-algorithm attack', async () => {
const token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.' + btoa(`{"id":1,"iat":${'' + Date.now()},"exp":999999999999}`) + '.';
const response = await request(`http://localhost:${PORT}`)
.get('/api/test/adminOnly')
.set('token', token)
.expect(401);
});

afterAll(async () => {
server.close();
await mongoose.connection.close();
});
});
6 changes: 2 additions & 4 deletions __tests__/middleware/requireLogin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ app.use('/api/test', router); // Mount the router under '/api' path

// Start the Express app on a specific port for testing
const PORT = 5022; // Choose a port for testing
const server = app.listen(PORT, () => {
console.log(`Express server is running on port ${PORT}`);
});
const server = app.listen(PORT);

// Mocked token secret
const TOKEN_SECRET = 'test';
Expand Down Expand Up @@ -62,7 +60,7 @@ describe('JWT verify', () => {
});

afterAll(async () => {
server.close();
await server.close();
await mongoose.connection.close();
});
});
Loading
Loading