Skip to content

Commit dd06c6f

Browse files
authored
Merge pull request #62 from lawrencehan650/main
add linting, clean up code base
2 parents 59eb908 + 871f9e2 commit dd06c6f

Some content is hidden

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

42 files changed

+2095
-16876
lines changed

__tests__/jest.js

+17-24
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,34 @@
1-
const userController = require('../server/controllers/userController')
2-
const { Pool } = require('pg');
3-
import { jest } from '@jest/globals';
1+
const userController = require("../server/controllers/userController");
2+
const { Pool } = require("pg");
3+
import { jest } from "@jest/globals";
44

5-
const myURI = 'postgres://calxwrwx:[email protected]/calxwrwx';
5+
const myURI =
6+
"postgres://calxwrwx:[email protected]/calxwrwx";
67

7-
8-
describe('db unit tests', () => {
8+
describe("db unit tests", () => {
99
// async callback to run before every all tests run
1010
beforeAll((done) => {
11-
console.log('connecting to db')
11+
console.log("connecting to db");
1212

1313
const pool = new Pool({
14-
connectionString: myURI
14+
connectionString: myURI,
1515
});
1616

1717
const db = {
1818
query: (text, params, callback) => {
19-
console.log('executed query', text);
19+
console.log("executed query", text);
2020
return pool.query(text, params, callback);
2121
},
22-
};
23-
console.log('connected to db')
22+
};
23+
console.log("connected to db");
2424
done();
25-
});
25+
});
2626
// async callback to run once all tests are completed regardless of pass/fail
2727
// afterAll((done) => {
28-
// testing github link
29-
28+
// testing github link
3029

3130
// })
32-
describe('add', () => {
33-
it('successfully adds a user', () => {
34-
35-
})
36-
})
37-
38-
39-
40-
41-
});
31+
describe("add", () => {
32+
it("successfully adds a user", () => {});
33+
});
34+
});

__tests__/supertest.js

+59-65
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,80 @@
1-
const app = require('../server/server.js');
2-
const request = require('supertest');
1+
const app = require("../server/server.js");
2+
const request = require("supertest");
33

4-
const server = 'http://localhost:8080';
4+
const server = "http://localhost:8080";
55

66
describe('GET "/"', () => {
7-
it('Serves the application', async () => {
7+
it("Serves the application", async () => {
88
await request(server)
9-
.get('/')
9+
.get("/")
1010
.expect(200)
11-
.expect('Content-Type', /text\/html/)
12-
})
13-
})
11+
.expect("Content-Type", /text\/html/);
12+
});
13+
});
1414

1515
describe('POST "/user/login" - login check', () => {
16-
it('Logs in with correct credentials', async () => {
16+
it("Logs in with correct credentials", async () => {
1717
const res = await request(server)
18-
.post('/user/login')
19-
.set('Content-Type', 'application/json')
20-
.send({email: '[email protected]', password: '123'})
21-
.expect(200)
22-
})
23-
it('Sends cookies after successful login', async () => {
18+
.post("/user/login")
19+
.set("Content-Type", "application/json")
20+
.send({ email: "[email protected]", password: "123" })
21+
.expect(200);
22+
});
23+
it("Sends cookies after successful login", async () => {
2424
const res = await request(server)
25-
.post('/user/login')
26-
.set('Content-Type', 'application/json')
27-
.send({email: '[email protected]', password: '123'})
28-
.expect(200)
29-
expect(res.headers['set-cookie'].length).not.toBe(0)
30-
})
31-
it('Returns an error with incorrect credentials', async () => {
25+
.post("/user/login")
26+
.set("Content-Type", "application/json")
27+
.send({ email: "[email protected]", password: "123" })
28+
.expect(200);
29+
expect(res.headers["set-cookie"].length).not.toBe(0);
30+
});
31+
it("Returns an error with incorrect credentials", async () => {
3232
const res = await request(server)
33-
.post('/user/login')
34-
.set('Content-Type', 'application/json')
35-
.send({email: '[email protected]', password: 'incorrect'})
36-
.expect(500)
37-
expect(res.body).toBe('Incorrect username/password')
38-
})
39-
})
33+
.post("/user/login")
34+
.set("Content-Type", "application/json")
35+
.send({ email: "[email protected]", password: "incorrect" })
36+
.expect(500);
37+
expect(res.body).toBe("Incorrect username/password");
38+
});
39+
});
4040

4141
describe('POST "/user/create" - creating user', () => {
4242
afterAll(async () => {
4343
await request(server)
44-
.delete('/user')
45-
.set('Content-type', 'application/json')
46-
.send({ email: '[email protected]'})
47-
})
44+
.delete("/user")
45+
.set("Content-type", "application/json")
46+
.send({ email: "[email protected]" });
47+
});
4848

