From 088406dffc41a5328e0bdacab8823d7e797fd04d Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sat, 11 May 2024 01:00:29 +0700 Subject: [PATCH] Create user.test.js --- test/integration/user.test.js | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/integration/user.test.js diff --git a/test/integration/user.test.js b/test/integration/user.test.js new file mode 100644 index 000000000..1b9e78d31 --- /dev/null +++ b/test/integration/user.test.js @@ -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: 'john.doe@example.com', + 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: 'john.doe@example.com', + 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'); + }); + }); +});