Skip to content

Commit 5f2b16f

Browse files
committed
Quick save before switching branches
1 parent 77f8080 commit 5f2b16f

File tree

8 files changed

+32511
-20
lines changed

8 files changed

+32511
-20
lines changed

__tests__2022/charts/LatencyChart.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ describe('Latency Chart', () => {
3434

3535
it('Should render graph', () => {
3636
expect(screen.getByTestId('Latency Chart')).toBeTruthy();
37-
expect(screen).toMatchSnapshot();
37+
});
38+
39+
it('Should display data', () => {
40+
expect(screen.getByTestId('Latency Chart').firstChild).toBeTruthy();
3841
});
3942
});

__tests__2022/charts/SpeedChart.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jest.mock('electron', () => ({
1212
},
1313
}));
1414

15-
1615
describe('Speed Chart', () => {
1716
const props = {
1817
healthData: mockData,
@@ -37,6 +36,10 @@ describe('Speed Chart', () => {
3736
expect(screen.getByTestId('Speed Chart').firstChild).toBeTruthy();
3837
});
3938

39+
it('Should render graph', () => {
40+
expect(screen.getByTestId('Speed Chart').firstChild).toBeTruthy();
41+
});
42+
4043
/**
4144
* expect 'Speed Chart' to be on screen
4245
*/

app/charts/LatencyChart.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ const LatencyChart: React.FC<GraphsContainerProps> = React.memo(({ sizing, colou
112112
);
113113
};
114114

115-
return <div className="chart">{solo && createChart()}</div>;
115+
return (
116+
<div className="chart" data-testid="Latency Chart">
117+
{createChart()}
118+
</div>
119+
);
116120
});
117121

118122
export default LatencyChart;

electron/routes/user.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
/* eslint-disable no-use-before-define */
12
import { ipcMain, IpcMainEvent } from 'electron';
23
import path from 'path';
34
import fs from 'fs';
4-
/**
5-
* @event addApp
6-
* @desc Adds an application to the user's list in the settings.json with the provided fields
7-
* @return New list of applications
8-
*/
9-
// Loads existing settings JSON and update settings to include new services entered by the user on 'submit' request
5+
6+
const bcrypt = require('bcrypt');
7+
8+
const saltRounds = 12;
9+
1010
let settingsLocation;
1111
let usersLocation;
12-
1312
if (process.env.NODE_ENV === 'development') {
1413
settingsLocation = path.resolve(__dirname, '../../__tests__2022/test_settings.json');
1514
usersLocation = path.resolve(__dirname, '../../__tests__2022/test_users.json');
@@ -44,13 +43,18 @@ ipcMain.on(
4443
awaitingApproval: boolean;
4544
};
4645
} = {};
47-
firstUser[email] = { email, username, password, admin: true, awaitingApproval: false };
46+
const salt = bcrypt.genSaltSync(saltRounds);
47+
const hash = bcrypt.hashSync(password, salt);
48+
firstUser[email] = {
49+
email,
50+
username,
51+
password: hash,
52+
admin: true,
53+
awaitingApproval: false,
54+
};
4855
fs.writeFileSync(usersLocation, JSON.stringify(firstUser));
4956
message.returnValue = firstUser;
50-
} else {
51-
// eslint-disable-next-line no-use-before-define
52-
message.returnValue = ensureEmailIsUnique();
53-
}
57+
} else message.returnValue = ensureEmailIsUnique();
5458

5559
function ensureEmailIsUnique() {
5660
const users = JSON.parse(fs.readFileSync(usersLocation).toString('utf8'));
@@ -72,7 +76,8 @@ ipcMain.on('verifyUser', (message: IpcMainEvent, user: { email: string; password
7276
admin: boolean;
7377
awaitingApproval: boolean;
7478
} = users[email];
75-
if (email in users && currUser.password === password)
79+
const checkPassword = bcrypt.compareSync(password, users[email]?.password);
80+
if (email in users && checkPassword)
7681
message.returnValue = currUser.awaitingApproval ? 'awaitingApproval' : currUser;
7782
else message.returnValue = false;
7883
});

0 commit comments

Comments
 (0)