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/Logout.test.js
2022-03-30 09:46:43 -05:00

50 lines
1.5 KiB
JavaScript

require('dotenv').config();
const supertest = require('supertest');
var { sequelize, Token } = require('../../models/index');
const app = require('../../app');
const { createTestToken } = require('../utils');
describe('Logout', function () {
beforeEach(async () => {
try {
await sequelize.authenticate();
await sequelize.sync({ force: 'true' });
} catch (error) {
console.log('[ERROR]: Database connection failed');
}
});
test('[200] Successful logout', async () => {
const token = await createTestToken({
firstName: 'Test',
lastName: 'User',
password: 'password',
});
await supertest(app)
.post('/api/auth/logout')
.send({ token: token.tokenID })
.expect(200, 'User logged out')
.set('Accept', 'text/html')
.expect('Content-Type', /text/);
});
test('[403] Missing token', async () => {
await supertest(app)
.post('/api/auth/logout')
.send()
.expect(403, 'Unauthorized user')
.set('Accept', 'text/html')
.expect('Content-Type', /text/);
});
test('[511] Token was not found', async () => {
await supertest(app)
.post('/api/auth/logout')
.send({ token: 'randomString' })
.expect(511, 'Session expired')
.set('Accept', 'text/html')
.expect('Content-Type', /text/);
});
});