* 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)
108 lines
3.3 KiB
JavaScript
108 lines
3.3 KiB
JavaScript
const supertest = require('supertest');
|
|
|
|
var { sequelize, Token } = require('../../db/models/index');
|
|
const app = require('../../app');
|
|
const { createTestToken, createTestUser } = require('../utils');
|
|
|
|
describe('GetUserDetails', function () {
|
|
beforeEach(async () => {
|
|
try {
|
|
await sequelize.authenticate();
|
|
await sequelize.sync({ force: 'true' });
|
|
} catch (error) {
|
|
console.log('[ERROR]: Database connection failed');
|
|
}
|
|
});
|
|
|
|
test('[200] Successfully recieved user details', async () => {
|
|
const token = await createTestToken({
|
|
firstName: 'Test',
|
|
lastName: 'User',
|
|
password: 'password',
|
|
});
|
|
|
|
await supertest(app)
|
|
.get(`/api/auth/${token.userID}`)
|
|
.query({
|
|
token: token.tokenID,
|
|
})
|
|
.send()
|
|
.expect(200)
|
|
.set('Accept', 'application/json')
|
|
.expect('Content-Type', /json/)
|
|
.then((response) => {
|
|
expect(response.body).toEqual(
|
|
expect.objectContaining({
|
|
firstName: 'Test',
|
|
lastName: 'User',
|
|
email: 'test.user@test.com',
|
|
})
|
|
);
|
|
});
|
|
});
|
|
|
|
test('[500] User ID does not exist', async () => {
|
|
const token = await createTestToken({
|
|
firstName: 'Test',
|
|
lastName: 'User',
|
|
password: 'password',
|
|
});
|
|
|
|
await supertest(app)
|
|
.get(`/api/auth/randomString`)
|
|
.query({ token: token.tokenID })
|
|
.send()
|
|
.expect(500, 'No user with that ID exists.')
|
|
.set('Accept', 'text/html')
|
|
.expect('Content-Type', /text/);
|
|
});
|
|
|
|
test('[403] No contact with that user', async () => {
|
|
const token = await createTestToken({
|
|
firstName: 'Test',
|
|
lastName: 'User',
|
|
password: 'password',
|
|
});
|
|
const user = await createTestUser('New', 'User', 'password');
|
|
|
|
await supertest(app)
|
|
.get(`/api/auth/${user.userID}`)
|
|
.query({ token: token.tokenID })
|
|
.send()
|
|
.expect(403, 'You do not have contact with this user.')
|
|
.set('Accept', 'text/html')
|
|
.expect('Content-Type', /text/);
|
|
});
|
|
|
|
test('[403] Missing token', async () => {
|
|
const token = await createTestToken({
|
|
firstName: 'Test',
|
|
lastName: 'User',
|
|
password: 'password',
|
|
});
|
|
|
|
await supertest(app)
|
|
.get(`/api/auth/${token.userID}`)
|
|
.query()
|
|
.send()
|
|
.expect(403, 'Unauthorized user')
|
|
.set('Accept', 'text/html')
|
|
.expect('Content-Type', /text/);
|
|
});
|
|
|
|
test('[511] Token was not found', async () => {
|
|
const token = await createTestToken({
|
|
firstName: 'Test',
|
|
lastName: 'User',
|
|
password: 'password',
|
|
});
|
|
|
|
await supertest(app)
|
|
.get(`/api/auth/${token.userID}`)
|
|
.query({ token: 'randomString' })
|
|
.send()
|
|
.expect(511, 'Session expired')
|
|
.set('Accept', 'text/html')
|
|
.expect('Content-Type', /text/);
|
|
});
|
|
});
|