generated from nyu-software-engineering/generic-mern-stack-project
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from agiledev-students-spring2024/loginSignUpT…
…ests create test folder & tests for signup + login
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const chai = require('chai'); | ||
const chaiHttp = require('chai-http'); | ||
const expect = chai.expect; | ||
const app = require('../back-end/App.js'); | ||
|
||
chai.use(chaiHttp); | ||
|
||
describe('Login', () => { | ||
// Test successful login for BobbyImpasto | ||
it('should log in a user with the correct credentials', done => { | ||
chai.request(app) | ||
.post('/login') | ||
.send({'username': 'john123', 'password': 'qwerasdf'}) | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
expect(res.body).to.have.property('message').eql('Login successful'); | ||
done(); | ||
}); | ||
}); | ||
|
||
// Test failed login for wrong password | ||
it('should not log in a user with incorrect credentials', done => { | ||
chai.request(app) | ||
.post('/login') | ||
.send({'username': 'john123', 'password': 'incorrectPassword'}) | ||
.end((err, res) => { | ||
expect(res).to.have.status(401); | ||
expect(res.body).to.have.property('message').eql('Invalid username or password'); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const chai = require('chai'); | ||
const chaiHttp = require('chai-http'); | ||
const expect = chai.expect; | ||
const app = require('../back-end/App.js'); // Replace with the correct path to your Express app | ||
|
||
chai.use(chaiHttp); | ||
|
||
describe('Signup', () => { | ||
// Test successful signup | ||
it('should register a new user', done => { | ||
chai.request(app) | ||
.post('/signup') | ||
.send({ | ||
'username': 'newUser123', | ||
'password': 'NewPass123!' | ||
}) | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
expect(res.body).to.have.property('message').eql('Signup successful.'); | ||
done(); | ||
}); | ||
}); | ||
|
||
// Test signup with existing username | ||
it('should not register a user with an existing username', done => { | ||
chai.request(app) | ||
.post('/signup') | ||
.send({ | ||
'username': 'john123', // Assuming john123 is already in the mockDatabase.json | ||
'password': 'SomePass123!' | ||
}) | ||
.end((err, res) => { | ||
expect(res).to.have.status(400); | ||
expect(res.body).to.have.property('message').eql('Username already exists.'); | ||
done(); | ||
}); | ||
}); | ||
}); |