|
| 1 | +const assert = require('assert'); |
| 2 | +const crypto = require('crypto'); |
| 3 | +const { createClient, findWireMockRequest } = require('../utils/utils.js'); |
| 4 | +const { TEST_PLAN_ID } = require('./common_test_constants.js'); |
| 5 | + |
| 6 | +describe('Users - listAllUsers endpoint tests', function () { |
| 7 | + let client = createClient(); |
| 8 | + const emails = '[email protected]'; |
| 9 | + const seatType = 'MEMBER'; |
| 10 | + const page = 1; |
| 11 | + const pageSize = 100; |
| 12 | + const includeAll = false; |
| 13 | + const seatTypeLastChangedAt = '2025-06-14T09:55:30Z'; |
| 14 | + const provisionalExpirationDate = '2026-12-13T12:17:52.525696Z'; |
| 15 | + const isInternal = true; |
| 16 | + const firstName = 'Test'; |
| 17 | + const lastName = 'User'; |
| 18 | + const name = 'Test User'; |
| 19 | + const email = '[email protected]'; |
| 20 | + const admin = true; |
| 21 | + const licensedSheetCreator = true; |
| 22 | + const resourceViewer = true; |
| 23 | + const groupAdmin = true; |
| 24 | + const status = 'ACTIVE'; |
| 25 | + const sheetCount = -1; |
| 26 | + const lastLogin = '2020-10-04T18:32:47Z'; |
| 27 | + const customWelcomeScreenViewed = '2020-08-25T12:15:47Z'; |
| 28 | + |
| 29 | + it('listUsers generated url is correct', async function () { |
| 30 | + const requestId = crypto.randomUUID(); |
| 31 | + const options = { |
| 32 | + queryParameters: { |
| 33 | + emails: emails, |
| 34 | + planId: TEST_PLAN_ID, |
| 35 | + seatType: seatType, |
| 36 | + includeAll: includeAll, |
| 37 | + page: page, |
| 38 | + pageSize: pageSize |
| 39 | + }, |
| 40 | + customProperties: { |
| 41 | + 'x-request-id': requestId, |
| 42 | + 'x-test-name': '/users/list-users/required-response-body-properties' |
| 43 | + } |
| 44 | + }; |
| 45 | + await client.users.listAllUsers(options); |
| 46 | + const matchedRequest = await findWireMockRequest(requestId); |
| 47 | + const queryParams = matchedRequest.queryParams; |
| 48 | + const emailsActual = queryParams.emails.values[0]; |
| 49 | + const planIdActual = parseInt(queryParams.planId.values[0]); |
| 50 | + const seatTypeActual = queryParams.seatType.values[0]; |
| 51 | + const includeAllActual = queryParams.includeAll.values[0]; |
| 52 | + const pageActual = queryParams.page.values[0]; |
| 53 | + const pageSizeActual = queryParams.pageSize.values[0]; |
| 54 | + assert.ok(matchedRequest.url.includes(`/2.0/users`)); |
| 55 | + assert.strictEqual(emailsActual, emails); |
| 56 | + assert.strictEqual(planIdActual, TEST_PLAN_ID); |
| 57 | + assert.strictEqual(seatTypeActual, seatType); |
| 58 | + assert.strictEqual(includeAllActual, includeAll.toString()); |
| 59 | + assert.strictEqual(parseInt(pageActual), page); |
| 60 | + assert.strictEqual(parseInt(pageSizeActual), pageSize); |
| 61 | + }); |
| 62 | + |
| 63 | + it('listUsers all response body properties', async function () { |
| 64 | + const requestId = crypto.randomUUID(); |
| 65 | + const options = { |
| 66 | + queryParameters: { |
| 67 | + planId: TEST_PLAN_ID |
| 68 | + }, |
| 69 | + customProperties: { |
| 70 | + 'x-request-id': requestId, |
| 71 | + 'x-test-name': '/users/list-users/all-response-body-properties' |
| 72 | + } |
| 73 | + }; |
| 74 | + const response = await client.users.listAllUsers(options); |
| 75 | + assert.ok(response); |
| 76 | + assert.strictEqual(response.data[0].seatType, seatType); |
| 77 | + assert.strictEqual(response.data[0].seatTypeLastChangedAt, seatTypeLastChangedAt); |
| 78 | + assert.strictEqual(response.data[0].provisionalExpirationDate, provisionalExpirationDate); |
| 79 | + assert.strictEqual(response.data[0].isInternal, isInternal); |
| 80 | + assert.strictEqual(response.data[0].firstName, firstName); |
| 81 | + assert.strictEqual(response.data[0].lastName, lastName); |
| 82 | + assert.strictEqual(response.data[0].name, name); |
| 83 | + assert.strictEqual(response.data[0].email, email); |
| 84 | + assert.strictEqual(response.data[0].admin, admin); |
| 85 | + assert.strictEqual(response.data[0].licensedSheetCreator, licensedSheetCreator); |
| 86 | + assert.strictEqual(response.data[0].resourceViewer, resourceViewer); |
| 87 | + assert.strictEqual(response.data[0].groupAdmin, groupAdmin); |
| 88 | + assert.strictEqual(response.data[0].status, status); |
| 89 | + assert.strictEqual(response.data[0].sheetCount, sheetCount); |
| 90 | + assert.strictEqual(response.data[0].lastLogin, lastLogin); |
| 91 | + assert.strictEqual(response.data[0].customWelcomeScreenViewed, customWelcomeScreenViewed); |
| 92 | + assert.strictEqual(response.data[0].id, TEST_PLAN_ID); |
| 93 | + }); |
| 94 | + |
| 95 | + it('listUsers required response body properties', async function () { |
| 96 | + const requestId = crypto.randomUUID(); |
| 97 | + const options = { |
| 98 | + queryParameters: { |
| 99 | + planId: TEST_PLAN_ID |
| 100 | + }, |
| 101 | + customProperties: { |
| 102 | + 'x-request-id': requestId, |
| 103 | + 'x-test-name': '/users/list-users/required-response-body-properties' |
| 104 | + } |
| 105 | + }; |
| 106 | + const response = await client.users.listAllUsers(options); |
| 107 | + assert.ok(response); |
| 108 | + assert.strictEqual(response.data[0].seatType, seatType); |
| 109 | + assert.strictEqual(response.data[0].seatTypeLastChangedAt, undefined); |
| 110 | + assert.strictEqual(response.data[0].provisionalExpirationDate, undefined); |
| 111 | + assert.strictEqual(response.data[0].isInternal, isInternal); |
| 112 | + assert.strictEqual(response.data[0].firstName, firstName); |
| 113 | + assert.strictEqual(response.data[0].lastName, lastName); |
| 114 | + assert.strictEqual(response.data[0].name, name); |
| 115 | + assert.strictEqual(response.data[0].email, email); |
| 116 | + assert.strictEqual(response.data[0].admin, admin); |
| 117 | + assert.strictEqual(response.data[0].licensedSheetCreator, licensedSheetCreator); |
| 118 | + assert.strictEqual(response.data[0].resourceViewer, resourceViewer); |
| 119 | + assert.strictEqual(response.data[0].groupAdmin, groupAdmin); |
| 120 | + assert.strictEqual(response.data[0].status, status); |
| 121 | + assert.strictEqual(response.data[0].sheetCount, sheetCount); |
| 122 | + assert.strictEqual(response.data[0].lastLogin, undefined); |
| 123 | + assert.strictEqual(response.data[0].customWelcomeScreenViewed, undefined); |
| 124 | + assert.strictEqual(response.data[0].id, TEST_PLAN_ID); |
| 125 | + }); |
| 126 | + |
| 127 | + it('listUserPlans error 500 response', async function () { |
| 128 | + const requestId = crypto.randomUUID(); |
| 129 | + const options = { |
| 130 | + queryParameters: { |
| 131 | + planId: TEST_PLAN_ID |
| 132 | + }, |
| 133 | + customProperties: { |
| 134 | + 'x-request-id': requestId, |
| 135 | + 'x-test-name': '/errors/500-response' |
| 136 | + } |
| 137 | + }; |
| 138 | + try { |
| 139 | + await client.users.listAllUsers(options); |
| 140 | + assert.fail('Expected an error to be thrown'); |
| 141 | + } catch (error) { |
| 142 | + assert.strictEqual(error.statusCode, 500); |
| 143 | + assert.strictEqual(error.message, 'Internal Server Error'); |
| 144 | + } |
| 145 | + }); |
| 146 | + |
| 147 | + it('listUserPlans error 400 response', async function () { |
| 148 | + const requestId = crypto.randomUUID(); |
| 149 | + const options = { |
| 150 | + queryParameters: { |
| 151 | + planId: TEST_PLAN_ID |
| 152 | + }, |
| 153 | + customProperties: { |
| 154 | + 'x-request-id': requestId, |
| 155 | + 'x-test-name': '/errors/400-response' |
| 156 | + } |
| 157 | + }; |
| 158 | + try { |
| 159 | + await client.users.listAllUsers(options); |
| 160 | + assert.fail('Expected an error to be thrown'); |
| 161 | + } catch (error) { |
| 162 | + assert.strictEqual(error.statusCode, 400); |
| 163 | + assert.strictEqual(error.message, 'Malformed Request'); |
| 164 | + } |
| 165 | + }); |
| 166 | +}); |
0 commit comments