Skip to content

Commit 11e10d2

Browse files
committed
merge dev changes
2 parents 0ac9d4c + f094bff commit 11e10d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2255
-866
lines changed

__tests__/server.test.tsx

Lines changed: 133 additions & 122 deletions
Large diffs are not rendered by default.

__tests__/userAuth.test.ts

Lines changed: 70 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,35 @@
22
* @jest-environment node
33
*/
44

5-
6-
import marketplaceController from '../server/controllers/marketplaceController';
75
import app from '../server/server';
86
import mockData from '../mockData';
9-
import { profileEnd } from 'console';
107
import { Sessions, Users } from '../server/models/reactypeModels';
118
const request = require('supertest');
129
const mongoose = require('mongoose');
1310
const mockNext = jest.fn(); // Mock nextFunction
14-
const MONGO_DB = process.env.MONGO_DB_TEST;
15-
const { state, projectToSave, user } = mockData
11+
const MONGO_DB = import.meta.env.MONGO_DB_TEST;
12+
const { user } = mockData;
1613
const PORT = 8080;
1714

1815
const num = Math.floor(Math.random() * 1000);
1916

2017
beforeAll(async () => {
2118
await mongoose.connect(MONGO_DB, {
2219
useNewUrlParser: true,
23-
useUnifiedTopology: true,
20+
useUnifiedTopology: true
2421
});
2522
});
2623

2724
afterAll(async () => {
28-
29-
const result = await Users.deleteMany({_id: {$ne: '64f551e5b28d5292975e08c8'}});//clear the users collection after tests are done except for the mockdata user account
30-
const result2 = await Sessions.deleteMany({cookieId: {$ne: '64f551e5b28d5292975e08c8'}});
31-
console.log(`${result.deletedCount} and ${result2.deletedCount} documents deleted.`);
25+
const result = await Users.deleteMany({
26+
_id: { $ne: '64f551e5b28d5292975e08c8' }
27+
}); //clear the users collection after tests are done except for the mockdata user account
28+
const result2 = await Sessions.deleteMany({
29+
cookieId: { $ne: '64f551e5b28d5292975e08c8' }
30+
});
31+
console.log(
32+
`${result.deletedCount} and ${result2.deletedCount} documents deleted.`
33+
);
3234
await mongoose.connection.close();
3335
});
3436

