Skip to content

Commit 859acde

Browse files
committed
merged server integration
2 parents 23d81ad + 2563da1 commit 859acde

20 files changed

+774
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Download for [MacOS](https://github.com/team-reactype/ReacType/releases), [Windo
2929

3030
- **Linux users**: run the application as a super user in order to read and write files.
3131

32-
![Gif of adding](https://i.imgur.com/hdVTFcP.gif)
32+
![Gif of adding](https://i.imgur.com/nOeuuU6.gif)
3333

3434
### How to use
3535

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Enzyme testing suite renders snapshots, too 1`] = `
4+
<div>
5+
<h1>
6+
Hello, Enzyme!
7+
</h1>
8+
</div>
9+
`;

__tests__/enzyme.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { shallow } from 'enzyme';
2+
import React from 'react';
3+
4+
describe('Enzyme testing suite', () => {
5+
6+
it('renders snapshots, too', () => {
7+
const wrapper = shallow(<div>
8+
<h1>Hello, Enzyme!</h1>
9+
</div>)
10+
expect(wrapper).toMatchSnapshot()
11+
})
12+
})

app/electron/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,12 @@ ipcMain.on('set_cookie', event => {
353353
ipcMain.on('delete_cookie', event => {
354354
session.defaultSession.cookies
355355
.remove(serverUrl, 'ssid')
356+
<<<<<<< HEAD
356357
// .then(removed => {
357358
// console.log('Cookies deleted', removed);
358359
// })
360+
=======
361+
>>>>>>> serverreIntegration
359362
.catch(err => console.log('Error deleting cookie:', err));
360363
});
361364

app/setupTests.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { configure } from 'enzyme'
2+
import Adapter from 'enzyme-adapter-react-16'
3+
4+
configure({
5+
adapter: new Adapter(),
6+
})

app/src/setupTests.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

package.json

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"scripts": {
2828
"postinstall": "ELECTRON_BUILDER_ALLOW_UNRESOLVED_DEPENDENCIES=true electron-builder install-app-deps",
2929
"dev-server": "cross-env NODE_ENV=development webpack-dev-server --config ./webpack.development.js",
30-
"dev": "concurrently --success first \"npm run dev-server\" \"cross-env NODE_ENV=development electron .\" -k",
30+
"dev": "concurrently --success first \"npm run dev-server\" \"cross-env NODE_ENV=development electron .\" \"npm run server\" -k",
3131
"prod-build": "cross-env NODE_ENV=production npx webpack --mode=production --config ./webpack.production.js",
3232
"prod": "npm run prod-build && electron .",
3333
"pack": "electron-builder --dir",
@@ -36,7 +36,8 @@
3636
"dist-linux": "npm run prod-build && electron-builder --linux",
3737
"dist-windows": "npm run prod-build && electron-builder --windows",
3838
"dist-all": "npm run prod-build && electron-builder --mac --linux --windows",
39-
"test": "cross-env NODE_ENV=test jest --verbose"
39+
"test": "cross-env NODE_ENV=test jest --verbose",
40+
"server": "nodemon server/server.js"
4041
},
4142
"repository": {
4243
"type": "git",
@@ -72,7 +73,12 @@
7273
"diagnostics": false
7374
}
7475
},
75-
"testTimeout": 50000
76+
"setupFilesAfterEnv": [
77+
"<rootDir>/app/setupTests.ts"
78+
],
79+
"snapshotSerializers": [
80+
"enzyme-to-json/serializer"
81+
]
7682
},
7783
"bugs": {
7884
"url": "https://github.com/open-source-labs/ReacType/issues"
@@ -84,8 +90,6 @@
8490
"@material-ui/core": "^4.11.0",
8591
"@material-ui/icons": "^4.0.1",
8692
"@material-ui/styles": "^4.9.6",
87-
"@types/enzyme": "^3.10.5",
88-
"@types/enzyme-adapter-react-16": "^1.0.6",
8993
"@types/js-cookie": "^2.2.6",
9094
"@types/node": "^14.0.20",
9195
"@types/prettier": "^1.19.0",
@@ -97,8 +101,11 @@
97101
"app-root-path": "^3.0.0",
98102
"autoprefixer": "^9.0.1",
99103
"babel-polyfill": "^6.26.0",
104+
"bcryptjs": "^2.4.3",
100105
"concurrently": "^5.1.0",
101106
"connected-react-router": "^6.8.0",
107+
"cookie-parser": "^1.4.5",
108+
"cors": "^2.8.5",
102109
"electron-debug": "^3.1.0",
103110
"electron-devtools-installer": "^2.2.4",
104111
"electron-splashscreen": "^1.0.0",
@@ -107,6 +114,8 @@
107114
"immutable": "^4.0.0-rc.12",
108115
"js-cookie": "^2.2.1",
109116
"localforage": "^1.7.2",
117+
"passport": "^0.4.1",
118+
"passport-github2": "^0.1.12",
110119
"prettier": "^1.19.1",
111120
"prop-types": "^15.6.2",
112121
"react": "^16.13.0",
@@ -125,6 +134,8 @@
125134
"@babel/preset-react": "^7.10.4",
126135
"@babel/preset-typescript": "^7.10.4",
127136
"@types/chai": "^4.2.11",
137+
"@types/enzyme": "^3.10.5",
138+
"@types/enzyme-adapter-react-16": "^1.0.6",
128139
"@types/jest": "^25.1.5",
129140
"babel-eslint": "^8.2.6",
130141
"babel-jest": "^25.2.4",
@@ -137,6 +148,7 @@
137148
"dotenv": "^8.2.0",
138149
"electron": "^9.1.0",
139150
"electron-builder": "^22.7.0",
151+
"enzyme-to-json": "^3.5.0",
140152
"eslint": "^4.19.1",
141153
"eslint-config-airbnb-base": "^13.0.0",
142154
"eslint-plugin-babel": "^5.3.1",
@@ -146,7 +158,7 @@
146158
"eslint-plugin-react": "^7.20.3",
147159
"html-loader": "^1.1.0",
148160
"html-webpack-plugin": "^3.1.0",
149-
"jest": "^25.2.6",
161+
"jest": "^25.5.4",
150162
"mini-css-extract-plugin": "^0.9.0",
151163
"mongodb": "^3.5.9",
152164
"mongoose": "^5.9.22",
@@ -156,6 +168,7 @@
156168
"sass-loader": "^7.0.3",
157169
"spectron": "^11.1.0",
158170
"style-loader": "^0.20.3",
171+
"supertest": "^4.0.2",
159172
"ts-jest": "^25.3.0",
160173
"ts-node": "^8.10.2",
161174
"typescript": "^3.9.6",

server/Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: npm run start

server/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<p align="center">
2+
<img width="300" src="reactypeserverlogo.png">
3+
<h1 align="center">ReacType Server</h1>
4+
</p>
5+
6+
**ReacType Server** is the backend complement to the visual React prototyping tool **ReacType**. It is built in **Node.js** with the **Express** framework linked to **MongoDB** to handle user authentication (personal accounts on our own database as well as through Github Oauth), sessions, and user project management. The server itself is officially deployed through Heroku, but you can host your own local environment to communicate with the database with this repo.
7+
8+
If `npm` is your package manager, you just need to run the script `npm run dev` and it will start the server on `http://localhost:5000` for your development environment.
9+
10+
Endpoint testing is currently integrated with Jest and Supertest as well and can be run by `npm run test` or `npm run test:watch` for watch mode.

server/__tests__/projects.test.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const request = require('supertest');
2+
let server = 'https://reactype.herokuapp.com';
3+
const isDev = process.env.NODE_ENV === 'development';
4+
if (isDev) {
5+
server = 'http://localhost:5000';
6+
}
7+
8+
// save and get projects endpoint testing
9+
describe('Project endpoints tests', () => {
10+
// initializes the project to be sent to server/DB
11+
const state = {
12+
name: 'test',
13+
isLoggedIn: false,
14+
components: [
15+
{
16+
id: 1,
17+
name: 'index',
18+
style: {},
19+
code: '<div>Drag in a component or HTML element into the canvas!</div>',
20+
children: [],
21+
},
22+
],
23+
projectType: 'Next.js',
24+
rootComponents: [1],
25+
canvasFocus: { componentId: 1, childId: null },
26+
nextComponentId: 2,
27+
nextChildId: 1,
28+
};
29+
const projectToSave = {
30+
name: 'test',
31+
project: state,
32+
userId: '5f0df0636678ba002ba43b88',
33+
};
34+
35+
// test saveProject endpoint
36+
describe('/saveProject', () => {
37+
describe('/POST', () => {
38+
it('responds with a status of 200 and json object equal to project sent', () => {
39+
return request(server)
40+
.post('/saveProject')
41+
.send(projectToSave)
42+
.expect('Content-Type', /json/)
43+
.expect(200)
44+
.then((res) => expect(res.body.project.name).toBe('test'));
45+
});
46+
});
47+
});
48+
49+
// test getProjects endpoint
50+
describe('/getProjects', () => {
51+
describe('POST', () => {
52+
it('responds with status of 200 and json object equal to an array of user projects', () => {
53+
return request(server)
54+
.post('/getProjects')
55+
.send({ userId: projectToSave.userId })
56+
.expect(200)
57+
.expect('Content-Type', /json/)
58+
.then((res) => {
59+
expect(Array.isArray(res.body)).toBeTruthy;
60+
expect(res.body[0].name).toBe('test');
61+
});
62+
});
63+
});
64+
});
65+
66+
// test deleteProject endpoint
67+
describe('/deleteProject', () => {
68+
describe('DELETE', () => {
69+
const { name, userId } = projectToSave;
70+
it('responds with status of 200 and json object equal to deleted project', () => {
71+
return request(server)
72+
.delete('/deleteProject')
73+
.send({ name, userId })
74+
.expect(200)
75+
.expect('Content-Type', /json/)
76+
.then((res) => expect(res.body.name).toBe('test'));
77+
});
78+
});
79+
});
80+
});

server/__tests__/users.test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const request = require('supertest');
2+
let server = 'https://reactype.herokuapp.com';
3+
const isDev = process.env.NODE_ENV === 'development';
4+
if (isDev) {
5+
server = 'http://localhost:5000';
6+
}
7+
8+
// tests user signup and login routes
9+
describe('User authentication tests', () => {
10+
let num = Math.floor(Math.random() * 1000);
11+
12+
describe('/signup', () => {
13+
describe('POST', () => {
14+
it('responds with status 200 and json object on valid new user signup', () => {
15+
return request(server)
16+
.post('/signup')
17+
.send({
18+
username: `supertest${num}`,
19+
email: `test${num}@test.com`,
20+
password: `${num}`,
21+
})
22+
.expect('Content-Type', /json/)
23+
.expect(200)
24+
.then((res) => expect(typeof res.body).toBe('object'));
25+
});
26+
it('responds with status 400 and json string on invalid new user signup', () => {
27+
return request(server)
28+
.post('/signup')
29+
.send({
30+
username: 'reactyp3test',
31+
32+
password: 'password',
33+
})
34+
.expect('Content-Type', /json/)
35+
.expect(400)
36+
.then((res) => expect(typeof res.body).toBe('string'));
37+
});
38+
});
39+
});
40+
describe('/login', () => {
41+
describe('POST', () => {
42+
it('responds with status 200 and json object on verified user login', () => {
43+
return request(server)
44+
.post('/login')
45+
.send({ username: 'reactyp3test', password: 'codesmith1!' })
46+
.expect(200)
47+
.expect('Content-Type', /json/)
48+
.then((res) =>
49+
expect(res.body.sessionId).toEqual('5f0df0636678ba002ba43b88')
50+
);
51+
});
52+
it('responds with status 400 and json string on invalid user login', () => {
53+
return request(server)
54+
.post('/login')
55+
.send({ username: 'wrongusername', password: 'wrongpassword' })
56+
.expect(400)
57+
.expect('Content-Type', /json/)
58+
.then((res) => expect(typeof res.body).toBe('string'));
59+
});
60+
});
61+
});
62+
});
63+
64+
describe('User Login Tests', () => {});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const cookieController = {};
2+
3+
// setSSIDCookie - store the user id from database in cookie
4+
cookieController.setSSIDCookie = (req, res, next) => {
5+
// set cookie with key 'ssid' and value to user's id
6+
res.cookie('ssid', res.locals.id);
7+
return next();
8+
};
9+
10+
module.exports = cookieController;

0 commit comments

Comments
 (0)