|
| 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