-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// test/integration/user.test.js | ||
|
||
const chai = require('chai'); | ||
const chaiHttp = require('chai-http'); | ||
const app = require('../app'); | ||
|
||
const expect = chai.expect; | ||
chai.use(chaiHttp); | ||
|
||
describe('User API Integration Tests', () => { | ||
describe('POST /register', () => { | ||
it('should create a new user and return a JWT', async () => { | ||
const res = await chai.request(app).post('/register').send({ | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
email: '[email protected]', | ||
password: 'password123' | ||
}); | ||
|
||
expect(res).to.have.status(201); | ||
expect(res.body).to.be.an('object'); | ||
expect(res.body).to.have.property('token'); | ||
expect(res.body.token).to.be.a('string'); | ||
}); | ||
}); | ||
|
||
describe('POST /login', () => { | ||
it('should login a user and return a JWT', async () => { | ||
const res = await chai.request(app).post('/login').send({ | ||
email: '[email protected]', | ||
password: 'password123' | ||
}); | ||
|
||
expect(res).to.have.status(200); | ||
expect(res.body).to.be.an('object'); | ||
expect(res.body).to.have.property('token'); | ||
expect(res.body.token).to.be.a('string'); | ||
}); | ||
}); | ||
}); |