Skip to content

Commit 3bdd89e

Browse files
Merge pull request #47 from Virtual-R/stephen-tanksley
Stephen tanksley
2 parents d24b08e + 1e04a33 commit 3bdd89e

222 files changed

Lines changed: 54371 additions & 164 deletions

File tree

Some content is hidden

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

data/middleware/logger.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
module.exports = (type) => (req, res, next) => {
2-
let time = new Date();
3-
let utcTime = time.toUTCString();
2+
let time = new Date();
3+
let utcTime = time.toUTCString();
44

5-
if(type === 'long') {
6-
console.log(`
5+
if (type === "long") {
6+
console.log(`
77
${req.method}\n
88
${req.url}\n
99
${utcTime}\n
10-
${req.ip}`)
11-
next()
12-
13-
} else {
14-
console.log(req)
15-
return
16-
}
17-
}
10+
${req.ip}`);
11+
next();
12+
} else if (type === "short") {
13+
console.log(`
14+
${req.url}\n
15+
${utcTime}`);
16+
next();
17+
} else {
18+
console.log(req);
19+
return;
20+
}
21+
};
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
const request = require('supertest')
2-
const server = require('../../../api/server')
3-
const db = require('../../config/dbConfig')
1+
const request = require("supertest");
2+
const server = require("../../../api/server");
3+
const db = require("../../config/dbConfig");
44

5-
// beforeEach(async () => {
6-
// await db.seed.run()
7-
// })
5+
beforeEach(async () => {
6+
await db.seed.run();
7+
});
88

9-
describe('projects router tests', () => {
10-
11-
test('get all projects', async () => {
12-
jest.setTimeout(10000)
13-
const res = await request(server).get('/api/overview')
14-
expect(res.status).toBe(200)
15-
expect(res.type).toBe('application/json')
16-
})
17-
})
9+
describe("projects router tests", () => {
10+
test("get all projects", async () => {
11+
jest.setTimeout(10000);
12+
const res = await request(server).get("/api/overview");
13+
expect(res.status).toBe(200);
14+
expect(res.type).toBe("application/json");
15+
});
16+
});
Lines changed: 70 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,79 @@
1-
const request = require('supertest')
2-
const server = require('../../../api/server')
3-
const db = require('../../config/dbConfig')
1+
const request = require("supertest");
2+
const server = require("../../../api/server");
43

5-
const jwt = require('jsonwebtoken')
6-
const secrets = require('../../config/secrets')
4+
const jwt = require("jsonwebtoken");
5+
const secrets = require("../../config/secrets");
76

87
beforeAll(() => {
9-
const generateToken = (user) => {
10-
const payload = {
11-
subject: user.id,
12-
username: user.username
13-
}
14-
const options = {
15-
expiresIn: '1d'
16-
}
17-
return jwt.sign(payload, secrets.jwt, options)
18-
}
19-
token = generateToken({ id: 1, username: 'testuser1' })
20-
})
8+
const generateToken = (user) => {
9+
const payload = {
10+
subject: user.id,
11+
username: user.username,
12+
};
13+
const options = {
14+
expiresIn: "1d",
15+
};
16+
return jwt.sign(payload, secrets.jwt, options);
17+
};
18+
token = generateToken({ id: 1, username: "testuser1" });
19+
});
2120

22-
describe('projects router tests', () => {
21+
describe("projects router tests", () => {
22+
test("get all projects for a user", async () => {
23+
const res = await request(server)
24+
.get("/api/users/1/projects")
25+
.set({ Authorization: token });
26+
expect(res.status).toBe(200);
27+
expect(res.type).toBe("application/json");
28+
});
2329

24-
test('get all projects for a user', async () => {
25-
const res = await request(server)
26-
.get('/api/users/1/projects')
27-
.set({ Authorization: token })
28-
expect(res.status).toBe(200)
29-
expect(res.type).toBe('application/json')
30-
})
30+
test("get a specific project", async () => {
31+
const res = await request(server)
32+
.get("/api/users/1/projects/1")
33+
.set({ Authorization: token });
34+
expect(res.status).toBe(200);
35+
expect(res.type).toBe("application/json");
36+
});
3137

32-
test('get a specific project', async () => {
33-
const res = await request(server)
34-
.get('/api/users/1/projects/1')
35-
.set({ Authorization: token })
36-
expect(res.status).toBe(200)
37-
expect(res.type).toBe('application/json')
38-
})
38+
test("create a new project", async () => {
39+
const payload = {
40+
user_id: 1,
41+
title: "Dogs, dogs, dogs!",
42+
description: "So many dogs! We love dogs. You can pet them.",
43+
goal_amount: 10000,
44+
amount_received: 1000,
45+
funding_completed: false,
46+
};
47+
const res = await request(server)
48+
.post("/api/users/1/projects/")
49+
.set({ Authorization: token })
50+
.send(payload);
51+
expect(res.status).toBe(201);
52+
expect(res.type).toBe("application/json");
53+
});
3954

40-
test('create a new project', async () => {
41-
const payload = {
42-
user_id: 1,
43-
title: "Dogs, dogs, dogs!",
44-
description: "So many dogs! We love dogs. You can pet them.",
45-
goal_amount: 10000,
46-
amount_received: 1000,
47-
funding_completed: false,
48-
}
49-
const res = await request(server)
50-
.post('/api/users/1/projects/')
51-
.set({ Authorization: token })
52-
.send(payload)
53-
expect(res.status).toBe(201)
54-
expect(res.type).toBe('application/json')
55-
})
55+
test("update a project", async () => {
56+
const payload = {
57+
user_id: 1,
58+
title: "Dogs, dogs, dogs!",
59+
description: "So many dogs! We love dogs. You can pet them.",
60+
goal_amount: 10000,
61+
amount_received: 10000,
62+
funding_completed: true,
63+
};
5664

57-
test('update a project', async () => {
58-
const payload = {
59-
user_id: 1,
60-
title: "Dogs, dogs, dogs!",
61-
description: "So many dogs! We love dogs. You can pet them.",
62-
goal_amount: 10000,
63-
amount_received: 10000,
64-
funding_completed: true,
65-
}
65+
const res = await request(server)
66+
.put("/api/users/1/projects/3")
67+
.set({ Authorization: token })
68+
.send(payload);
69+
expect(res.status).toBe(200);
70+
expect(res.type).toBe("application/json");
71+
});
6672

67-
const res = await request(server)
68-
.put('/api/users/1/projects/3')
69-
.set({ Authorization: token })
70-
.send(payload)
71-
expect(res.status).toBe(200)
72-
expect(res.type).toBe('application/json')
73-
})
74-
75-
//
76-
77-
// test('delete a project', async () => {
78-
// const res = await request(server)
79-
// .delete('/users/2/projects/2')
80-
// .set({ Authorization: token })
81-
// expect(res.status).toBe(204)
82-
// })
83-
})
73+
test("delete a project", async () => {
74+
const res = await request(server)
75+
.delete("/users/2/projects/2")
76+
.set({ Authorization: token });
77+
expect(res.status).toBe(204);
78+
});
79+
});
Lines changed: 57 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,60 @@
1-
const request = require('supertest')
2-
const server = require('../../../api/server')
3-
const db = require('../../config/dbConfig')
4-
5-
const jwt = require('jsonwebtoken')
6-
const secrets = require('../../config/secrets')
7-
1+
const request = require("supertest");
2+
const server = require("../../../api/server");
3+
const db = require("../../config/dbConfig");
84

