Skip to content

Commit 9c89e62

Browse files
organizations testcases
1 parent db9d6b1 commit 9c89e62

File tree

11 files changed

+1689
-10
lines changed

11 files changed

+1689
-10
lines changed

src/integration-test/commonTests.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ const adminLogIn = async () => {
148148
userId: res.body.result.user.id,
149149
email: email,
150150
password: password,
151+
organization_id: res.body.result.user.organization_id,
151152
}
152153
} else {
153154
console.error('Error while getting access token')
@@ -157,6 +158,76 @@ const adminLogIn = async () => {
157158
console.error(error)
158159
}
159160
}
161+
162+
const orgAdminLogIn = async () => {
163+
try {
164+
var waitOn = require('wait-on')
165+
var opts = {
166+
resources: [baseURL],
167+
delay: 1000, // initial delay in ms, default 0
168+
interval: 500, // poll interval in ms, default 250ms
169+
timeout: 30000,
170+
}
171+
await waitOn(opts)
172+
let email = 'nevil' + crypto.randomBytes(5).toString('hex') + '@admin.com'
173+
let password = faker.internet.password()
174+
let res = await request
175+
.post('/user/v1/admin/create')
176+
.set({
177+
internal_access_token: 'internal_access_token',
178+
Connection: 'keep-alive',
179+
'Content-Type': 'application/json',
180+
})
181+
.send({
182+
name: 'Nevil',
183+
email: email,
184+
password: password,
185+
secret_code: 'W5bF7gesuS0xsNWmpsKy',
186+
})
187+
res = await request.post('/user/v1/admin/login').send({
188+
email: email,
189+
password: password,
190+
})
191+
res = await request
192+
.post('/user/v1/admin/addOrgAdmin')
193+
.set({
194+
'X-auth-token': 'bearer ' + res.body.result.access_token,
195+
})
196+
.send({
197+
email: email,
198+
organization_id: 1,
199+
})
200+
res = await request.post('/user/v1/account/login').send({
201+
email: email,
202+
password: password,
203+
})
204+
205+
if (res.body.result.access_token && res.body.result.user.id) {
206+
defaultHeaders = {
207+
'X-auth-token': 'bearer ' + res.body.result.access_token,
208+
Connection: 'keep-alive',
209+
'Content-Type': 'application/json',
210+
}
211+
global.request = defaults(supertest(baseURL))
212+
global.request.set(defaultHeaders)
213+
global.userId = res.body.result.user.id
214+
return {
215+
token: res.body.result.access_token,
216+
refreshToken: res.body.result.refresh_token,
217+
userId: res.body.result.user.id,
218+
email: email,
219+
password: password,
220+
organization_id: res.body.result.user.organization_id,
221+
}
222+
} else {
223+
console.error('Error while getting access token')
224+
return false
225+
}
226+
} catch (error) {
227+
console.error(error)
228+
}
229+
}
230+
160231
function logError(res) {
161232
let successCodes = [200, 201, 202]
162233
if (!successCodes.includes(res.statusCode)) {
@@ -169,4 +240,5 @@ module.exports = {
169240
logError,
170241
mentorLogIn,
171242
adminLogIn,
243+
orgAdminLogIn,
172244
}

src/integration-test/mentor/mentor.spec.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@
55
* Description : Integration test for mentor controllers.
66
*/
77

8-
const { request, logIn, logError } = require('@commonTests')
8+
const { request, logIn, mentorLogIn, logError } = require('@commonTests')
99
const { listMentorsSchema } = require('./responseSchema')
1010
const { insertMentor } = require('./mentorData')
1111

1212
describe('user/v1/mentors', function () {
1313
let userDetails
1414

1515
beforeAll(async () => {
16-
userDetails = await logIn()
16+
userDetails = await mentorLogIn()
1717
})
1818
it('/list', async () => {
19-
await insertMentor()
20-
let res = await request.get('/user/v1/mentors/list')
19+
// await insertMentor()
20+
let res = await request.post('/user/v1/mentors/list').set({
21+
'X-auth-token': 'bearer ' + userDetails.token,
22+
Connection: 'keep-alive',
23+
'Content-Type': 'application/json',
24+
})
2125
logError(res)
2226
expect(res.statusCode).toBe(200)
2327
expect(res.body).toMatchSchema(listMentorsSchema)
2428
})
2529
})
30+
31+
// mentor/list role permissions are not present , so integrations doesn't work.

src/integration-test/mentor/mentorData.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
const usersData = require('@db/users/queries')
1+
const usersData = require('@database/queries/users')
22
const { faker } = require('@faker-js/faker')
33
let bodyData
44
const insertMentor = async () => {
55
try {
66
bodyData = {
77
name: 'Nevil (Mentor)',
8-
email: { address: faker.internet.email(), verified: false },
8+
email: faker.internet.email(),
99
password: faker.internet.password(),
1010
isAMentor: true,
11-
secretCode: 'secret-code',
11+
secret_code: 'secret-code',
12+
roles: 2,
13+
organization_id: 1,
1214
}
13-
await usersData.createUser(bodyData)
15+
await usersData.create(bodyData)
1416
} catch (error) {
1517
console.error(error)
1618
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const { request, orgAdminLogIn, logError } = require('@commonTests')
2+
const { faker } = require('@faker-js/faker')
3+
4+
const insertRequest = async () => {
5+
try {
6+
userDetails = await orgAdminLogIn()
7+
8+
let res = await request
9+
.post('/user/v1/organization/requestOrgRole')
10+
.set({
11+
'X-auth-token': 'bearer ' + userDetails.token,
12+
Connection: 'keep-alive',
13+
'Content-Type': 'application/json',
14+
})
15+
.send({
16+
role: 5,
17+
organization_id: 1,
18+
form_data: {
19+
designation: 'Manager',
20+
experience: '5 years',
21+
area_of_expertise: ['Finance', 'Management'],
22+
about: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
23+
},
24+
})
25+
26+
logError(res)
27+
return [res.body, userDetails.token]
28+
} catch (error) {
29+
console.error(error)
30+
}
31+
}
32+
33+
module.exports = {
34+
insertRequest,
35+
}
36+
37+
// roleRequestData = {
38+
// requester_id: userDetails.userId,
39+
// role: 2,
40+
// status: 'REQUESTED',
41+
// organization_id: userDetails.organization_id,
42+
// handled_by: null,
43+
// meta: {
44+
// designation: 'Manager',
45+
// experience: '5 years',
46+
// area_of_expertise: ['Finance', 'Management'],
47+
// about: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
48+
// },
49+
// comments: ['Needs approval']
50+
// }
51+
// let createdReq = await OrganizationRoleRequests.create(roleRequestData)
52+
// return createdReq.get({ plain: true })
53+
// const result = await orgRoleReqQueries.create(roleRequestData)
54+
// console.log("result of inserting request",result)
55+
// return result
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
const { request, logError, orgAdminLogIn } = require('@commonTests')
2+
let responseSchema = require('./responseSchema')
3+
const { faker } = require('@faker-js/faker')
4+
const { insertRequest } = require('./orgAdminData')
5+
//const { requestDetails } = require('@database/queries/orgRoleRequest')
6+
7+
describe('/user/v1/org-admin', function () {
8+
let userDetails
9+
let randomFilePath
10+
11+
beforeAll(async () => {
12+
userDetails = await orgAdminLogIn()
13+
const generateRandomFilePath = () => {
14+
const randomFileName = faker.system.fileName()
15+
return `${randomFileName}.csv`
16+
}
17+
randomFilePath = generateRandomFilePath()
18+
})
19+
20+
it('/bulkUserCreate', async () => {
21+
let res = await request
22+
.post('/user/v1/org-admin/bulkUserCreate')
23+
.set({
24+
'X-auth-token': 'bearer ' + userDetails.token,
25+
Connection: 'keep-alive',
26+
'Content-Type': 'application/json',
27+
})
28+
.send({
29+
file_path: randomFilePath,
30+
})
31+
32+
logError(res)
33+
expect(res.statusCode).toBe(200)
34+
expect(res.body).toMatchSchema(responseSchema.bulkUserCreateSchema)
35+
})
36+
37+
it('/getBulkInvitesFilesList', async () => {
38+
let res = await request
39+
.get('/user/v1/org-admin/getBulkInvitesFilesList')
40+
.set({
41+
'X-auth-token': 'bearer ' + userDetails.token,
42+
Connection: 'keep-alive',
43+
'Content-Type': 'application/json',
44+
})
45+
.query({ page: 1, limit: 10, status: 'REQUESTED' })
46+
47+
logError(res)
48+
expect(res.statusCode).toBe(200)
49+
expect(res.body).toMatchSchema(responseSchema.getBulkInvitesFilesListSchema)
50+
})
51+
52+
it('/getRequestDetails', async () => {
53+
let requestDetails = await insertRequest()
54+
//console.log(requestDetails[0].meta.formsVersion)
55+
let res = await request.get('/user/v1/org-admin/getRequestDetails/' + requestDetails[0].result.id).set({
56+
'X-auth-token': 'bearer ' + requestDetails[1],
57+
Connection: 'keep-alive',
58+
'Content-Type': 'application/json',
59+
})
60+
61+
logError(res)
62+
expect(res.statusCode).toBe(200)
63+
expect(res.body).toMatchSchema(responseSchema.getRequestDetailsSchema)
64+
})
65+
66+
it('/getRequests', async () => {
67+
let requestDetails = await insertRequest()
68+
let res = await request
69+
.post('/user/v1/org-admin/getRequests')
70+
.set({
71+
'X-auth-token': 'bearer ' + requestDetails[1],
72+
Connection: 'keep-alive',
73+
'Content-Type': 'application/json',
74+
})
75+
.send({ filters: { role: requestDetails[0].result.role, status: ['REQUESTED'] } })
76+
77+
logError(res)
78+
expect(res.statusCode).toBe(200)
79+
expect(res.body).toMatchSchema(responseSchema.getRequestsSchema)
80+
})
81+
82+
it('/updateRequestStatus', async () => {
83+
let requestDetails = await insertRequest()
84+
let res = await request
85+
.post('/user/v1/org-admin/updateRequestStatus')
86+
.set({
87+
'X-auth-token': 'bearer ' + requestDetails[1],
88+
Connection: 'keep-alive',
89+
'Content-Type': 'application/json',
90+
})
91+
.send({
92+
request_id: requestDetails[0].result.id,
93+
comments: ['All uploaded documents verified', 'Profile information verified'],
94+
status: 'APPROVED',
95+
})
96+
97+
logError(res)
98+
expect(res.statusCode).toBe(200)
99+
expect(res.body).toMatchSchema(responseSchema.updateRequestStatusSchema)
100+
})
101+
102+
it('/deactivateUser', async () => {
103+
let requestDetails = await insertRequest()
104+
console.log(requestDetails)
105+
let res = await request
106+
.post('/user/v1/org-admin/deactivateUser')
107+
.set({
108+
'X-auth-token': 'bearer ' + requestDetails[1],
109+
Connection: 'keep-alive',
110+
'Content-Type': 'application/json',
111+
})
112+
.send({
113+
id: [requestDetails[0].result.requester_id],
114+
})
115+
116+
logError(res)
117+
expect(res.statusCode).toBe(200)
118+
console.log(res.body)
119+
expect(res.body).toMatchSchema(responseSchema.deactivateUserSchema)
120+
})
121+
122+
// need to get understanding for below api , where it is there for user service
123+
124+
// it('/inheritEntityType', async () => {
125+
// let requestDetails = await insertRequest()
126+
// console.log(requestDetails[0].result.meta)
127+
// let res = await request
128+
// .post('/user/v1/org-admin/inheritEntityType')
129+
// .set({
130+
// 'X-auth-token': 'bearer ' + requestDetails[1],
131+
// Connection: 'keep-alive',
132+
// 'Content-Type': 'application/json',
133+
// })
134+
// .send({
135+
// entity_type_value: 'categories',
136+
// target_entity_type_label: 'training'
137+
// })
138+
139+
// logError(res)
140+
// expect(res.statusCode).toBe(200)
141+
// console.log(res.body)
142+
// expect(res.body).toMatchSchema(responseSchema.deactivateUserSchema)
143+
// })
144+
})

0 commit comments

Comments
 (0)