* 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)
128 lines
4 KiB
JavaScript
128 lines
4 KiB
JavaScript
const supertest = require('supertest');
|
|
|
|
var { sequelize, Organization } = require('../../db/models/index');
|
|
const app = require('../../app');
|
|
const { createTestUser, createTestOrg } = require('../utils');
|
|
|
|
describe('CreateUser', function () {
|
|
beforeEach(async () => {
|
|
try {
|
|
await sequelize.authenticate();
|
|
await sequelize.sync({ force: 'true' });
|
|
} catch (error) {
|
|
console.log('[ERROR]: Database connection failed');
|
|
}
|
|
});
|
|
|
|
test('[200] User successfully created', async () => {
|
|
const user = {
|
|
firstName: 'Test',
|
|
lastName: 'User',
|
|
email: 'test.user@test.com',
|
|
pronouns: 'they/them',
|
|
};
|
|
const password = 'password';
|
|
|
|
await supertest(app)
|
|
.post('/api/auth/register')
|
|
.send({ ...user, password })
|
|
.expect(200)
|
|
.set('Accept', 'application/json')
|
|
.expect('Content-Type', /json/)
|
|
.then((response) => {
|
|
expect(response.body).toEqual(expect.objectContaining(user));
|
|
});
|
|
});
|
|
|
|
test('[500] Request missing fields', async () => {
|
|
await supertest(app)
|
|
.post('/api/auth/register')
|
|
.send()
|
|
.expect(400, 'The request is missing required fields.')
|
|
.set('Accept', 'text/html')
|
|
.expect('Content-Type', /text/);
|
|
});
|
|
|
|
test('[500] User already exists', async () => {
|
|
await createTestUser('Test', 'User', 'password');
|
|
const userInfo = {
|
|
firstName: 'Test',
|
|
lastName: 'User',
|
|
email: 'test.user@test.com',
|
|
pronouns: 'they/them',
|
|
password: 'password',
|
|
};
|
|
|
|
await supertest(app)
|
|
.post('/api/auth/register')
|
|
.send(userInfo)
|
|
.expect(500, 'A user with that email already exists.')
|
|
.set('Accept', 'text/html')
|
|
.expect('Content-Type', /text/);
|
|
});
|
|
|
|
test('[200] Created with organization', async () => {
|
|
const orgOwner = {
|
|
firstName: 'Org',
|
|
lastName: 'Owner',
|
|
password: 'password',
|
|
};
|
|
const org = await createTestOrg('Test Org', orgOwner);
|
|
|
|
const user = {
|
|
firstName: 'Test',
|
|
lastName: 'User',
|
|
email: 'test.user@test.com',
|
|
pronouns: 'they/them',
|
|
};
|
|
const password = 'password';
|
|
|
|
await supertest(app)
|
|
.post(`/api/auth/register`)
|
|
.send({ ...user, password, orgID: org.orgID })
|
|
.expect(200)
|
|
.set('Accept', 'application/json')
|
|
.expect('Content-Type', /json/)
|
|
.then(async (response) => {
|
|
const org = await Organization.findByPk(response.body.orgID, {
|
|
include: {
|
|
association: 'orgMember',
|
|
},
|
|
});
|
|
|
|
expect(response.body.user).toEqual(
|
|
expect.objectContaining(user)
|
|
);
|
|
expect(org.orgMember).toEqual(
|
|
expect.arrayContaining([expect.objectContaining(user)])
|
|
);
|
|
});
|
|
});
|
|
|
|
test('[200] Attemped to create with organization', async () => {
|
|
const orgOwner = {
|
|
firstName: 'Org',
|
|
lastName: 'Owner',
|
|
password: 'password',
|
|
};
|
|
await createTestOrg('Test Org', orgOwner);
|
|
|
|
const user = {
|
|
firstName: 'Test',
|
|
lastName: 'User',
|
|
email: 'test.user@test.com',
|
|
pronouns: 'they/them',
|
|
};
|
|
const password = 'password';
|
|
|
|
await supertest(app)
|
|
.post(`/api/auth/register`)
|
|
.send({ ...user, password, orgID: 'randomString' })
|
|
.expect(200)
|
|
.set('Accept', 'application/json')
|
|
.expect('Content-Type', /json/)
|
|
.then(async (response) => {
|
|
expect(response.body).toEqual(expect.objectContaining(user));
|
|
});
|
|
});
|
|
});
|