added all testing files
This commit is contained in:
BIN
MilestoneSubmissions/UAT_TESTING.pdf
Normal file
BIN
MilestoneSubmissions/UAT_TESTING.pdf
Normal file
Binary file not shown.
@@ -33,6 +33,6 @@ services:
|
||||
volumes:
|
||||
- ../ProjectSourceCode:/home/node/app # Mount ProjectSourceCode directory
|
||||
- ../ProjectSourceCode/node_modules:/home/node/app/node_modules # Mount node_modules directory
|
||||
command: 'npm start'
|
||||
command: 'npm run testandrun'
|
||||
volumes:
|
||||
group-project:
|
||||
2394
ProjectSourceCode/package-lock.json
generated
2394
ProjectSourceCode/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -56,6 +56,9 @@ app.set('views', path.join(__dirname, 'views'));
|
||||
app.use(bodyParser.json()); // specify the usage of JSON for parsing request body.
|
||||
|
||||
// initialize session variables
|
||||
app.get('/welcome', (req, res) => {
|
||||
res.json({status: 'success', message: 'Welcome!'});
|
||||
});
|
||||
app.use(
|
||||
session({
|
||||
secret: process.env.SESSION_SECRET,
|
||||
@@ -137,16 +140,23 @@ app.get('/', (req, res) => {
|
||||
// Trigger Registration Form to Post
|
||||
app.post('/register', async (req, res) => {
|
||||
try {
|
||||
if (!req.body.username || !req.body.password) {
|
||||
// If username or password is missing, respond with status 400 and an error message
|
||||
return res.status(400).json({status: 'error', message: 'Invalid input'});
|
||||
}
|
||||
// Hash the password using bcrypt library
|
||||
const hash = await bcrypt.hash(req.body.password, 10);
|
||||
|
||||
// Insert username and hashed password into the 'users' table
|
||||
await db.none('INSERT INTO users (username, password) VALUES ($1, $2)', [req.body.username, hash]);
|
||||
|
||||
//res.status(200);
|
||||
res.json({status: 'success', message: 'Success'});
|
||||
// Direct user to login screen after data has been inserted successfully
|
||||
res.redirect('/login');
|
||||
} catch (error) {
|
||||
// If the insert fails, redirect to GET /register route
|
||||
res.status(400);
|
||||
//res.json({status: 'success', message: 'Invalid input'});
|
||||
res.redirect('/register');
|
||||
}
|
||||
});
|
||||
@@ -165,5 +175,5 @@ app.get('/', (req, res) => {
|
||||
// <!-- Section 5 : Start Server-->
|
||||
// *****************************************************
|
||||
// starting the server and keeping the connection open to listen for more requests
|
||||
app.listen(3000);
|
||||
module.exports = app.listen(3000);
|
||||
console.log('Server is listening on port 3000');
|
||||
@@ -1,4 +1,12 @@
|
||||
CREATE TABLE users (
|
||||
username VARCHAR(50) PRIMARY KEY,
|
||||
password CHAR(60) NOT NULL
|
||||
UserID SERIAL PRIMARY KEY,
|
||||
Username VARCHAR(50) UNIQUE NOT NULL,
|
||||
Password CHAR(60) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE FavoriteTeam (
|
||||
UserID INT REFERENCES users(UserID) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
TeamID INT,
|
||||
TeamName VARCHAR(50),
|
||||
PRIMARY KEY (UserID, TeamID)
|
||||
);
|
||||
@@ -0,0 +1,82 @@
|
||||
|
||||
// ********************** Initialize server **********************************
|
||||
|
||||
const server = require('../src/index.js'); //TODO: Make sure the path to your index.js is correctly added
|
||||
|
||||
// ********************** Import Libraries ***********************************
|
||||
|
||||
const chai = require('chai'); // Chai HTTP provides an interface for live integration testing of the API's.
|
||||
const chaiHttp = require('chai-http');
|
||||
chai.should();
|
||||
chai.use(chaiHttp);
|
||||
const {assert, expect} = chai;
|
||||
|
||||
// ********************** DEFAULT WELCOME TESTCASE ****************************
|
||||
|
||||
describe('Server!', () => {
|
||||
// Sample test case given to test / endpoint.
|
||||
it('Returns the default welcome message', done => {
|
||||
chai
|
||||
.request(server)
|
||||
.get('/welcome')
|
||||
.end((err, res) => {
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body.status).to.equals('success');
|
||||
assert.strictEqual(res.body.message, 'Welcome!');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// *********************** TODO: WRITE 2 UNIT TESTCASES **************************
|
||||
|
||||
// ********************************************************************************
|
||||
|
||||
describe('Testing Add User API', () => {
|
||||
it('positive: /register', done => {
|
||||
// Define mock user data
|
||||
const userData = {
|
||||
username: 'Vishal Vunnam',
|
||||
password: '123456'
|
||||
};
|
||||
// Make a POST request to /register with mock user data
|
||||
chai.request(server)
|
||||
.post('/register')
|
||||
.send(userData)
|
||||
.end((err, res) => {
|
||||
// Assertions
|
||||
expect(res).to.have.status(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
//We are checking POST /add_user API by passing the user info in in incorrect manner (name cannot be an integer). This test case should pass and return a status 400 along with a "Invalid input" message.
|
||||
|
||||
describe('Testing Add User API', () => {
|
||||
it('Negative: /register. Checking invalid name', done => {
|
||||
chai.request(server)
|
||||
.post('/register')
|
||||
.send({ Username: 10, Password: '2020-02-20'})
|
||||
.end((err, res) => {
|
||||
// Assertions
|
||||
expect(res).to.have.status(400);
|
||||
expect(res.body.message).to.equals('Invalid input');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Testing Render', () => {
|
||||
// Sample test case given to test /test endpoint.
|
||||
it('test "/login" route should render with an html response', done => {
|
||||
chai
|
||||
.request(server)
|
||||
.get('/login') // for reference, see lab 8's login route (/login) which renders home.hbs
|
||||
.end((err, res) => {
|
||||
res.should.have.status(200); // Expecting a success status code
|
||||
res.should.be.html; // Expecting a HTML response
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user