5+
const jwt = require("jsonwebtoken");
6+
const secrets = require("../../config/secrets");
97

108
beforeAll(() => {
11-
const generateToken = (user) => {
12-
const payload = {
13-
subject: user.id,
14-
username: user.username
15-
}
16-
const options = {
17-
expiresIn: '1d'
18-
}
19-
return jwt.sign(payload, secrets.jwt, options)
20-
}
21-
token = generateToken({ id: 1, username: 'testuser1' })
22-
})
23-
24-
describe('users router tests', () => {
25-
test('get all users failure - no token', async () => {
26-
const res = await request(server).get('/api/users')
27-
expect(res.status).toBe(401)
28-
expect(res.type).toBe('application/json')
29-
30-
})
31-
32-
//this test requires a token. Figure out how to get a token into a test environment.
33-
test('get all users - success', async () => {
34-
const res = await request(server)
35-
.get('/api/users')
36-
.set({ Authorization: token})
37-
expect(res.status).toBe(200)
38-
expect(res.type).toBe('application/json')
39-
})
40-
41-
test('get a single user', async () => {
42-
const res = await request(server)
43-
.get('/api/users/1')
44-
.set({ Authorization: token})
45-
expect(res.status).toBe(200)
46-
expect(res.type).toBe('application/json')
47-
})
48-
49-
//need to figure out how to add the token to this request.
50-
test('update a user', async () => {
51-
const res = await request(server)
52-
.put('/api/users/1')
53-
.set({ Authorization: token})
54-
.send({ username: 'TestUserFive', password: 'TestPasswordFive' })
55-
expect(res.type).toBe('application/json')
56-
expect(res.status).toBe(200)
57-
})
58-
59-
//need to figure out how to add the token to this request.
60-
test('delete a user', async () => {
61-
const res = await request(server)
62-
.delete('/api/users/1')
63-
.set({ Authorization: token})
64-
expect(res.status).toBe(204)
65-
})
66-
})
9+
const generateToken = (user) => {
10+
const payload = {
11+
subject: user.id,
12+
username: user.username,
13+
};
14+
const options = {
15+
expiresIn: "1d",
16+
};
17+
return jwt.sign(payload, secrets.jwt, options);
18+
};
19+
token = generateToken({ id: 1, username: "testuser1" });
20+
});
21+
22+
describe("users router tests", () => {
23+
test("get all users failure - no token", async () => {
24+
const res = await request(server).get("/api/users");
25+
expect(res.status).toBe(401);
26+
expect(res.type).toBe("application/json");
27+
});
28+
29+
test("get all users - success", async () => {
30+
const res = await request(server)
31+
.get("/api/users")
32+
.set({ Authorization: token });
33+
expect(res.status).toBe(200);
34+
expect(res.type).toBe("application/json");
35+
});
36+
37+
test("get a single user", async () => {
38+
const res = await request(server)
39+
.get("/api/users/1")
40+
.set({ Authorization: token });
41+
expect(res.status).toBe(200);
42+
expect(res.type).toBe("application/json");
43+
});
44+
45+
test("update a user", async () => {
46+
const res = await request(server)
47+
.put("/api/users/1")
48+
.set({ Authorization: token })
49+
.send({ username: "TestUserFive", password: "TestPasswordFive" });
50+
expect(res.type).toBe("application/json");
51+
expect(res.status).toBe(200);
52+
});
53+
54+
test("delete a user", async () => {
55+
const res = await request(server)
56+
.delete("/api/users/1")
57+
.set({ Authorization: token });
58+
expect(res.status).toBe(204);
59+
});
60+
});

node_modules/@types/node/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@types/node/README.md

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)