diff --git a/README.md b/README.md index 338dd34e8..c7b0690c9 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,6 @@ Refer to [Kafka Ubuntu 22.04 setup guide](https://www.fosstechnix.com/install-ap 4. Reload systemd: - ```bash $ sudo systemctl daemon-reload ``` @@ -275,7 +274,6 @@ Refer to [Kafka Ubuntu 22.04 setup guide](https://www.fosstechnix.com/install-ap ### Install Redis - Refer to [Redis Ubuntu 22.04 setup guide](https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-22-04) 1. Update the package list: diff --git a/src/constants/common.js b/src/constants/common.js index 29d1935cd..296ce2031 100644 --- a/src/constants/common.js +++ b/src/constants/common.js @@ -27,6 +27,7 @@ module.exports = { '/user/v1/organization/list', '/user/v1/user-role/default', '/user/v1/account/validateUserSession', + '/user/v1/account/searchByEmailIds', ], notificationEmailType: 'email', accessTokenExpiry: process.env.ACCESS_TOKEN_EXPIRY, diff --git a/src/controllers/v1/account.js b/src/controllers/v1/account.js index b49cdc363..ae68f93fb 100644 --- a/src/controllers/v1/account.js +++ b/src/controllers/v1/account.js @@ -310,4 +310,24 @@ module.exports = class Account { return error } } + + /** + * Account Search By Email + * @method + * @name list + * @param {Object} req -request data with method POST. + * @param {Object} req.body -request body contains user deatils. + * @param {Array} req.body.userIds -contains emailIds. + * @returns {JSON} - all accounts data + */ + async searchByEmailIds(req) { + try { + const result = await accountService.searchByEmailIds(req) + return result + } catch (error) { + return error + } + } + + listByEmailIds } diff --git a/src/helpers/responses.js b/src/helpers/responses.js index 9b5df37ae..2fb351ede 100644 --- a/src/helpers/responses.js +++ b/src/helpers/responses.js @@ -5,7 +5,7 @@ * Description : Response constants used in this service */ -const form = require('@generics/form') +const form = require('../generics/form') const { elevateLog, correlationId } = require('elevate-logger') const logger = elevateLog.init() const successResponse = async ({ statusCode = 500, responseCode = 'OK', message, result = [], meta = {} }) => { diff --git a/src/integration-test/account/account.spec.js b/src/integration-test/account/account.spec.js index c4b13c777..ba1f67714 100644 --- a/src/integration-test/account/account.spec.js +++ b/src/integration-test/account/account.spec.js @@ -27,39 +27,21 @@ describe('/user/v1/account', function () { password: password, isAMentor: false, }) - logError(res) expect(res.statusCode).toBe(201) expect(res.body).toMatchSchema(responseSchema.createProfileSchema) }) + it('/login', async () => { - let insertedUserDetails = await insertUser() let res = await request.post('/user/v1/account/login').send({ - email: insertedUserDetails.email, - password: insertedUserDetails.password, + email: userEmail, + password: password, }) - logError(res) expect(res.statusCode).toBe(200) expect(res.body).toMatchSchema(responseSchema.loginSchema) }) - it('/verifyMentor', async () => { - let res = await request.get('/user/v1/account/verifyMentor').query({ userId: userDetails.userId }) - - logError(res) - expect(res.statusCode).toBe(200) - expect(res.body).toMatchSchema(responseSchema.verifyMentor) - }) - - it('/verifyUser', async () => { - let res = await request.get('/user/v1/account/verifyUser').query({ userId: userDetails.userId }) - - logError(res) - expect(res.statusCode).toBe(200) - expect(res.body).toMatchSchema(responseSchema.verifyUser) - }) - it('/acceptTermsAndCondition', async () => { let res = await request.patch('/user/v1/account/acceptTermsAndCondition') @@ -67,41 +49,75 @@ describe('/user/v1/account', function () { expect(res.statusCode).toBe(200) expect(res.body).toMatchSchema(responseSchema.acceptTermsAndConditionSchema) }) - it('/list', async () => { - let res = await request.patch('/user/v1/account/list').query({ type: 'mentee', page: 1, limit: 2 }) - logError(res) - expect(res.statusCode).toBe(200) - expect(res.body).toMatchSchema(responseSchema.listSchema) - }) it('/generateToken', async () => { let res = await request .post('/user/v1/account/generateToken') .query({ type: 'mentee', page: 1, limit: 2 }) .send({ - refreshToken: userDetails.refreshToken, + refresh_token: userDetails.refreshToken, }) logError(res) expect(res.statusCode).toBe(200) expect(res.body).toMatchSchema(responseSchema.generateTokenSchema) }) - it('/changeRole', async () => { - let res = await request.post('/user/v1/account/changeRole').send({ - email: userDetails.email, - }) - userDetails = await logIn() - logError(res) - expect(res.statusCode).toBe(200) - expect(res.body).toMatchSchema(responseSchema.changeRoleSchema) - }) it('/logout', async () => { let res = await request.post('/user/v1/account/logout').send({ - refreshToken: userDetails.refreshToken, + refresh_token: userDetails.refreshToken, }) logError(res) expect(res.statusCode).toBe(200) expect(res.body).toMatchSchema(responseSchema.logoutSchema) }) + + // search , changerole , verifyMentor , verifyuser doesn't have permissions and it is used in rolevalidation + + // it('/search', async () => { + // console.log(userDetails.userId) + // let res = await request.post('/user/v1/account/search') + // .set({ + // 'internal_access_token': 'internal_access_token', + // Connection: 'keep-alive', + // 'Content-Type': 'application/json', + // }) + // .send({ + // userIds : [456] + // }) + + // logError(res) + // expect(res.statusCode).toBe(200) + // console.log("listr ======",res.body) + // expect(res.body).toMatchSchema(responseSchema.listSchema) + // }) + + // it('/changeRole', async () => { + // let res = await request.post('/user/v1/account/changeRole').send({ + // email: userDetails.email, + // role : 'mentor' + // }) + // userDetails = await logIn() + + // logError(res) + // expect(res.statusCode).toBe(200) + // expect(res.body).toMatchSchema(responseSchema.changeRoleSchema) + // }) + + // it('/verifyMentor', async () => { + // console.log(userDetails) + // let res = await request.get('/user/v1/account/verifyMentor').query({ userId: userDetails.userId }) + + // logError(res) + // expect(res.statusCode).toBe(200) + // expect(res.body).toMatchSchema(responseSchema.verifyMentor) + // }) + + // it('/verifyUser', async () => { + // let res = await request.get('/user/v1/account/verifyUser').query({ userId: userDetails.userId }) + + // logError(res) + // expect(res.statusCode).toBe(200) + // expect(res.body).toMatchSchema(responseSchema.verifyUser) + // }) }) diff --git a/src/integration-test/account/accountData.js b/src/integration-test/account/accountData.js index 4f3ce3cae..3ded6ad35 100644 --- a/src/integration-test/account/accountData.js +++ b/src/integration-test/account/accountData.js @@ -1,4 +1,5 @@ const usersData = require('@database/queries/users') +const UserCredentialQueries = require('@database/queries/userCredential') const { faker } = require('@faker-js/faker') const utilsHelper = require('@generics/utils') const crypto = require('crypto') @@ -10,12 +11,23 @@ const insertUser = async () => { let password = faker.internet.password() bodyData = { name: 'Nevil', - email: { address: email, verified: false }, + email: email, password: password, isAMentor: false, + organization_id: 1, + roles: [3], + otp: process.env.ENABLE_EMAIL_OTP_VERIFICATION, } bodyData.password = utilsHelper.hashPassword(bodyData.password) - await usersData.createUser(bodyData) + const res = await usersData.create(bodyData) + const userCredentialsBody = { + email: email, + password: password, + organization_id: bodyData.organization_id, + user_id: res.user_id, + } + await UserCredentialQueries.create(userCredentialsBody) + return { email: email, password: password, diff --git a/src/integration-test/account/responseSchema.js b/src/integration-test/account/responseSchema.js index cb72e3b97..3c4814e67 100644 --- a/src/integration-test/account/responseSchema.js +++ b/src/integration-test/account/responseSchema.js @@ -1,15 +1,13 @@ let commonBody = { properties: { - message: { + responseCode: { type: 'string', }, - meta: { - type: 'object', - }, - responseCode: { + message: { type: 'string', }, result: { + type: 'object', properties: { access_token: { type: 'string', @@ -18,80 +16,181 @@ let commonBody = { type: 'string', }, user: { + type: 'object', properties: { - _id: { + id: { + type: 'integer', + }, + email: { type: 'string', }, - areasOfExpertise: { - items: {}, - type: 'array', + email_verified: { + type: 'string', }, - createdAt: { + name: { type: 'string', }, - deleted: { - type: 'boolean', + gender: { + type: 'null', }, - designation: { - items: {}, - type: 'array', + location: { + type: 'null', }, - educationQualification: { + about: { type: 'null', }, - email: { + share_link: { + type: 'null', + }, + status: { + type: 'string', + }, + image: { + type: 'null', + }, + has_accepted_terms_and_conditions: { + type: 'boolean', + }, + languages: { + type: 'null', + }, + preferred_language: { + type: 'object', properties: { - address: { + value: { type: 'string', }, - verified: { - type: 'boolean', + label: { + type: 'string', }, }, - required: ['address', 'verified'], - type: 'object', - }, - hasAcceptedTAndC: { - type: 'boolean', + required: ['value', 'label'], }, - isAMentor: { - type: 'boolean', + organization_id: { + type: 'integer', }, - languages: { - items: {}, + roles: { type: 'array', + items: [ + { + type: 'integer', + }, + { + type: 'integer', + }, + { + type: 'integer', + }, + ], }, - location: { - items: {}, - type: 'array', + meta: { + type: 'null', }, - name: { + created_at: { type: 'string', }, - updatedAt: { + updated_at: { type: 'string', }, + deleted_at: { + type: 'null', + }, + organization: { + type: 'object', + }, + user_roles: { + type: 'array', + items: [ + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + title: { + type: 'string', + }, + user_type: { + type: 'integer', + }, + status: { + type: 'string', + }, + organization_id: { + type: 'integer', + }, + visibility: { + type: 'string', + }, + }, + required: ['id', 'title', 'user_type', 'status', 'organization_id', 'visibility'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + title: { + type: 'string', + }, + user_type: { + type: 'integer', + }, + status: { + type: 'string', + }, + organization_id: { + type: 'integer', + }, + visibility: { + type: 'string', + }, + }, + required: ['id', 'title', 'user_type', 'status', 'organization_id', 'visibility'], + }, + ], + }, }, required: [ + 'id', 'email', - '_id', + 'email_verified', 'name', - 'isAMentor', - 'hasAcceptedTAndC', - 'deleted', - 'educationQualification', - 'designation', + 'gender', 'location', - 'areasOfExpertise', + 'about', + 'share_link', + 'status', + 'image', + 'has_accepted_terms_and_conditions', 'languages', - 'updatedAt', - 'createdAt', + 'preferred_language', + 'organization_id', + 'roles', + 'meta', + 'created_at', + 'updated_at', + 'deleted_at', + 'organization', + 'user_roles', ], - type: 'object', }, }, required: ['access_token', 'refresh_token', 'user'], + }, + meta: { type: 'object', + properties: { + formsVersion: { + type: 'array', + items: {}, + }, + correlation: { + type: 'string', + }, + }, + required: ['formsVersion', 'correlation'], }, }, required: ['responseCode', 'message', 'result', 'meta'], @@ -103,7 +202,6 @@ const createProfileSchema = { commonBody.properties.result.properties.user.properties['lastLoggedInAt'] = { type: 'string', } - const loginSchema = { type: 'object', ...commonBody, diff --git a/src/integration-test/commonTests.js b/src/integration-test/commonTests.js index 67d79f862..6d11172cb 100644 --- a/src/integration-test/commonTests.js +++ b/src/integration-test/commonTests.js @@ -31,7 +31,7 @@ const logIn = async () => { }) //console.log(res.body) - if (res.body.result.access_token && res.body.result.user._id) { + if (res.body.result.access_token && res.body.result.user.id) { defaultHeaders = { 'X-auth-token': 'bearer ' + res.body.result.access_token, Connection: 'keep-alive', @@ -42,9 +42,10 @@ const logIn = async () => { return { token: res.body.result.access_token, refreshToken: res.body.result.refresh_token, - userId: res.body.result.user._id, + userId: res.body.result.user.id, email: email, password: password, + roles: res.body.result.user.user_roles, } } else { console.error('Error while getting access token') @@ -54,6 +55,179 @@ const logIn = async () => { console.error(error) } } +const mentorLogIn = async () => { + try { + var waitOn = require('wait-on') + var opts = { + resources: [baseURL], + delay: 1000, // initial delay in ms, default 0 + interval: 500, // poll interval in ms, default 250ms + timeout: 30000, + } + await waitOn(opts) + let email = 'nevil' + crypto.randomBytes(5).toString('hex') + '@tunerlabs.com' + let password = faker.internet.password() + let res = await request.post('/user/v1/account/create').send({ + name: 'Nevil', + email: email, + password: password, + isAMentor: true, + secretCode: 'secret-code', + }) + res = await request.post('/user/v1/account/login').send({ + email: email, + password: password, + }) + + if (res.body.result.access_token && res.body.result.user.id) { + defaultHeaders = { + 'X-auth-token': 'bearer ' + res.body.result.access_token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + } + global.request = defaults(supertest(baseURL)) + global.request.set(defaultHeaders) + global.userId = res.body.result.user.id + return { + token: res.body.result.access_token, + refreshToken: res.body.result.refresh_token, + userId: res.body.result.user.id, + email: email, + password: password, + } + } else { + console.error('Error while getting access token') + return false + } + } catch (error) { + console.error(error) + } +} +const adminLogIn = async () => { + try { + var waitOn = require('wait-on') + var opts = { + resources: [baseURL], + delay: 1000, // initial delay in ms, default 0 + interval: 500, // poll interval in ms, default 250ms + timeout: 30000, + } + await waitOn(opts) + let email = 'nevil' + crypto.randomBytes(5).toString('hex') + '@admin.com' + let password = faker.internet.password() + let res = await request + .post('/user/v1/admin/create') + .set({ + internal_access_token: 'internal_access_token', + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + name: 'Nevil', + email: email, + password: password, + secret_code: 'W5bF7gesuS0xsNWmpsKy', + }) + res = await request.post('/user/v1/account/login').send({ + email: email, + password: password, + }) + + if (res.body.result.access_token && res.body.result.user.id) { + defaultHeaders = { + 'X-auth-token': 'bearer ' + res.body.result.access_token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + } + global.request = defaults(supertest(baseURL)) + global.request.set(defaultHeaders) + global.userId = res.body.result.user.id + return { + token: res.body.result.access_token, + refreshToken: res.body.result.refresh_token, + userId: res.body.result.user.id, + email: email, + password: password, + organization_id: res.body.result.user.organization_id, + } + } else { + console.error('Error while getting access token') + return false + } + } catch (error) { + console.error(error) + } +} + +const orgAdminLogIn = async () => { + try { + var waitOn = require('wait-on') + var opts = { + resources: [baseURL], + delay: 1000, // initial delay in ms, default 0 + interval: 500, // poll interval in ms, default 250ms + timeout: 30000, + } + await waitOn(opts) + let email = 'nevil' + crypto.randomBytes(5).toString('hex') + '@admin.com' + let password = faker.internet.password() + let res = await request + .post('/user/v1/admin/create') + .set({ + internal_access_token: 'internal_access_token', + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + name: 'Nevil', + email: email, + password: password, + secret_code: 'W5bF7gesuS0xsNWmpsKy', + }) + res = await request.post('/user/v1/admin/login').send({ + email: email, + password: password, + }) + res = await request + .post('/user/v1/admin/addOrgAdmin') + .set({ + 'X-auth-token': 'bearer ' + res.body.result.access_token, + }) + .send({ + email: email, + organization_id: 1, + }) + res = await request.post('/user/v1/account/login').send({ + email: email, + password: password, + }) + + if (res.body.result.access_token && res.body.result.user.id) { + defaultHeaders = { + 'X-auth-token': 'bearer ' + res.body.result.access_token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + } + global.request = defaults(supertest(baseURL)) + global.request.set(defaultHeaders) + global.userId = res.body.result.user.id + return { + token: res.body.result.access_token, + refreshToken: res.body.result.refresh_token, + userId: res.body.result.user.id, + email: email, + password: password, + organization_id: res.body.result.user.organization_id, + } + } else { + console.error('Error while getting access token') + return false + } + } catch (error) { + console.error(error) + } +} + function logError(res) { let successCodes = [200, 201, 202] if (!successCodes.includes(res.statusCode)) { @@ -64,4 +238,7 @@ module.exports = { request, logIn, //-- export if token is generated logError, + mentorLogIn, + adminLogIn, + orgAdminLogIn, } diff --git a/src/integration-test/form/form.spec.js b/src/integration-test/form/form.spec.js index 70e40e53a..023f687c5 100644 --- a/src/integration-test/form/form.spec.js +++ b/src/integration-test/form/form.spec.js @@ -5,43 +5,53 @@ * Description : Integration test for form controllers. */ -const { request, logIn, logError } = require('@commonTests') const { formCreateSchema, formReadSchema, formUpdateSchema } = require('./responseSchema') -const { insertForm, formBody } = require('./formData') +const { request, adminLogIn, logIn, logError } = require('@commonTests') +const { insertForm, formBody, insertMentor } = require('./formData') const { faker } = require('@faker-js/faker') describe('user/v1/form', function () { + let type = faker.random.alpha(5) beforeAll(async () => { - await logIn() + adminDetails = await adminLogIn() + UserDetails = await logIn() }) + it('/create', async () => { - let res = await request.post('/user/v1/form/create').send({ - type: faker.random.alpha(5), - ...formBody, - }) + let res = await request + .post('/user/v1/form/create') + .set('X-auth-token', 'bearer ' + adminDetails.token) + .send({ + type: type, + ...formBody, + }) logError(res) expect(res.statusCode).toBe(201) expect(res.body).toMatchSchema(formCreateSchema) }) it('/read', async () => { let type = await insertForm() - let res = await request.patch('/user/v1/form/read').send({ - type: type, - subType: 'profileForm', - action: 'profileFields', - ver: '1.0', - templateName: 'defaultTemplate', - }) + let res = await request + .post('/user/v1/form/read') + .set('X-auth-token', 'bearer ' + UserDetails.token) + .send({ + type: 'profile', + sub_type: 'profileForm', + }) logError(res) expect(res.statusCode).toBe(200) expect(res.body).toMatchSchema(formReadSchema) }) it('/update', async () => { - let type = await insertForm() - let res = await request.post('/user/v1/form/update').send({ - type: type, - ...formBody, - }) + // let type = await insertForm() + // console.log(type) + let res = await request + .post('/user/v1/form/update') + .set('X-auth-token', 'bearer ' + adminDetails.token) + .send({ + type: type, + ...formBody, + }) logError(res) expect(res.statusCode).toBe(202) expect(res.body).toMatchSchema(formUpdateSchema) diff --git a/src/integration-test/form/formData.js b/src/integration-test/form/formData.js index 20eddb636..8e7d67fe0 100644 --- a/src/integration-test/form/formData.js +++ b/src/integration-test/form/formData.js @@ -1,38 +1,315 @@ -const formsData = require('@db/forms/queries') +const formsData = require('@database/queries/form') const { faker } = require('@faker-js/faker') +const usersData = require('@database/queries/users') + let bodyData let formBody = { - subType: 'profileForm', - action: 'profileFields', - ver: '1.0', + sub_type: 'profileForm', data: { - templateName: 'defaultTemplate', + template_name: 'defaultTemplate', fields: { controls: [ { name: 'name', - label: 'name', - value: '', - class: 'ion-margin', + label: 'Your name', + value: 'mentor', + class: 'ion-no-margin', + type: 'text', + position: 'floating', + placeHolder: 'Please enter your full name', + errorMessage: 'This field can only contain alphabets', + showValidationError: true, + validators: { + required: true, + pattern: '^[^0-9!@#%$&()\\-`.+,/"]*$', + }, + options: [], + }, + { + name: 'location', + label: 'Select your location', + value: [ + { + value: 'AP', + label: 'Andhra Pradesh', + }, + ], + class: 'ion-no-margin', + type: 'select', + position: 'floating', + errorLabel: 'Location', + errorMessage: 'Please select your location', + validators: { + required: true, + }, + options: [ + { + value: 'AP', + label: 'Andhra Pradesh', + }, + { + value: 'AR', + label: 'Arunachal Pradesh', + }, + { + value: 'As', + label: 'Assam', + }, + { + value: 'BR', + label: 'Bihar', + }, + { + value: 'CG', + label: 'Chhattisgarh', + }, + { + value: 'GA', + label: 'Goa', + }, + { + value: 'GJ', + label: 'Gujarat', + }, + { + value: 'HR', + label: 'Haryana', + }, + { + value: 'HP', + label: 'Himachal Pradesh', + }, + { + value: 'JH', + label: 'Jharkhand', + }, + { + value: 'KN', + label: 'Karnataka', + }, + { + value: 'KL', + label: 'Kerala', + }, + { + value: 'MP', + label: 'Madhya Pradesh', + }, + { + value: 'MH', + label: 'Maharashtra', + }, + { + value: 'MN', + label: 'Manipur', + }, + { + value: 'ML', + label: 'Meghalaya', + }, + { + value: 'MZ', + label: 'Mizoram', + }, + { + value: 'NL', + label: 'Nagaland', + }, + { + value: 'OD', + label: 'Odisha', + }, + { + value: 'PB', + label: 'Punjab', + }, + { + value: 'RJ', + label: 'Rajasthan', + }, + { + value: 'SK', + label: 'Sikkim', + }, + { + value: 'TN', + label: 'Tamil Nadu', + }, + { + value: 'TS', + label: 'Telangana', + }, + { + value: 'TR', + label: 'Tripura', + }, + { + value: 'UP', + label: 'Uttar Pradesh', + }, + { + value: 'UK', + label: 'Uttarakhand', + }, + { + value: 'WB', + label: 'West Bengal', + }, + ], + }, + { + name: 'designation', + label: 'Your role', + class: 'ion-no-margin', + value: [ + { + value: 'teacher', + label: 'Teacher', + }, + { + value: 'HM', + label: 'Head master', + }, + ], + type: 'chip', + position: '', + disabled: false, + showSelectAll: true, + errorLabel: 'Designation', + errorMessage: 'Enter your role', + addNewPopupHeader: 'Add a new role', + validators: { + required: true, + }, + showAddOption: true, + options: [ + { + value: 'teacher', + label: 'Teacher', + }, + { + value: 'HM', + label: 'Head master', + }, + { + value: 'BEO', + label: 'Block education officer', + }, + { + value: 'DEO', + label: 'District education officer', + }, + ], + }, + { + name: 'experience', + label: 'Your experience in years', + value: '10', + class: 'ion-no-margin', + type: 'text', + position: 'floating', + placeHolder: 'Ex. 5 years', + errorMessage: 'Enter your experience in years', + isNumberOnly: true, + validators: { + required: true, + maxLength: 2, + }, + options: [], + }, + { + name: 'about', + label: 'Tell us about yourself', + value: 'mentor', + class: 'ion-no-margin', + type: 'textarea', + position: 'floating', + errorMessage: 'This field cannot be empty', + placeHolder: 'Please use only 150 character', + validators: { + required: true, + maxLength: 150, + }, + options: [], + }, + { + name: 'areasOfExpertise', + label: 'Your expertise', + class: 'ion-no-margin', + value: [ + { + value: 'eduLdship', + label: 'Educational leadership', + }, + ], + type: 'chip', + position: '', + disabled: false, + showSelectAll: true, + errorLabel: 'Expertise', + errorMessage: 'Enter your expertise', + addNewPopupHeader: 'Add your expertise', + validators: { + required: true, + }, + showAddOption: true, + options: [ + { + value: 'eduLdship', + label: 'Educational leadership', + }, + { + value: 'schoolProcess', + label: 'School process', + }, + ], + }, + { + name: 'educationQualification', + label: 'Education qualification', + value: 'mentor', + class: 'ion-no-margin', type: 'text', position: 'floating', + errorLabel: 'Education qualification', + errorMessage: 'Enter education qualification', + placeHolder: 'Ex. BA, B.ED', validators: { required: true, - minLength: 10, }, + options: [], }, { - name: 'roles', - label: 'Select your role', - value: '', - class: 'ion-margin', + name: 'languages', + label: 'Languages', + class: 'ion-no-margin', + value: [ + { + value: 'english', + label: 'English', + }, + ], type: 'chip', position: '', disabled: false, showSelectAll: true, + errorLabel: 'Medium', + errorMessage: 'Enter language', + addNewPopupHeader: 'Add new language', validators: { required: true, }, + showAddOption: true, + options: [ + { + value: 'english', + label: 'English', + }, + { + value: 'hindi', + label: 'Hindi', + }, + ], }, ], }, @@ -47,7 +324,7 @@ const insertForm = async () => { ...formBody, } - await formsData.createForm(bodyData) + await formsData.create(bodyData) return type } catch (error) { diff --git a/src/integration-test/form/responseSchema.js b/src/integration-test/form/responseSchema.js index 134c92e63..33ea95024 100644 --- a/src/integration-test/form/responseSchema.js +++ b/src/integration-test/form/responseSchema.js @@ -20,21 +20,18 @@ const formCreateSchema = { const formReadSchema = { type: 'object', properties: { - responseCode: { - type: 'string', - }, - message: { - type: 'string', - }, + responseCode: { type: 'string' }, + message: { type: 'string' }, result: { type: 'object', properties: { + id: { type: 'integer' }, + type: { type: 'string' }, + sub_type: { type: 'string' }, data: { type: 'object', properties: { - templateName: { - type: 'string', - }, + template_name: { type: 'string' }, fields: { type: 'object', properties: { @@ -44,36 +41,24 @@ const formReadSchema = { { type: 'object', properties: { - name: { - type: 'string', - }, - label: { - type: 'string', - }, - value: { - type: 'string', - }, - class: { - type: 'string', - }, - type: { - type: 'string', - }, - position: { - type: 'string', - }, + name: { type: 'string' }, + label: { type: 'string' }, + value: { type: 'string' }, + class: { type: 'string' }, + type: { type: 'string' }, + position: { type: 'string' }, + placeHolder: { type: 'string' }, + errorMessage: { type: 'string' }, + showValidationError: { type: 'boolean' }, validators: { type: 'object', properties: { - required: { - type: 'boolean', - }, - minLength: { - type: 'integer', - }, + required: { type: 'boolean' }, + pattern: { type: 'string' }, }, - required: ['required', 'minLength'], + required: ['required', 'pattern'], }, + options: { type: 'array', items: {} }, }, required: [ 'name', @@ -82,45 +67,64 @@ const formReadSchema = { 'class', 'type', 'position', + 'placeHolder', + 'errorMessage', + 'showValidationError', 'validators', + 'options', ], }, { type: 'object', properties: { - name: { - type: 'string', - }, - label: { - type: 'string', - }, + name: { type: 'string' }, + label: { type: 'string' }, value: { - type: 'string', - }, - class: { - type: 'string', - }, - type: { - type: 'string', - }, - position: { - type: 'string', - }, - disabled: { - type: 'boolean', - }, - showSelectAll: { - type: 'boolean', + type: 'array', + items: [ + { + type: 'object', + properties: { + value: { type: 'string' }, + label: { type: 'string' }, + }, + required: ['value', 'label'], + }, + ], }, + class: { type: 'string' }, + type: { type: 'string' }, + position: { type: 'string' }, + errorLabel: { type: 'string' }, + errorMessage: { type: 'string' }, validators: { type: 'object', properties: { - required: { - type: 'boolean', - }, + required: { type: 'boolean' }, }, required: ['required'], }, + options: { + type: 'array', + items: [ + { + type: 'object', + properties: { + value: { type: 'string' }, + label: { type: 'string' }, + }, + required: ['value', 'label'], + }, + { + type: 'object', + properties: { + value: { type: 'string' }, + label: { type: 'string' }, + }, + required: ['value', 'label'], + }, + ], + }, }, required: [ 'name', @@ -129,49 +133,62 @@ const formReadSchema = { 'class', 'type', 'position', - 'disabled', - 'showSelectAll', + 'errorLabel', + 'errorMessage', 'validators', + 'options', ], }, ], }, }, - required: ['controls'], }, }, - required: ['templateName', 'fields'], - }, - _id: { - type: 'string', - }, - type: { - type: 'string', - }, - subType: { - type: 'string', - }, - action: { - type: 'string', - }, - updatedAt: { - type: 'string', - }, - createdAt: { - type: 'string', - }, - __v: { - type: 'integer', + required: ['template_name', 'fields'], }, + version: { type: 'integer' }, + organization_id: { type: 'integer' }, + created_at: { type: 'string' }, + updated_at: { type: 'string' }, + deleted_at: { type: 'null' }, }, - required: ['data', '_id', 'type', 'subType', 'action', 'updatedAt', 'createdAt', '__v'], + required: [ + 'id', + 'type', + 'sub_type', + 'data', + 'version', + 'organization_id', + 'created_at', + 'updated_at', + 'deleted_at', + ], }, - meta: { - type: 'object', + }, + meta: { + type: 'object', + properties: { + formsVersion: { + type: 'array', + items: [ + { + type: 'object', + properties: { + id: { type: 'integer' }, + type: { type: 'string' }, + version: { type: 'integer' }, + }, + required: ['id', 'type', 'version'], + }, + ], + }, + correlation: { type: 'string' }, }, + required: ['formsVersion', 'correlation'], }, required: ['responseCode', 'message', 'result', 'meta'], } + const formUpdateSchema = { type: 'object', properties: { diff --git a/src/integration-test/mentor/mentor.spec.js b/src/integration-test/mentor/mentor.spec.js index 493dda3be..82d996187 100644 --- a/src/integration-test/mentor/mentor.spec.js +++ b/src/integration-test/mentor/mentor.spec.js @@ -5,21 +5,25 @@ * Description : Integration test for mentor controllers. */ -const { request, logIn, logError } = require('@commonTests') +const { request, mentorLogIn, logError } = require('@commonTests') const { listMentorsSchema } = require('./responseSchema') -const { insertMentor } = require('./mentorData') describe('user/v1/mentors', function () { let userDetails beforeAll(async () => { - userDetails = await logIn() + userDetails = await mentorLogIn() }) it('/list', async () => { - await insertMentor() - let res = await request.get('/user/v1/mentors/list') + let res = await request.post('/user/v1/mentors/list').set({ + 'X-auth-token': 'bearer ' + userDetails.token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) logError(res) expect(res.statusCode).toBe(200) expect(res.body).toMatchSchema(listMentorsSchema) }) }) + +// mentor/list role permissions are not present , so integrations doesn't work. diff --git a/src/integration-test/mentor/mentorData.js b/src/integration-test/mentor/mentorData.js index 20c4b4c08..e972ae234 100644 --- a/src/integration-test/mentor/mentorData.js +++ b/src/integration-test/mentor/mentorData.js @@ -1,16 +1,18 @@ -const usersData = require('@db/users/queries') +const usersData = require('@database/queries/users') const { faker } = require('@faker-js/faker') let bodyData const insertMentor = async () => { try { bodyData = { name: 'Nevil (Mentor)', - email: { address: faker.internet.email(), verified: false }, + email: faker.internet.email(), password: faker.internet.password(), isAMentor: true, - secretCode: 'secret-code', + secret_code: 'secret-code', + roles: 2, + organization_id: 1, } - await usersData.createUser(bodyData) + await usersData.create(bodyData) } catch (error) { console.error(error) } diff --git a/src/integration-test/org-admin/orgAdminData.js b/src/integration-test/org-admin/orgAdminData.js new file mode 100644 index 000000000..287204ee5 --- /dev/null +++ b/src/integration-test/org-admin/orgAdminData.js @@ -0,0 +1,35 @@ +const { request, orgAdminLogIn, logError } = require('@commonTests') +const { faker } = require('@faker-js/faker') + +const insertRequest = async () => { + try { + userDetails = await orgAdminLogIn() + + let res = await request + .post('/user/v1/organization/requestOrgRole') + .set({ + 'X-auth-token': 'bearer ' + userDetails.token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + role: 5, + organization_id: 1, + form_data: { + designation: 'Manager', + experience: '5 years', + area_of_expertise: ['Finance', 'Management'], + about: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', + }, + }) + + logError(res) + return [res.body, userDetails.token] + } catch (error) { + console.error(error) + } +} + +module.exports = { + insertRequest, +} diff --git a/src/integration-test/org-admin/orgadmin.spec.js b/src/integration-test/org-admin/orgadmin.spec.js new file mode 100644 index 000000000..53f2fd681 --- /dev/null +++ b/src/integration-test/org-admin/orgadmin.spec.js @@ -0,0 +1,144 @@ +const { request, logError, orgAdminLogIn } = require('@commonTests') +let responseSchema = require('./responseSchema') +const { faker } = require('@faker-js/faker') +const { insertRequest } = require('./orgAdminData') +//const { requestDetails } = require('@database/queries/orgRoleRequest') + +describe('/user/v1/org-admin', function () { + let userDetails + let randomFilePath + + beforeAll(async () => { + userDetails = await orgAdminLogIn() + const generateRandomFilePath = () => { + const randomFileName = faker.system.fileName() + return `${randomFileName}.csv` + } + randomFilePath = generateRandomFilePath() + }) + + it('/bulkUserCreate', async () => { + let res = await request + .post('/user/v1/org-admin/bulkUserCreate') + .set({ + 'X-auth-token': 'bearer ' + userDetails.token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + file_path: randomFilePath, + }) + + logError(res) + expect(res.statusCode).toBe(200) + expect(res.body).toMatchSchema(responseSchema.bulkUserCreateSchema) + }) + + it('/getBulkInvitesFilesList', async () => { + let res = await request + .get('/user/v1/org-admin/getBulkInvitesFilesList') + .set({ + 'X-auth-token': 'bearer ' + userDetails.token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .query({ page: 1, limit: 10, status: 'REQUESTED' }) + + logError(res) + expect(res.statusCode).toBe(200) + expect(res.body).toMatchSchema(responseSchema.getBulkInvitesFilesListSchema) + }) + + it('/getRequestDetails', async () => { + let requestDetails = await insertRequest() + //console.log(requestDetails[0].meta.formsVersion) + let res = await request.get('/user/v1/org-admin/getRequestDetails/' + requestDetails[0].result.id).set({ + 'X-auth-token': 'bearer ' + requestDetails[1], + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + + logError(res) + expect(res.statusCode).toBe(200) + expect(res.body).toMatchSchema(responseSchema.getRequestDetailsSchema) + }) + + it('/getRequests', async () => { + let requestDetails = await insertRequest() + let res = await request + .post('/user/v1/org-admin/getRequests') + .set({ + 'X-auth-token': 'bearer ' + requestDetails[1], + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ filters: { role: requestDetails[0].result.role, status: ['REQUESTED'] } }) + + logError(res) + expect(res.statusCode).toBe(200) + expect(res.body).toMatchSchema(responseSchema.getRequestsSchema) + }) + + it('/updateRequestStatus', async () => { + let requestDetails = await insertRequest() + let res = await request + .post('/user/v1/org-admin/updateRequestStatus') + .set({ + 'X-auth-token': 'bearer ' + requestDetails[1], + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + request_id: requestDetails[0].result.id, + comments: ['All uploaded documents verified', 'Profile information verified'], + status: 'APPROVED', + }) + + logError(res) + expect(res.statusCode).toBe(200) + expect(res.body).toMatchSchema(responseSchema.updateRequestStatusSchema) + }) + + it('/deactivateUser', async () => { + let requestDetails = await insertRequest() + console.log(requestDetails) + let res = await request + .post('/user/v1/org-admin/deactivateUser') + .set({ + 'X-auth-token': 'bearer ' + requestDetails[1], + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + id: [requestDetails[0].result.requester_id], + }) + + logError(res) + expect(res.statusCode).toBe(200) + console.log(res.body) + expect(res.body).toMatchSchema(responseSchema.deactivateUserSchema) + }) + + // need to get understanding for below api , where it is there for user service + + // it('/inheritEntityType', async () => { + // let requestDetails = await insertRequest() + // console.log(requestDetails[0].result.meta) + // let res = await request + // .post('/user/v1/org-admin/inheritEntityType') + // .set({ + // 'X-auth-token': 'bearer ' + requestDetails[1], + // Connection: 'keep-alive', + // 'Content-Type': 'application/json', + // }) + // .send({ + // entity_type_value: 'categories', + // target_entity_type_label: 'training' + // }) + + // logError(res) + // expect(res.statusCode).toBe(200) + // console.log(res.body) + // expect(res.body).toMatchSchema(responseSchema.deactivateUserSchema) + // }) +}) diff --git a/src/integration-test/org-admin/responseSchema.js b/src/integration-test/org-admin/responseSchema.js new file mode 100644 index 000000000..34d60fd02 --- /dev/null +++ b/src/integration-test/org-admin/responseSchema.js @@ -0,0 +1,1112 @@ +const bulkUserCreateSchema = { + type: 'object', + properties: { + responseCode: { + type: 'string', + }, + message: { + type: 'string', + }, + result: { + type: 'object', + properties: { + status: { + type: 'string', + }, + name: { + type: 'string', + }, + input_path: { + type: 'string', + }, + type: { + type: 'string', + }, + organization_id: { + type: 'integer', + }, + created_by: { + type: 'integer', + }, + updated_at: { + type: 'string', + }, + created_at: { + type: 'string', + }, + id: { + type: 'integer', + }, + output_path: { + type: 'null', + }, + updated_by: { + type: 'null', + }, + deleted_at: { + type: 'null', + }, + }, + required: [ + 'status', + 'name', + 'input_path', + 'type', + 'organization_id', + 'created_by', + 'updated_at', + 'created_at', + 'id', + ], + }, + meta: { + type: 'object', + properties: { + formsVersion: { + type: 'array', + items: {}, + }, + correlation: { + type: 'string', + }, + }, + required: ['formsVersion', 'correlation'], + }, + }, + required: ['responseCode', 'message', 'result', 'meta'], +} + +const getBulkInvitesFilesListSchema = { + type: 'object', + properties: { + responseCode: { + type: 'string', + }, + message: { + type: 'string', + }, + result: { + type: 'object', + properties: { + count: { + type: 'integer', + }, + data: { + type: 'array', + items: {}, + }, + }, + required: ['count', 'data'], + }, + meta: { + type: 'object', + properties: { + formsVersion: { + type: 'array', + items: [ + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + ], + }, + correlation: { + type: 'string', + }, + }, + required: ['formsVersion', 'correlation'], + }, + }, + required: ['responseCode', 'message', 'result', 'meta'], +} + +const getRequestsSchema = { + type: 'object', + properties: { + responseCode: { + type: 'string', + }, + message: { + type: 'string', + }, + result: { + type: 'object', + properties: { + count: { + type: 'integer', + }, + data: { + type: 'array', + items: [ + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + requester_id: { + type: 'integer', + }, + role: { + type: 'integer', + }, + status: { + type: 'string', + }, + organization_id: { + type: 'integer', + }, + handled_by: { + type: 'null', + }, + meta: { + type: 'object', + properties: { + designation: { + type: 'string', + }, + experience: { + type: 'string', + }, + area_of_expertise: { + type: 'array', + items: [ + { + type: 'string', + }, + { + type: 'string', + }, + ], + }, + about: { + type: 'string', + }, + }, + required: ['designation', 'experience', 'area_of_expertise', 'about'], + }, + comments: { + type: 'null', + }, + requester: { + type: 'object', + properties: { + id: { + type: 'integer', + }, + name: { + type: 'string', + }, + }, + required: ['id', 'name'], + }, + }, + required: [ + 'id', + 'requester_id', + 'role', + 'status', + 'organization_id', + 'handled_by', + 'meta', + 'comments', + 'requester', + ], + }, + ], + }, + }, + required: ['count', 'data'], + }, + meta: { + type: 'object', + properties: { + formsVersion: { + type: 'array', + items: [ + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + ], + }, + correlation: { + type: 'string', + }, + }, + required: ['formsVersion', 'correlation'], + }, + }, + required: ['responseCode', 'message', 'result', 'meta'], +} + +const getRequestDetailsSchema = { + type: 'object', + properties: { + responseCode: { + type: 'string', + }, + message: { + type: 'string', + }, + result: { + type: 'object', + properties: { + id: { + type: 'integer', + }, + requester_id: { + type: 'integer', + }, + role: { + type: 'integer', + }, + status: { + type: 'string', + }, + organization_id: { + type: 'integer', + }, + handled_by: { + type: 'null', + }, + meta: { + type: 'object', + properties: { + designation: { + type: 'string', + }, + experience: { + type: 'string', + }, + area_of_expertise: { + type: 'array', + items: [ + { + type: 'string', + }, + { + type: 'string', + }, + ], + }, + about: { + type: 'string', + }, + }, + required: ['designation', 'experience', 'area_of_expertise', 'about'], + }, + comments: { + type: 'null', + }, + requester: { + type: 'object', + properties: { + id: { + type: 'integer', + }, + name: { + type: 'string', + }, + }, + required: ['id', 'name'], + }, + handler: { + type: 'null', + }, + }, + required: [ + 'id', + 'requester_id', + 'role', + 'status', + 'organization_id', + 'handled_by', + 'meta', + 'comments', + 'requester', + 'handler', + ], + }, + meta: { + type: 'object', + properties: { + formsVersion: { + type: 'array', + items: [ + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + ], + }, + correlation: { + type: 'string', + }, + }, + required: ['formsVersion', 'correlation'], + }, + }, + required: ['responseCode', 'message', 'result', 'meta'], +} + +const updateRequestStatusSchema = { + type: 'object', + properties: { + responseCode: { + type: 'string', + }, + message: { + type: 'string', + }, + result: { + type: 'object', + properties: { + id: { + type: 'integer', + }, + requester_id: { + type: 'integer', + }, + role: { + type: 'integer', + }, + status: { + type: 'string', + }, + organization_id: { + type: 'integer', + }, + handled_by: { + type: 'integer', + }, + meta: { + type: 'object', + properties: { + designation: { + type: 'string', + }, + experience: { + type: 'string', + }, + area_of_expertise: { + type: 'array', + items: [ + { + type: 'string', + }, + { + type: 'string', + }, + ], + }, + about: { + type: 'string', + }, + }, + required: ['designation', 'experience', 'area_of_expertise', 'about'], + }, + comments: { + type: 'array', + items: [ + { + type: 'string', + }, + { + type: 'string', + }, + ], + }, + created_at: { + type: 'string', + }, + updated_at: { + type: 'string', + }, + deleted_at: { + type: 'null', + }, + requester: { + type: 'object', + properties: { + id: { + type: 'integer', + }, + name: { + type: 'string', + }, + }, + required: ['id', 'name'], + }, + handler: { + type: 'object', + properties: { + id: { + type: 'integer', + }, + name: { + type: 'string', + }, + }, + required: ['id', 'name'], + }, + }, + required: [ + 'id', + 'requester_id', + 'role', + 'status', + 'organization_id', + 'handled_by', + 'meta', + 'comments', + 'created_at', + 'updated_at', + 'deleted_at', + 'requester', + 'handler', + ], + }, + meta: { + type: 'object', + properties: { + formsVersion: { + type: 'array', + items: [ + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { + id: { + type: 'integer', + }, + type: { + type: 'string', + }, + version: { + type: 'integer', + }, + }, + required: ['id', 'type', 'version'], + }, + ], + }, + correlation: { + type: 'string', + }, + }, + required: ['formsVersion', 'correlation'], + }, + }, + required: ['responseCode', 'message', 'result', 'meta'], +} +const deactivateUserSchema = { + type: 'object', + properties: { + responseCode: { + type: 'string', + }, + message: { + type: 'string', + }, + result: { + type: 'array', + items: {}, + }, + meta: { + type: 'object', + properties: { + formsVersion: { + type: 'array', + items: {}, + }, + correlation: { + type: 'string', + }, + }, + required: ['formsVersion', 'correlation'], + }, + }, + required: ['responseCode', 'message', 'result', 'meta'], +} + +module.exports = { + bulkUserCreateSchema, + getBulkInvitesFilesListSchema, + getRequestDetailsSchema, + getRequestsSchema, + updateRequestStatusSchema, + deactivateUserSchema, +} diff --git a/src/integration-test/organization/organization.spec.js b/src/integration-test/organization/organization.spec.js new file mode 100644 index 000000000..1d5c1a682 --- /dev/null +++ b/src/integration-test/organization/organization.spec.js @@ -0,0 +1,70 @@ +const { request, logError, orgAdminLogIn, adminLogIn } = require('@commonTests') +let responseSchema = require('./responseSchema') +const { faker } = require('@faker-js/faker') +const { insertOrganization } = require('./organizationData') +//const { requestDetails } = require('@database/queries/orgRoleRequest') + +describe('/user/v1/organization', function () { + let userDetails + beforeAll(async () => { + userDetails = await orgAdminLogIn() + adminDetails = await adminLogIn() + insertOrg = await insertOrganization() + }) + + it('/create', async () => { + let res = await request + .post('/user/v1/organization/create') + .set({ + 'X-auth-token': 'bearer ' + userDetails.token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + name: faker.random.alpha(5), + code: faker.random.alpha(5), + description: 'testing org', + domains: ['cc.com'], + }) + + logError(res) + expect(res.statusCode).toBe(201) + expect(res.body).toMatchSchema(responseSchema.createSchema) + }) + + it('/read', async () => { + let res = await request + .get('/user/v1/organization/read') + .set({ + internal_access_token: 'internal_access_token', + // Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .query({ organisation_id: 1, organisation_code: 'default' }) + + logError(res) + expect(res.statusCode).toBe(200) + expect(res.body).toMatchSchema(responseSchema.readSchema) + }) + + it('/update', async () => { + console.log(insertOrg[0].result.id) + let res = await request + .patch('/user/v1/organization/update/' + insertOrg[0].result.id) + .set({ + 'X-auth-token': 'bearer ' + insertOrg[1], + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + name: faker.random.alpha(5), + description: 'testing org', + related_orgs: [3, 4], + }) + + logError(res) + expect(res.statusCode).toBe(202) + console.log(res.body) + expect(res.body).toMatchSchema(responseSchema.updateSchema) + }) +}) diff --git a/src/integration-test/organization/organizationData.js b/src/integration-test/organization/organizationData.js new file mode 100644 index 000000000..7ce1fd9c6 --- /dev/null +++ b/src/integration-test/organization/organizationData.js @@ -0,0 +1,31 @@ +const { request, orgAdminLogIn, logError, adminLogIn } = require('@commonTests') +const { faker } = require('@faker-js/faker') + +const insertOrganization = async () => { + try { + userDetails = await adminLogIn() + + let res = await request + .post('/user/v1/organization/create') + .set({ + 'X-auth-token': 'bearer ' + userDetails.token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + name: faker.random.alpha(5), + code: faker.random.alpha(5), + description: 'testing org', + domains: ['cc.com'], + }) + + logError(res) + return [res.body, userDetails.token] + } catch (error) { + console.error(error) + } +} + +module.exports = { + insertOrganization, +} diff --git a/src/integration-test/organization/responseSchema.js b/src/integration-test/organization/responseSchema.js new file mode 100644 index 000000000..83e90606e --- /dev/null +++ b/src/integration-test/organization/responseSchema.js @@ -0,0 +1,188 @@ +const createSchema = { + type: 'object', + properties: { + responseCode: { + type: 'string', + }, + message: { + type: 'string', + }, + result: { + type: 'object', + properties: { + status: { + type: 'string', + }, + id: { + type: 'integer', + }, + name: { + type: 'string', + }, + code: { + type: 'string', + }, + description: { + type: 'string', + }, + created_by: { + type: 'integer', + }, + updated_at: { + type: 'string', + }, + created_at: { + type: 'string', + }, + org_admin: { + type: 'null', + }, + parent_id: { + type: 'null', + }, + related_orgs: { + type: 'null', + }, + in_domain_visibility: { + type: 'null', + }, + updated_by: { + type: 'null', + }, + deleted_at: { + type: 'null', + }, + }, + required: [ + 'status', + 'id', + 'name', + 'code', + 'description', + 'created_by', + 'updated_at', + 'created_at', + 'org_admin', + 'parent_id', + 'related_orgs', + 'in_domain_visibility', + 'updated_by', + 'deleted_at', + ], + }, + meta: { + type: 'object', + properties: { + formsVersion: { + type: 'array', + items: {}, + }, + correlation: { + type: 'string', + }, + }, + required: ['formsVersion', 'correlation'], + }, + }, + required: ['responseCode', 'message', 'result', 'meta'], +} + +const readSchema = { + type: 'object', + properties: { + responseCode: { type: 'string' }, + message: { type: 'string' }, + result: { + type: 'object', + properties: { + id: { type: 'integer' }, + name: { type: 'string' }, + code: { type: 'string' }, + description: { type: 'string' }, + status: { type: 'string' }, + org_admin: { + type: 'array', + items: { type: 'integer' }, + }, + parent_id: { type: ['null', 'integer'] }, + related_orgs: { type: ['null', 'array'] }, + in_domain_visibility: { type: ['null', 'array'] }, + created_by: { type: ['null', 'integer'] }, + updated_by: { type: 'integer' }, + created_at: { type: 'string' }, + updated_at: { type: 'string' }, + deleted_at: { type: ['null', 'string'] }, + }, + required: [ + 'id', + 'name', + 'code', + 'description', + 'status', + 'org_admin', + 'parent_id', + 'related_orgs', + 'in_domain_visibility', + 'created_by', + 'updated_by', + 'created_at', + 'updated_at', + 'deleted_at', + ], + }, + meta: { + type: 'object', + properties: { + formsVersion: { + type: 'array', + items: { + type: 'object', + properties: { + id: { type: 'integer' }, + type: { type: 'string' }, + version: { type: 'integer' }, + }, + required: ['id', 'type', 'version'], + }, + }, + correlation: { type: 'string' }, + }, + required: ['formsVersion', 'correlation'], + }, + }, + required: ['responseCode', 'message', 'result', 'meta'], +} + +const updateSchema = { + type: 'object', + properties: { + responseCode: { type: 'string' }, + message: { type: 'string' }, + result: { + type: 'array', + items: {}, + }, + meta: { + type: 'object', + properties: { + formsVersion: { + type: 'array', + items: { + type: 'object', + properties: { + id: { type: 'integer' }, + type: { type: 'string' }, + version: { type: 'integer' }, + }, + required: ['id', 'type', 'version'], + }, + }, + correlation: { type: 'string' }, + }, + required: ['formsVersion', 'correlation'], + }, + }, + required: ['responseCode', 'message', 'result', 'meta'], +} + +module.exports = { createSchema, readSchema, updateSchema } diff --git a/src/integration-test/systemUser/responseSchema.js b/src/integration-test/systemUser/responseSchema.js index 0b35f60ae..a4d4700c9 100644 --- a/src/integration-test/systemUser/responseSchema.js +++ b/src/integration-test/systemUser/responseSchema.js @@ -20,62 +20,296 @@ const createSystemUserSchema = { const loginSchema = { type: 'object', properties: { - responseCode: { - type: 'string', - }, - message: { - type: 'string', - }, + responseCode: { type: 'string' }, + message: { type: 'string' }, result: { type: 'object', properties: { - access_token: { - type: 'string', - }, - refresh_token: { - type: 'string', - }, + access_token: { type: 'string' }, + refresh_token: { type: 'string' }, user: { type: 'object', properties: { - _id: { - type: 'string', + id: { type: 'integer' }, + email: { type: 'string' }, + email_verified: { type: 'string' }, + name: { type: 'string' }, + gender: { type: 'null' }, + location: { type: 'null' }, + about: { type: 'null' }, + share_link: { type: 'null' }, + status: { type: 'string' }, + image: { type: 'null' }, + last_logged_in_at: { type: 'null' }, + has_accepted_terms_and_conditions: { type: 'boolean' }, + refresh_tokens: { type: 'null' }, + languages: { type: 'null' }, + preferred_language: { type: 'string' }, + organization_id: { type: 'integer' }, + roles: { type: 'array', items: [{ type: 'integer' }] }, + custom_entity_text: { type: 'null' }, + meta: { type: 'null' }, + created_at: { type: 'string' }, + updated_at: { type: 'string' }, + deleted_at: { type: 'null' }, + user_roles: { + type: 'array', + items: [ + { + type: 'object', + properties: { + id: { type: 'integer' }, + title: { type: 'string' }, + user_type: { type: 'integer' }, + status: { type: 'string' }, + organization_id: { type: 'integer' }, + visibility: { type: 'string' }, + }, + required: ['id', 'title', 'user_type', 'status', 'organization_id', 'visibility'], + }, + ], + }, + }, + required: [ + 'id', + 'email', + 'email_verified', + 'name', + 'gender', + 'location', + 'about', + 'share_link', + 'status', + 'image', + 'last_logged_in_at', + 'has_accepted_terms_and_conditions', + 'refresh_tokens', + 'languages', + 'preferred_language', + 'organization_id', + 'roles', + 'custom_entity_text', + 'meta', + 'created_at', + 'updated_at', + 'deleted_at', + 'user_roles', + ], + }, + }, + required: ['access_token', 'refresh_token', 'user'], + }, + }, + meta: { + type: 'object', + properties: { + formsVersion: { + type: 'array', + items: [ + { + type: 'object', + properties: { id: { type: 'integer' }, type: { type: 'string' }, version: { type: 'integer' } }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { id: { type: 'integer' }, type: { type: 'string' }, version: { type: 'integer' } }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { id: { type: 'integer' }, type: { type: 'string' }, version: { type: 'integer' } }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { id: { type: 'integer' }, type: { type: 'string' }, version: { type: 'integer' } }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { id: { type: 'integer' }, type: { type: 'string' }, version: { type: 'integer' } }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { id: { type: 'integer' }, type: { type: 'string' }, version: { type: 'integer' } }, + required: ['id', 'type', 'version'], + }, + ], + }, + correlation: { type: 'string' }, + }, + required: ['formsVersion', 'correlation'], + }, + required: ['responseCode', 'message', 'result', 'meta'], +} + +const addOrgAdminSchema = { + type: 'object', + properties: { + responseCode: { type: 'string' }, + message: { type: 'string' }, + result: { + type: 'object', + properties: { + user_id: { type: 'integer' }, + organization_id: { type: 'integer' }, + user_roles: { + type: 'array', + items: [ + { + type: 'object', + properties: { + id: { type: 'integer' }, + title: { type: 'string' }, + user_type: { type: 'integer' }, + status: { type: 'string' }, + organization_id: { type: 'integer' }, + visibility: { type: 'string' }, + }, + required: ['id', 'title', 'user_type', 'status', 'organization_id', 'visibility'], }, - email: { + { type: 'object', properties: { - address: { - type: 'string', - }, - verified: { - type: 'boolean', - }, + id: { type: 'integer' }, + title: { type: 'string' }, + user_type: { type: 'integer' }, + status: { type: 'string' }, + organization_id: { type: 'integer' }, + visibility: { type: 'string' }, + }, + required: ['id', 'title', 'user_type', 'status', 'organization_id', 'visibility'], + }, + ], + }, + }, + required: ['user_id', 'organization_id', 'user_roles'], + }, + }, + meta: { + type: 'object', + properties: { + formsVersion: { + type: 'array', + items: [ + { + type: 'object', + properties: { id: { type: 'integer' }, type: { type: 'string' }, version: { type: 'integer' } }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { id: { type: 'integer' }, type: { type: 'string' }, version: { type: 'integer' } }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { id: { type: 'integer' }, type: { type: 'string' }, version: { type: 'integer' } }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { id: { type: 'integer' }, type: { type: 'string' }, version: { type: 'integer' } }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { id: { type: 'integer' }, type: { type: 'string' }, version: { type: 'integer' } }, + required: ['id', 'type', 'version'], + }, + { + type: 'object', + properties: { id: { type: 'integer' }, type: { type: 'string' }, version: { type: 'integer' } }, + required: ['id', 'type', 'version'], + }, + ], + }, + correlation: { type: 'string' }, + }, + required: ['formsVersion', 'correlation'], + }, + required: ['responseCode', 'message', 'result', 'meta'], +} + +const deactivateOrgSchema = { + type: 'object', + properties: { + responseCode: { type: 'string' }, + message: { type: 'string' }, + result: { + type: 'object', + properties: { + deactivated_users: { type: 'integer' }, + }, + required: ['deactivated_users'], + }, + meta: { + type: 'object', + properties: { + formsVersion: { + type: 'array', + items: [ + { + type: 'object', + properties: { + id: { type: 'integer' }, + type: { type: 'string' }, + version: { type: 'integer' }, }, - required: ['address', 'verified'], + required: ['id', 'type', 'version'], }, - name: { - type: 'string', + { + type: 'object', + properties: { + id: { type: 'integer' }, + type: { type: 'string' }, + version: { type: 'integer' }, + }, + required: ['id', 'type', 'version'], }, - role: { - type: 'string', + { + type: 'object', + properties: { + id: { type: 'integer' }, + type: { type: 'string' }, + version: { type: 'integer' }, + }, + required: ['id', 'type', 'version'], }, - updatedAt: { - type: 'string', + { + type: 'object', + properties: { + id: { type: 'integer' }, + type: { type: 'string' }, + version: { type: 'integer' }, + }, + required: ['id', 'type', 'version'], }, - createdAt: { - type: 'string', + { + type: 'object', + properties: { + id: { type: 'integer' }, + type: { type: 'string' }, + version: { type: 'integer' }, + }, + required: ['id', 'type', 'version'], }, - __v: { - type: 'integer', + { + type: 'object', + properties: { + id: { type: 'integer' }, + type: { type: 'string' }, + version: { type: 'integer' }, + }, + required: ['id', 'type', 'version'], }, - }, - required: ['_id', 'email', 'name', 'role', 'updatedAt', 'createdAt', '__v'], + ], }, + correlation: { type: 'string' }, }, - required: ['access_token', 'refresh_token', 'user'], - }, - meta: { - type: 'object', + required: ['formsVersion', 'correlation'], }, }, required: ['responseCode', 'message', 'result', 'meta'], @@ -84,4 +318,6 @@ const loginSchema = { module.exports = { createSystemUserSchema, loginSchema, + addOrgAdminSchema, + deactivateOrgSchema, } diff --git a/src/integration-test/systemUser/systemUser.spec.js b/src/integration-test/systemUser/systemUser.spec.js index 734ae0d41..7652a41aa 100644 --- a/src/integration-test/systemUser/systemUser.spec.js +++ b/src/integration-test/systemUser/systemUser.spec.js @@ -5,40 +5,74 @@ * Description : Integration test for systemUser controllers. */ -const { request, logIn, logError } = require('@commonTests') -const { createSystemUserSchema, loginSchema } = require('./responseSchema') +const { request, logIn, adminLogIn, logError } = require('@commonTests') +const { createSystemUserSchema, loginSchema, addOrgAdminSchema, deactivateOrgSchema } = require('./responseSchema') const { faker } = require('@faker-js/faker') +const { afterLogIn } = require('./systemUserData') -const { insertAdminUser } = require('./systemUserData') - -describe('user/v1/systemUsers', function () { +describe('user/v1/admin', function () { let userDetails - + let email = faker.internet.email() + let password = faker.internet.password() beforeAll(async () => { userDetails = await logIn() + adminDetails = await adminLogIn() }) it('/create', async () => { - let res = await request.post('/user/v1/systemUsers/create').send({ - name: 'admin', - email: faker.internet.email(), - password: faker.internet.password(), - role: 'admin', - secretCode: 'W5bF7gesuS0xsNWmpsKy', - }) + let res = await request + .post('/user/v1/admin/create') + .set({ + internal_access_token: 'internal_access_token', + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + name: 'admin', + email: email, + password: password, + secret_code: 'W5bF7gesuS0xsNWmpsKy', + }) logError(res) expect(res.statusCode).toBe(201) expect(res.body).toMatchSchema(createSystemUserSchema) }) it('/login', async () => { - let adminDetails = await insertAdminUser() - let res = await request.post('/user/v1/systemUsers/login').send({ - email: adminDetails.email, - password: adminDetails.password, + let res = await request.post('/user/v1/admin/login').send({ + email: email, + password: password, }) logError(res) expect(res.statusCode).toBe(200) expect(res.body).toMatchSchema(loginSchema) }) + it('/addOrgAdmin', async () => { + let res = await request + .post('/user/v1/admin/addOrgAdmin') + .set({ + 'X-auth-token': 'bearer ' + adminDetails.token, + }) + .send({ + email: email, + organization_id: 1, + }) + + logError(res) + expect(res.statusCode).toBe(200) + expect(res.body).toMatchSchema(addOrgAdminSchema) + }) + it('/deactivateOrg', async () => { + const logInAfter = await afterLogIn(email, password) + let res = await request + .post('/user/v1/admin/deactivateOrg/1') + .set({ + 'X-auth-token': 'bearer ' + logInAfter.token, + }) + .send({}) + + logError(res) + expect(res.statusCode).toBe(200) + expect(res.body).toMatchSchema(deactivateOrgSchema) + }) }) diff --git a/src/integration-test/systemUser/systemUserData.js b/src/integration-test/systemUser/systemUserData.js index 6bd636dca..ac731bffc 100644 --- a/src/integration-test/systemUser/systemUserData.js +++ b/src/integration-test/systemUser/systemUserData.js @@ -1,7 +1,14 @@ -const systemUserData = require('@db/systemUsers/queries') +const systemUserData = require('@database/queries/users') const utilsHelper = require('@generics/utils') const { faker } = require('@faker-js/faker') const crypto = require('crypto') +const baseURL = 'http://localhost:3001' +var supertest = require('supertest') //require supertest +var defaults = require('superagent-defaults') +require('@configs/aes256cbc')() + +const request = defaults(supertest(baseURL)) //supertest hits the HTTP server (your app) +let defaultHeaders let bodyData const insertAdminUser = async () => { @@ -11,9 +18,11 @@ const insertAdminUser = async () => { bodyData = { name: 'Admin', - email: { address: email, verified: false }, + email: email, password: password, - role: 'admin', + secret_code: 'W5bF7gesuS0xsNWmpsKy', + roles: 'admin', + organization_id: 1, } bodyData.password = utilsHelper.hashPassword(bodyData.password) await systemUserData.create(bodyData) @@ -23,6 +32,36 @@ const insertAdminUser = async () => { } } +const afterLogIn = async (email, password) => { + try { + res = await request.post('/user/v1/account/login').send({ + email: email, + password: password, + }) + if (res.body.result.access_token && res.body.result.user.id) { + defaultHeaders = { + 'X-auth-token': 'bearer ' + res.body.result.access_token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + } + request.set(defaultHeaders) + return { + token: res.body.result.access_token, + refreshToken: res.body.result.refresh_token, + userId: res.body.result.user.id, + email: email, + password: password, + } + } else { + console.error('Error while getting access token') + return false + } + } catch (error) { + console.error(error) + } +} + module.exports = { insertAdminUser, + afterLogIn, } diff --git a/src/integration-test/user-role/responseSchema.js b/src/integration-test/user-role/responseSchema.js index 9022f3d42..0f7463d11 100644 --- a/src/integration-test/user-role/responseSchema.js +++ b/src/integration-test/user-role/responseSchema.js @@ -73,7 +73,7 @@ const updateSchema = { type: 'integer', }, }, - required: ['title', 'user_type', 'status', 'visibility', 'organization_id'], + required: [], }, meta: { type: 'object', diff --git a/src/integration-test/user-role/userRole.spec.js b/src/integration-test/user-role/userRole.spec.js index a1df3e9df..9cecc2860 100644 --- a/src/integration-test/user-role/userRole.spec.js +++ b/src/integration-test/user-role/userRole.spec.js @@ -1,20 +1,30 @@ -const { request, logIn, logError } = require('@commonTests') +const { request, logIn, adminLogIn, logError } = require('@commonTests') let responseSchema = require('./responseSchema') +const { faker } = require('@faker-js/faker') +const { insertUserRole } = require('./userRoleData') describe('/user/v1/user-role', function () { let userDetails beforeAll(async () => { - userDetails = await logIn() + userDetails = await adminLogIn() + insertRole = await insertUserRole() }) it('/create', async () => { - let res = await request.post('/user/v1/user-role/create').send({ - title: 'system_admin', - user_type: 1, - status: 'ACTIVE', - visibility: 'PUBLIC', - organization_id: 1, - }) + let name = faker.lorem.word().toLowerCase() + let res = await request + .post('/user/v1/user-role/create') + .set({ + 'X-auth-token': 'bearer ' + userDetails.token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + title: name, + user_type: 1, + status: 'ACTIVE', + visibility: 'PUBLIC', + }) logError(res) expect(res.statusCode).toBe(201) @@ -22,13 +32,20 @@ describe('/user/v1/user-role', function () { }) it('/update', async () => { - let res = await request.post('/user/v1/user-role/update/7').send({ - title: 'system_adm', - user_type: 1, - status: 'ACTIVE', - visibility: 'PUBLIC', - organization_id: 1, - }) + let name = faker.lorem.word().toLowerCase() + let res = await request + .post('/user/v1/user-role/update/' + insertRole[0]) + .set({ + 'X-auth-token': 'bearer ' + insertRole[1], + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + title: name, + user_type: 1, + status: 'ACTIVE', + visibility: 'PUBLIC', + }) logError(res) expect(res.statusCode).toBe(201) @@ -36,7 +53,11 @@ describe('/user/v1/user-role', function () { }) it('/delete', async () => { - let res = await request.post('/user/v1/user-role/delete/7') + let res = await request.post('/user/v1/user-role/delete/' + insertRole[0]).set({ + 'X-auth-token': 'bearer ' + insertRole[1], + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) logError(res) expect(res.statusCode).toBe(202) @@ -46,7 +67,12 @@ describe('/user/v1/user-role', function () { it('/list', async () => { let res = await request .get('/user/v1/user-role/list') - .query({ page: 1, limit: 10, code: 'system', organization_id: 1 }) + .set({ + 'X-auth-token': 'bearer ' + userDetails.token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .query({ page: 1, limit: 10, search: 'user' }) logError(res) expect(res.statusCode).toBe(200) @@ -56,7 +82,10 @@ describe('/user/v1/user-role', function () { it('/default', async () => { let res = await request .get('/user/v1/user-role/default') - .query({ page: 1, limit: 10, code: 'system', organization_id: 1 }) + .set({ + internal_access_token: 'internal_access_token', + }) + .query({ page: 1, limit: 10 }) logError(res) expect(res.statusCode).toBe(200) diff --git a/src/integration-test/user-role/userRoleData.js b/src/integration-test/user-role/userRoleData.js new file mode 100644 index 000000000..1ceb655f5 --- /dev/null +++ b/src/integration-test/user-role/userRoleData.js @@ -0,0 +1,39 @@ +const { request, adminLogIn, logError } = require('@commonTests') + +const { faker } = require('@faker-js/faker') + +const insertUserRole = async () => { + try { + userDetails = await adminLogIn() + + let name = faker.lorem.word().toLowerCase() + let res = await request + .post('/user/v1/user-role/create') + .set({ + 'X-auth-token': 'bearer ' + userDetails.token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + title: name, + user_type: 1, + status: 'ACTIVE', + visibility: 'PUBLIC', + }) + res = await request + .get('/user/v1/user-role/list') + .set({ + 'X-auth-token': 'bearer ' + userDetails.token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .query({ page: 1, limit: 10, search: name }) + return [res.body.result.data[0].id, userDetails.token] + } catch (error) { + console.error(error) + } +} + +module.exports = { + insertUserRole, +} diff --git a/src/integration-test/userentity/responseSchema.js b/src/integration-test/userentity/responseSchema.js index d6eac6e68..6f94e7808 100644 --- a/src/integration-test/userentity/responseSchema.js +++ b/src/integration-test/userentity/responseSchema.js @@ -19,28 +19,28 @@ const createEntitySchema = { status: { type: 'string', }, - deleted: { - type: 'boolean', + deleted_at: { + type: 'null', }, type: { type: 'string', }, - createdBy: { - type: 'string', + created_by: { + type: 'integer', }, - updatedBy: { - type: 'string', + updated_by: { + type: 'integer', }, - _id: { - type: 'string', + id: { + type: 'integer', }, - updatedAt: { + updated_at: { type: 'string', }, - createdAt: { + created_at: { type: 'string', }, - __v: { + entity_type_id: { type: 'integer', }, }, @@ -48,14 +48,14 @@ const createEntitySchema = { 'value', 'label', 'status', - 'deleted', + 'deleted_at', 'type', - 'createdBy', - 'updatedBy', - '_id', - 'updatedAt', - 'createdAt', - '__v', + 'created_by', + 'updated_by', + 'id', + 'updated_at', + 'created_at', + 'entity_type_id', ], }, }, diff --git a/src/integration-test/userentity/userentity.spec.js b/src/integration-test/userentity/userentity.spec.js index 1399ff2ba..59987feb2 100644 --- a/src/integration-test/userentity/userentity.spec.js +++ b/src/integration-test/userentity/userentity.spec.js @@ -5,7 +5,7 @@ * Description : Integration test for userEntity controllers. */ -const { request, logIn, logError } = require('@commonTests') +const { request, adminLogIn, logError } = require('@commonTests') const { faker } = require('@faker-js/faker') const { insertEntity } = require('./userentityData') const schema = require('./responseSchema') @@ -15,47 +15,74 @@ describe('End point test for', function () { let entityId beforeAll(async () => { - userDetails = await logIn() + userDetails = await adminLogIn() entityId = await insertEntity() }) - it('creating user entity', async () => { + it('/create', async () => { let value = faker.random.alpha(5) let res = await request - .post('/user/v1/userentity/create') + .post('/user/v1/entity/create') + .set({ + 'X-auth-token': 'bearer ' + userDetails.token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) .send({ - value: value, - label: value, + value: faker.random.alpha(5), + label: faker.random.alpha(5), + status: 'ACTIVE', type: 'roles', + entity_type_id: 1, }) - .set('X-auth-token', 'bearer ' + userDetails.token) logError(res) expect(res.statusCode).toBe(201) expect(res.body).toMatchSchema(schema.createEntitySchema) }) - it('reading user entity', async () => { + it('/read', async () => { let res = await request - .patch('/user/v1/userentity/read') + .patch('/user/v1/entity/read') + .set({ + 'X-auth-token': 'bearer ' + userDetails.token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) .query({ type: 'roles', deleted: 'false', status: 'ACTIVE' }) logError(res) expect(res.statusCode).toBe(200) expect(res.body).toMatchSchema(schema.readEntitySchema) }) - it('updating user entity', async () => { - let res = await request.patch('/user/v1/userentity/update/' + entityId).send({ - value: 'testUpdate', - }) + + it('/update', async () => { + let res = await request + .post('/user/v1/entity/update/' + entityId[0]) + .set({ + 'X-auth-token': 'bearer ' + entityId[1], + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + value: faker.random.alpha(5), + label: 'acycz', + status: 'ACTIVE', + type: 'roles', + entity_type_id: 1, + }) logError(res) expect(res.statusCode).toBe(202) expect(res.body).toMatchSchema(schema.updateEntitySchema) }) - it('deleting user entity', async () => { - let res = await request.delete('/user/v1/userentity/delete/' + entityId) + it('/delete', async () => { + let res = await request.delete('/user/v1/entity/delete/' + entityId[0]).set({ + 'X-auth-token': 'bearer ' + entityId[1], + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) logError(res) expect(res.statusCode).toBe(202) diff --git a/src/integration-test/userentity/userentityData.js b/src/integration-test/userentity/userentityData.js index aed7a3a0e..be4b5747f 100644 --- a/src/integration-test/userentity/userentityData.js +++ b/src/integration-test/userentity/userentityData.js @@ -1,18 +1,26 @@ -const userEntitiesData = require('@db/userentities/query') +const { request, adminLogIn, logError } = require('@commonTests') + const { faker } = require('@faker-js/faker') -let res, bodyData const insertEntity = async () => { try { - bodyData = { - value: faker.random.alpha(5), - label: faker.random.alpha(5), - type: 'roles', - updatedBy: faker.database.mongodbObjectId(), - createdBy: faker.database.mongodbObjectId(), - } - res = await userEntitiesData.createEntity(bodyData) - return res._id.valueOf() + userDetails = await adminLogIn() + + let res = await request + .post('/user/v1/entity/create') + .set({ + 'X-auth-token': 'bearer ' + userDetails.token, + Connection: 'keep-alive', + 'Content-Type': 'application/json', + }) + .send({ + value: faker.random.alpha(5), + label: faker.random.alpha(5), + status: 'ACTIVE', + type: 'roles', + entity_type_id: 1, + }) + return [res.body.result.id, userDetails.token] } catch (error) { console.error(error) } diff --git a/src/integrationJest.config.js b/src/integrationJest.config.js index 973a0c66f..d05be4274 100644 --- a/src/integrationJest.config.js +++ b/src/integrationJest.config.js @@ -10,6 +10,8 @@ module.exports = { '@services/(.*)': '/services/$1', '@controllers/(.*)': '/controllers/$1', '@database/(.*)': '/database/$1', + '@utils/(.*)': '/utils/$1', + '@db/(.*)': '/db/$1', '@generics/(.*)': '/generics/$1', '@constants/(.*)': '/constants/$1', '@configs/(.*)': '/configs/$1', diff --git a/src/package.json b/src/package.json index 39f87028e..5a46f6abb 100644 --- a/src/package.json +++ b/src/package.json @@ -37,7 +37,7 @@ "crypto": "^1.0.1", "csvtojson": "^2.0.10", "dotenv": "^10.0.0", - "elevate-cloud-storage": "2.6.1", + "elevate-cloud-storage": "^2.6.3", "elevate-encryption": "^1.0.1", "elevate-logger": "^3.1.0", "elevate-node-cache": "^1.0.6", diff --git a/src/services/account.js b/src/services/account.js index 4d1de6a92..7b1f0539a 100644 --- a/src/services/account.js +++ b/src/services/account.js @@ -1420,4 +1420,65 @@ module.exports = class AccountHelper { throw error } } + + /** + * Account Search By Email + * @method + * @name list method post + * @param {Object} req -request data. + * @param {Array} userIds -contains emailIds. + * @returns {JSON} - all accounts data + */ + + static async searchByEmailIds(params) { + if (params.hasOwnProperty('body') && params.body.hasOwnProperty('emailIds')) { + const emailIds = params.body.emailIds + let filterQuery = { + email: emailIds, + } + + let options = { + attributes: { + exclude: ['password', 'refresh_tokens'], + }, + } + + //returning deleted user if internal token is passing + if (params.headers.internal_access_token) { + options.paranoid = false + } + + let users = await userQueries.findAll(filterQuery, options) + + let roles = await roleQueries.findAll( + {}, + { + attributes: { + exclude: ['created_at', 'updated_at', 'deleted_at'], + }, + } + ) + + users.forEach(async (user) => { + if (user.roles && user.roles.length > 0) { + let roleData = roles.filter((role) => user.roles.includes(role.id)) + user['user_roles'] = roleData + } + user.email = emailEncryption.decrypt(user.email) + }) + if (!users) { + return responses.successResponse({ + statusCode: httpStatusCode.ok, + message: 'USERS_FETCHED_SUCCESSFULLY', + result: {}, + }) + } else { + return responses.successResponse({ + statusCode: httpStatusCode.ok, + message: 'USERS_FETCHED_SUCCESSFULLY', + result: users[0], + }) + } + } + } } diff --git a/src/setupFileAfterEnv.js b/src/setupFileAfterEnv.js index 6226cd686..b5b616467 100644 --- a/src/setupFileAfterEnv.js +++ b/src/setupFileAfterEnv.js @@ -1,45 +1,38 @@ -const mongoose = require('mongoose') -const mongoose_autopopulate = require('mongoose-autopopulate') -const mongoose_timestamp = require('mongoose-timestamp') +const { Client } = require('pg') const { matchers } = require('jest-json-schema') -expect.extend(matchers) - -//Connect to database -/* -Uses MongoDB v4.1.4, which has an OSI Compliant License (GNU Affero General Public License, version 3) -MongoDB v4.1.4 repository: https://github.com/mongodb/mongo/tree/r4.1.4 -MongoDB v4.1.4 License: https://github.com/mongodb/mongo/blob/r4.1.4/LICENSE-Community.txt -*/ +const { Pool } = require('pg') +const pool = new Pool() -const db = mongoose.createConnection('mongodb://127.0.0.1:27017/elevate-mentoring', { - useNewUrlParser: true, -}) +expect.extend(matchers) -db.on('error', function () { - console.log('Database connection error:') -}) +//PostgreSQL connection string +const connectionString = 'postgres://postgres:postgres@localhost:5432/mentoring-local' -db.once('open', function () { - //console.log('Connected to DB') +// Connect to the PostgreSQL database using the connection string +const db = new Client({ + connectionString: connectionString, }) -mongoose.plugin(mongoose_timestamp, { - createdAt: 'createdAt', - updatedAt: 'updatedAt', +db.connect((err) => { + if (err) { + console.error('Database connection error:', err) + } else { + console.log('Connected to DB') + } }) -mongoose.plugin(mongoose_autopopulate) - global.db = db -beforeAll(async () => {}) +beforeAll(async () => { + // You can add any setup code you need here +}) afterAll(async () => { try { - //console.log('runs afterAll') - //await db.dropDatabase() + // Add any cleanup code you need, such as dropping tables, here } catch (error) { - console.log(error) + console.error(error) + } finally { + db.end() // Close the PostgreSQL connection } - mongoose.disconnect() })