forked from redlipbatfish/scratchproject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
141 lines (94 loc) · 3.21 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// test('it should sum correctly', () => {
// expect(1+2).toEqual(3)
// })
const request = require('supertest');
const assert = require('assert');
const express = require('express');
const app = express();
//const server = 'http://localhost:3000';
const userController = require('./server/controllers/userController');
const dbController = require('./server/controllers/dbController');
const { hasUncaughtExceptionCaptureCallback } = require('process');
app.post('/login', userController.checkUser,
(req, res) => {
return res.status(200).json(res.locals.loginUser)
})
app.get('/test', (req,res) => {
res.status(200).send();
})
app.listen(3000, () => console.log(`App listening on port ${3000}`));
// front end test
// describe('front end test', () => {
// first test
// let clicked = false;
// const signUpBtn = document.querySelector('login-btn')
// signUpBtn.addEventListener('click', function () {
// clicked = true;
// })
// // expect(global.window.location.href).toContain('/fee+d')
// expect(global.window.location.href).toContain('/feed');
// expect(data.userid).toEqual(expect.any(Number))
// })
// //2nd test
// test('should log user in', () => {
// const email = "red@gmail.com";
// const password = "1234"
// const body = { email: "red@gmail.com", password:"1234"}
// const reqOptions = {
// method: 'POST',
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify({ email: email, password: password})
// }
// fetch('/db/login', reqOptions)
// .then(res => {
// return res.json()
// })
// .then((authStatus) => {
// console.log("-----",authStatus)
// })
// expect(authStatus.userid).toBe(Number);
// expect(global.window.location.href).toContain('/feed')
// })
// })
// backend tests
describe('Back-end tests', function(){
it('Should increment the status by one when pushing increment button', () => {
})
it('Should successfully respond to a login attempt from an invalid user ID.', () => {
// send a post request to login with invalid user data
// should not invoke the redirect
const invalidUser = {
firstName: '!invalidFirstName',
lastName:'!invalidLastName',
username:'!invalidUsername',
email:'!invalidEmail',
// password:'!invalidPassword',
}
const validUser = {
email:'jetyn@gmail.com',
password:'123',
}
// request(app)
// .post('/login')
// .send(validUser)
// .end(async(err, res) => {
// await console.log(res.body)
// })
// works
// request(app)
// .get('/test')
// .end((err,res) => {
// if (err) throw err;
// expect(res.status).toBe(400)
// })
return request(app)
.post('/login')
.send(validUser)
.end((err,res) => {
if (err) throw err;
expect(res.status).toBe(200)
})
// baseline test
// request(app)
});
})