Skip to content

Commit

Permalink
Merge pull request #211 from Nefariusek/develop
Browse files Browse the repository at this point in the history
Release version 2.0
  • Loading branch information
Nefariusek authored Mar 27, 2022
2 parents 74b6892 + 62efa52 commit f4d57a2
Show file tree
Hide file tree
Showing 119 changed files with 3,560 additions and 399 deletions.
835 changes: 740 additions & 95 deletions backend/package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testTimeout=10000"
},
"dependencies": {
"bcrypt": "^5.0.1",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
Expand All @@ -17,7 +18,9 @@
"helmet": "^4.6.0",
"http-status-codes": "^2.1.4",
"joi": "^17.4.2",
"mongoose": "^6.0.6"
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.0.6",
"mongoose-unique-validator": "^3.0.0"
},
"devDependencies": {
"cross-env": "^7.0.3",
Expand Down
1 change: 1 addition & 0 deletions backend/resource/bandage-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions backend/resource/eye-dropper-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions backend/resource/flask-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions backend/resource/joint-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions backend/resource/lungs-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions backend/resource/pills-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions backend/resource/syringe-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions backend/src/__test__/models/Medication.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Medication, { medicationValidator } from '../../models/Medication';

describe('Medication model test', () => {
const date = new Date().getDay();

it('Medication with no given addDate has todays date', () => {
const med = new Medication();
const addDate = med.addDate.getDay();
expect(addDate).toBe(date);
});
});

describe('Joi validator for medication model', () => {
let testRequestBody;
let res;
let err;
beforeEach(() => {
err = undefined;
testRequestBody = {
body: {
nameOfMedication: undefined,
quantity: undefined,
addDate: undefined,
dosage: undefined,
expirationDate: undefined,
},
};
});

it('Joi validator accepts allowed data', () => {
testRequestBody.body.nameOfMedication = 'xanax';
testRequestBody.body.quantity = 2;
testRequestBody.body.addDate = new Date();
testRequestBody.body.dosage = 'daily';
testRequestBody.body.expirationDate = new Date();

medicationValidator(testRequestBody, res, (e) => {
err = e;
});
expect(err).toBeUndefined();
});

it('Joi validator rejects wrong values', () => {
testRequestBody.body.nameOfMedication = 'xa';
testRequestBody.body.quantity = 0;
testRequestBody.body.addDate = 332;
testRequestBody.body.dosage = '3';
testRequestBody.body.expirationDate = '01.02.2022';

medicationValidator(testRequestBody, res, (e) => {
err = e;
});
expect(err).not.toBeUndefined();
});
});
73 changes: 73 additions & 0 deletions backend/src/__test__/models/MedicationCategory.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import MedicationCategory, { medicationCategoryValidator } from '../../models/MedicationCategory';
import { PILLS_COLOR, SYRUP_COLOR } from '../../constants/MedicationCategory/pillColors';
import { QUANTITY_UNIT, VOLUME_UNIT } from '../../constants/MedicationCategory/medsUnits';
import { PILLS_ICON, SYRUP_ICON } from '../../constants/MedicationCategory/medsIcons';
import { PILL_MED_TYPE, SYRUP_MED_TYPE } from '../../constants/MedicationCategory/medTypes';
let testMedicationCategory;
let testRequestBody;
let res;
let err;

describe('MedicationCategory model', () => {
beforeEach(() => {
testMedicationCategory = new MedicationCategory();
});

it('new medication category has default values', () => {
expect(testMedicationCategory.name).toBe(PILL_MED_TYPE);
expect(testMedicationCategory.unit).toBe(QUANTITY_UNIT);
expect(testMedicationCategory.color).toBe('blue');
expect(testMedicationCategory.icon).toBe(PILLS_ICON);
});

it('settings model accepts allowed values', () => {
testMedicationCategory.name = SYRUP_MED_TYPE;
testMedicationCategory.unit = VOLUME_UNIT;
testMedicationCategory.color = SYRUP_COLOR;
testMedicationCategory.icon = SYRUP_ICON;

expect(testMedicationCategory.name).toBe(SYRUP_MED_TYPE);
expect(testMedicationCategory.unit).toBe(VOLUME_UNIT);
expect(testMedicationCategory.color).toBe(SYRUP_COLOR);
expect(testMedicationCategory.icon).toBe(SYRUP_ICON);
});
});

describe('Joi validator for medication category model', () => {
beforeEach(() => {
err = undefined;
testRequestBody = {
body: {
name: undefined,
unit: undefined,
color: undefined,
icon: undefined,
},
};
});

it('Joi validator accepts allowed data', () => {
testRequestBody.body.name = SYRUP_MED_TYPE;
testRequestBody.body.unit = VOLUME_UNIT;
testRequestBody.body.color = SYRUP_COLOR;
testRequestBody.body.icon = SYRUP_ICON;

medicationCategoryValidator(testRequestBody, res, (e) => {
err = e;
});
expect(err).toBeUndefined();
});

it('Joi validator rejects wrong values', () => {
let res;
testRequestBody.body.name = 'Xa';
testRequestBody.body.unit = 'cm3';
testRequestBody.body.color = 'salmon';
testRequestBody.body.icon = 'not a valid icon';

medicationCategoryValidator(testRequestBody, res, (e) => {
err = e;
});
expect(err).not.toBeUndefined();
});
});
60 changes: 60 additions & 0 deletions backend/src/__test__/models/Profile.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import Profile, { profileValidator } from '../../models/Profile';

let testRequestBody;
let res;
let err;
const date = new Date().getDay();
const testString = 'abc'.repeat(61);
const testDate = new Date().getDay() + 1;

describe('Profile model test', () => {
it('new profile has default last online value', () => {
const profile = new Profile();
const addDate = profile.onlineDate.getDay();
expect(addDate).toBe(date);
});
});

describe('Joi validator for profile model', () => {
beforeEach(() => {
err = undefined;
testRequestBody = {
body: {
age: undefined,
firstName: undefined,
lastName: undefined,
userBio: undefined,
registerDate: undefined,
onlineDate: undefined,
},
};
});

it('Joi validator accepts allowed data', () => {
testRequestBody.body.age = 5;
testRequestBody.body.firstName = 'abcd';
testRequestBody.body.lastName = 'abcd';
testRequestBody.body.userBio = 'abcd';
testRequestBody.body.registerDate = date;
testRequestBody.body.onlineDate = date;

profileValidator(testRequestBody, res, (e) => {
err = e;
});
expect(err).toBeUndefined();
});

it('Joi validator rejects wrong values', () => {
testRequestBody.body.age = 5.5;
testRequestBody.body.firstName = 'ABCD';
testRequestBody.body.lastName = 'ABCD';
testRequestBody.body.userBio = testString;
testRequestBody.body.registerDate = testDate;
testRequestBody.body.onlineDate = testDate;

profileValidator(testRequestBody, res, (e) => {
err = e;
});
expect(err).not.toBeUndefined();
});
});
66 changes: 66 additions & 0 deletions backend/src/__test__/models/Settings.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import Settings, { settingsValidator } from '../../models/Settings';
import { LIGHT_THEME, DARK_THEME } from '../../constants/themes';

let testSettings;
let testRequestBody;
let res;
let err;

describe('Settings model', () => {
beforeEach(() => {
testSettings = new Settings();
});

it('new settings has default values', () => {
expect(testSettings.appTheme).toBe(LIGHT_THEME);
expect(testSettings.soonExpiringFilterLength).toBe(3);
expect(testSettings.validateSync()).toBeUndefined();
});

it('settings model doesnt allow wrong values', () => {
testSettings.appTheme = 'wrongAppTheme';
testSettings.soonExpiringFilterLength = 11;

expect(testSettings.validateSync).toThrow();
});

it('settings model accepts allowed values', () => {
testSettings.appTheme = DARK_THEME;
testSettings.soonExpiringFilterLength = 5;

expect(testSettings.appTheme).toBe(DARK_THEME);
expect(testSettings.soonExpiringFilterLength).toBe(5);
expect(testSettings.validateSync()).toBeUndefined();
});
});

describe('Joi validator for settings model', () => {
beforeEach(() => {
err = undefined;
testRequestBody = {
body: {
appTheme: undefined,
soonExpiringFilterLength: undefined,
},
};
});

it('Joi validator accepts allowed data', () => {
testRequestBody.body.appTheme = DARK_THEME;
testRequestBody.body.soonExpiringFilterLength = 7;
settingsValidator(testRequestBody, res, (e) => {
err = e;
});
expect(err).toBeUndefined();
});

it('Joi validator doesnt allow wrong values', () => {
let res;
testRequestBody.body.appTheme = 'wrongAppTheme';
testRequestBody.body.soonExpiringFilterLength = 4;
settingsValidator(testRequestBody, res, (e) => {
err = e;
});
expect(err).not.toBeUndefined();
});
});
Loading

0 comments on commit f4d57a2

Please sign in to comment.