This repository has been archived on 2025-11-04. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
know-it-all/server/tests/auth/Login.test.js
C4 Patino 1b9b8db04d
Merge development (#13)
* Added direct join functionality

* Completed CreateUser test suite

* Removed non-essential imports

* Reordered test functions

* Login test suite completed

* Completed Logout test suite

* Completed RequestReset test suite

* Completed ResetPassword test suite

* Completed UpdateUserDetails test suite

* Completed SetAudio test suite

* Fixed UpdateUserDetials suite

* GetUserDetails test suite complete

* Completed ResetPassword test suite

* Completed GetMemberOrgs test suite

* Completed GetOwnedOrgs test suite

* AddOrgMember test suite added

* Created CreateOrg test suite

* Modified AddOrgMember suite

* Delete Org test suite completed

* Completed GetOrg test suite

* Completed RemoveOrgMember test suite

* Completed UpdateOrgDetails test suite

* Changed oackage,json files

* Switched project over to workspaces

* Test build script completed

* Fixed config.json missing on workflow run

* Completed test-build.js.yml

* Completed test-build.js.yml

* Completed test-build.js.yml

* Test build completed

* Completed test-build.js.yml

* Added touch server

* Touched test-build.js.yml

* Reworked workflows and automated test suite (#7)

Reworked workflows and automated test suite (#7)

* Configured new js file and isolated database files in db folder (#10)

* Changed config.js and isolated db

* Configured new js file and isolated database files in db folder

* Removed .env files from config (#11)
2022-03-30 14:59:11 -05:00

55 lines
1.8 KiB
JavaScript

const supertest = require('supertest');
var { sequelize, Token } = require('../../db/models/index');
const app = require('../../app');
const { createTestUser } = require('../utils');
describe('Login', function () {
beforeEach(async () => {
try {
await sequelize.authenticate();
await sequelize.sync({ force: 'true' });
} catch (error) {
console.log('[ERROR]: Database connection failed');
}
});
test('[200] Successful login', async () => {
const password = 'password';
const user = await createTestUser('Test', 'User', password);
await supertest(app)
.post('/api/auth/login')
.send({ email: user.email, password })
.expect(200)
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.then(async (response) => {
const token = await Token.findByPk(response.body.token);
expect(response.body.token).toEqual(token.tokenID);
expect(response.body.userID).toEqual(token.userID);
});
});
test('[400] Request missing fields', async () => {
await supertest(app)
.post('/api/auth/login')
.send()
.expect(400, 'Request lacking information')
.set('Accept', 'text/html')
.expect('Content-Type', /text/);
});
test('[400] Invalid password', async () => {
const password = 'password';
const user = await createTestUser('Test', 'User', password);
await supertest(app)
.post('/api/auth/login')
.send({ email: user.email, password: 'randomString' })
.expect(400, 'Unauthorized user')
.set('Accept', 'text/html')
.expect('Content-Type', /text/);
});
});