@@ -40,7 +42,7 @@ describe('User Authentication tests', () => {
4042
expect(response.text).toBe('test request is working');
4143
});
4244
});
43-
describe('/signup', ()=> {
45+
describe('/signup', () => {
4446
describe('POST', () => {
4547
//testing new signup
4648
it('responds with status 200 and sessionId on valid new user signup', () => {
@@ -55,7 +57,7 @@ describe('User Authentication tests', () => {
5557
.expect(200)
5658
.then((res) => expect(res.body.sessionId).not.toBeNull());
5759
});
58-
60+
5961
it('responds with status 400 and json string on invalid new user signup (Already taken)', () => {
6062
return request(app)
6163
.post('/signup')
@@ -67,8 +69,9 @@ describe('User Authentication tests', () => {
6769
});
6870
});
6971
});
72+
7073
describe('/login', () => {
71-
// tests whether existing login information permits user to log in
74+
// tests whether existing login information permits user to log in
7275
describe('POST', () => {
7376
it('responds with status 200 and json object on verified user login', () => {
7477
return request(app)
@@ -80,183 +83,68 @@ describe('User Authentication tests', () => {
8083
.then((res) => expect(res.body.sessionId).toEqual(user.userId));
8184
});
8285
// if invalid username/password, should respond with status 400
83-
it('responds with status 400 and json string on invalid user login', () => {
86+
it('responds with status 400 and json string on invalid user login', () => {
8487
return request(app)
8588
.post('/login')
8689
.send({ username: 'wrongusername', password: 'wrongpassword' })
8790
.expect(400)
8891
.expect('Content-Type', /json/)
8992
.then((res) => expect(typeof res.body).toBe('string'));
9093
});
91-
});
92-
});
93-
94-
});
95-
96-
97-
98-
// import request from 'supertest';
99-
// import app from '../server/server';
100-
// import mockObj from '../mockData';
101-
// const user = mockObj.user;
102-
// import mongoose from 'mongoose';
103-
// const URI = process.env.MONGO_DB;
104-
105-
// beforeAll(() => {
106-
// mongoose
107-
// .connect(URI, { useNewUrlParser: true }, { useUnifiedTopology: true })
108-
// .then(() => console.log('connected to test database'));
109-
// });
110-
111-
// afterAll(async () => {
112-
// await mongoose.connection.close();
113-
// });
114-
// //for creating unqiue login credentials
115-
// const num = Math.floor(Math.random() * 1000);
116-
117-
// describe('User authentication tests', () => {
118-
// //test connection to server
119-
// describe('initial connection test', () => {
120-
// it('should connect to the server', async () => {
121-
// const response = await request(app).get('/test');
122-
// expect(response.text).toEqual('test request is working');
123-
// });
124-
// });
125-
126-
// xdescribe('POST', () => {
127-
// it('responds with status 200 and json object on valid new user signup', () => {
128-
// return request(app)
129-
// .post('/signup')
130-
// .set('Content-Type', 'application/json')
131-
// .send({
132-
// username: `supertest${num}`,
133-
// email: `test${num}@test.com`,
134-
// password: `${num}`
135-
// })
136-
// .expect(200)
137-
// .then((res) => expect(typeof res.body).toBe('object'));
138-
// });
139-
140-
// it('responds with status 400 and json string on invalid new user signup', () => {
141-
// return request(app)
142-
// .post('/signup')
143-
// .send(user)
144-
// .set('Accept', 'application/json')
145-
// .expect('Content-Type', /json/)
146-
// .expect(400)
147-
// .then((res) => expect(typeof res.body).toBe('string'));
148-
// });
149-
// });
150-
// });
151-
// describe('/login', () => {
152-
// // tests whether existing login information permits user to log in
153-
// xdescribe('POST', () => {
154-
// it('responds with status 200 and json object on verified user login', () => {
155-
// return request(app)
156-
// .post('/login')
157-
// .set('Accept', 'application/json')
158-
// .send(user)
159-
// .expect(200)
160-
// .expect('Content-Type', /json/)
161-
// .then((res) => expect(res.body.sessionId).toEqual(user.userId));
162-
// });
163-
// // if invalid username/password, should respond with status 400
164-
// it('responds with status 400 and json string on invalid user login', () => {
165-
// return request(app)
166-
// .post('/login')
167-
// .send({ username: 'wrongusername', password: 'wrongpassword' })
168-
// .expect(400)
169-
// .expect('Content-Type', /json/)
170-
// .then((res) => expect(typeof res.body).toBe('string'));
171-
// });
172-
// it('responds with status 400 and json string on invalid new user signup', () => {
173-
// return request(app)
174-
// .post('/signup')
175-
// .send(user)
176-
// .set('Accept', 'application/json')
177-
// .expect('Content-Type', /json/)
178-
// .expect(400)
179-
// .then((res) => expect(typeof res.body).toBe('string'));
180-
// });
181-
// });
182-
// });
183-
184-
// describe('sessionIsCreated', () => {
185-
// it("returns the message 'No Username Input' when no username is entered", () => {
186-
// return request(app)
187-
// .post('/login')
188-
// .send({
189-
// username: '',
190-
// password: 'Reactype123!@#',
191-
// isFbOauth: false
192-
// })
193-
// .then((res) => expect(res.text).toBe('"No Username Input"'));
194-
// });
195-
196-
// it("returns the message 'No Password Input' when no password is entered", () => {
197-
// return request(app)
198-
// .post('/login')
199-
// .send({
200-
// username: 'reactype123',
201-
// password: '',
202-
// isFbOauth: false
203-
// })
204-
// .then((res) => expect(res.text).toBe('"No Password Input"'));
205-
// });
94+
it("returns the message 'No Username Input' when no username is entered", () => {
95+
return request(app)
96+
.post('/login')
97+
.send({
98+
username: '',
99+
password: 'Reactype123!@#',
100+
isFbOauth: false
101+
})
102+
.then((res) => expect(res.text).toBe('"No Username Input"'));
103+
});
206104

207-
// it("returns the message 'Invalid Username' when username does not exist", () => {
208-
// return request(app)
209-
// .post('/login')
210-
// .send({
211-
// username: 'l!b',
212-
// password: 'test',
213-
// isFbOauth: false
214-
// })
215-
// .then((res) => expect(res.text).toBe('"Invalid Username"'));
216-
// });
217-
// });
105+
it("returns the message 'No Username Input' when no username is entered", () => {
106+
return request(app)
107+
.post('/login')
108+
.send({
109+
username: '',
110+
password: 'Reactype123!@#',
111+
isFbOauth: false
112+
})
113+
.then((res) => expect(res.text).toBe('"No Username Input"'));
114+
});
218115

219-
// it("returns the message 'Incorrect Password' when password does not match", () => {
220-
// return request(app)
221-
// .post('/login')
222-
// .send({
223-
// username: 'test',
224-
// password: 'test',
225-
// isFbOauth: false
226-
// })
227-
// .then((res) => expect(res.text).toBe('"Incorrect Password"'));
228-
// });
229-
// // note that the username and password in this test are kept in the heroku database
230-
// // DO NOT CHANGE unless you have access to the heroku database
231-
// it("returns the message 'Success' when the user passes all auth checks", () => {
232-
// return request(app)
233-
// .post('/login')
234-
// .send({
235-
// username: 'test',
236-
// password: 'password1!',
237-
// isFbOauth: false
238-
// })
239-
// .then((res) => expect(res.body).toHaveProperty('sessionId'));
240-
// });
116+
it("returns the message 'No Password Input' when no password is entered", () => {
117+
return request(app)
118+
.post('/login')
119+
.send({
120+
username: 'reactype123',
121+
password: '',
122+
isFbOauth: false
123+
})
124+
.then((res) => expect(res.text).toBe('"No Password Input"'));
125+
});
241126

242-
// // // OAuth tests (currently inoperative)
127+
it("returns the message 'Invalid Username' when username does not exist", () => {
128+
return request(app)
129+
.post('/login')
130+
.send({
131+
username: 'l!b',
132+
password: 'test',
133+
isFbOauth: false
134+
})
135+
.then((res) => expect(res.text).toBe('"Invalid Username"'));
136+
});
137+
});
243138

244-
// // xdescribe('Github oauth tests', () => {
245-
// // describe('/github/callback?code=', () => {
246-
// // describe('GET', () => {
247-
// // it('responds with status 400 and error message if no code received', () => {
248-
// // return request(server)
249-
// // .get('/github/callback?code=')
250-
// // .expect(400)
251-
// // .then((res) => {
252-
// // return expect(res.text).toEqual(
253-
// // '"Undefined or no code received from github.com"'
254-
// // );
255-
// // });
256-
// // });
257-
// // it('responds with status 400 if invalid code received', () => {
258-
// // return request(server).get('/github/callback?code=123456').expect(400);
259-
// // });
260-
// // });
261-
// // });
262-
// // });
139+
it("returns the message 'Incorrect Password' when password does not match", () => {
140+
return request(app)
141+
.post('/login')
142+
.send({
143+
username: 'test',
144+
password: 'test',
145+
isFbOauth: false
146+
})
147+
.then((res) => expect(res.text).toBe('"Incorrect Password"'));
148+
});
149+
});
150+
});

app/.electron/main.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import MenuBuilder from './menu';
3030

3131
// mode that the app is running in
3232
const isDev =
33-
process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
33+
import.meta.env.NODE_ENV === 'development' ||
34+
import.meta.env.NODE_ENV === 'test';
3435
const port = 8080;
3536
const selfHost = `http://localhost:${port}`;
3637

@@ -388,8 +389,8 @@ ipcMain.on('github', (event) => {
388389
? `http://localhost:${DEV_PORT}/auth/github`
389390
: `https://reactype-caret.herokuapp.com/auth/github`;
390391
const options = {
391-
client_id: process.env.GITHUB_ID,
392-
client_secret: process.env.GITHUB_SECRET,
392+
client_id: import.meta.env.GITHUB_ID,
393+
client_secret: import.meta.env.GITHUB_SECRET,
393394
scopes: ['user:email', 'notifications']
394395
};
395396
// create new browser window object with size, title, security options

app/.electron/menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var MenuBuilder = function (mainWindow, appName) {
4747
devTools: false
4848
}
4949
});
50-
if (process.env.NODE_ENV === 'development') {
50+
if (import.meta.env.NODE_ENV === 'development') {
5151
tutorial.loadURL(`http://localhost:8080/#/tutorial`);
5252
} else {
5353
tutorial.loadURL(`${Protocol.scheme}://rse/index-prod.html#/tutorial`);

0 commit comments

Comments
 (0)