49-
it('Adds a new user to the database', async () => {
49+
it("Adds a new user to the database", async () => {
5050
const res = await request(server)
51-
.post('/user/create')
52-
.set('Content-type', 'application/json')
51+
.post("/user/create")
52+
.set("Content-type", "application/json")
5353
.send({
54-
55-
password: '123',
56-
firstName: 'test',
57-
lastName: 'test',
58-
teamName: 'ohana',
59-
isAdmin: 'true',
54+
55+
password: "123",
56+
firstName: "test",
57+
lastName: "test",
58+
teamName: "ohana",
59+
isAdmin: "true",
6060
})
61-
.expect(200)
62-
expect(res.body).toBe('Successfully added new user')
63-
})
61+
.expect(200);
62+
expect(res.body).toBe("Successfully added new user");
63+
});
6464

65-
it('New user appears in the database', async () => {
66-
const res = await request(server)
67-
.get('/user')
68-
.expect(200)
69-
expect(res.body[res.body.length - 1].email).toBe('[email protected]')
70-
})
71-
})
65+
it("New user appears in the database", async () => {
66+
const res = await request(server).get("/user").expect(200);
67+
expect(res.body[res.body.length - 1].email).toBe("[email protected]");
68+
});
69+
});
7270

7371
describe('GET "/spaces" and "/vclusters"', () => {
74-
it('Receives a list of all the active namespaces', async () => {
75-
const res = await request(server)
76-
.get('/spaces/fetch')
77-
.expect(200)
78-
expect(Array.isArray(res.body)).toBe(true)
79-
})
80-
it('Receives a list of all the active vClusters', async () => {
81-
const res = await request(server)
82-
.get('/vclusters')
83-
.expect(200)
84-
expect(Array.isArray(res.body)).toBe(true)
85-
})
86-
})
72+
it("Receives a list of all the active namespaces", async () => {
73+
const res = await request(server).get("/spaces/fetch").expect(200);
74+
expect(Array.isArray(res.body)).toBe(true);
75+
});
76+
it("Receives a list of all the active vClusters", async () => {
77+
const res = await request(server).get("/vclusters").expect(200);
78+
expect(Array.isArray(res.body)).toBe(true);
79+
});
80+
});

client/components/App.jsx

+36-30
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,58 @@
1-
import React, { useState } from 'react';
2-
import MainContainer from '../containers/MainContainer.jsx';
3-
import { BrowserRouter as Router } from 'react-router-dom';
4-
import { AppContext } from './AppContext';
5-
import { makeStyles } from '@material-ui/core/styles';
6-
import ToggleTheme from '../themes/ToggleTheme.jsx';
1+
import React, { useState } from "react";
2+
import MainContainer from "../containers/MainContainer.jsx";
3+
import { BrowserRouter as Router } from "react-router-dom";
4+
import { AppContext } from "./AppContext";
5+
import { makeStyles } from "@material-ui/core/styles";
6+
import ToggleTheme from "../themes/ToggleTheme.jsx";
77

8-
const useStyles = makeStyles(theme => ({
8+
const useStyles = makeStyles((theme) => ({
99
footer: {
1010
padding: theme.spacing(2, 2),
11-
marginTop: 'auto',
11+
marginTop: "auto",
1212
backgroundColor: theme.palette.primary.main,
1313
},
1414
header: {
15-
paddingBottom: '2px'
16-
}
15+
paddingBottom: "2px",
16+
},
1717
}));
1818

19-
2019
const App = (props) => {
21-
2220
const [isLoggedIn, setIsLoggedIn] = useState(false);
2321
const [isAdmin, setIsAdmin] = useState(false);
24-
const [clusterNames, setClusterNames] = useState([])
25-
const [namespaceNames, setNamespaces] = useState([])
26-
const [teamId, setTeamId] = useState('');
27-
const [firstName, setFirstName] = useState('');
28-
const [lastName, setLastName] = useState('');
29-
const [vClusters, setvClusters] = useState('');
30-
const value = {
31-
isLoggedIn, setIsLoggedIn,
32-
isAdmin, setIsAdmin,
33-
clusterNames, setClusterNames,
34-
namespaceNames, setNamespaces,
35-
teamId, setTeamId,
36-
firstName, setFirstName,
37-
lastName, setLastName,
38-
vClusters, setvClusters
22+
const [clusterNames, setClusterNames] = useState([]);
23+
const [namespaceNames, setNamespaces] = useState([]);
24+
const [teamId, setTeamId] = useState("");
25+
const [firstName, setFirstName] = useState("");
26+
const [lastName, setLastName] = useState("");
27+
const [vClusters, setvClusters] = useState("");
28+
const value = {
29+
isLoggedIn,
30+
setIsLoggedIn,
31+
isAdmin,
32+
setIsAdmin,
33+
clusterNames,
34+
setClusterNames,
35+
namespaceNames,
36+
setNamespaces,
37+
teamId,
38+
setTeamId,
39+
firstName,
40+
setFirstName,
41+
lastName,
42+
setLastName,
43+
vClusters,
44+
setvClusters,
3945
};
4046
// if (isLoggedIn) navBar = <NavBar />;
4147

4248
const classes = useStyles();
4349

4450
return (
45-
<div className="App">
51+
<div className='App'>
4652
<Router>
4753
<AppContext.Provider value={value}>
48-
<MainContainer />
49-
<ToggleTheme />
54+
<MainContainer />
55+
<ToggleTheme />
5056
</AppContext.Provider>
5157
</Router>
5258
</div>

0 commit comments

Comments
 (0)