-
Notifications
You must be signed in to change notification settings - Fork 16
Add tests for user endpoints #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
61df371
Add wiremock tests for the user endpoints module
denislavstanchev 0ce66ef
Add wiremock tests for the user module
denislavstanchev 9ac8546
Delete openapi.yaml
denislavstanchev 4384e53
Fix typo in timeZone from 'Pacfic' to 'Pacific'
denislavstanchev 241f7b0
Remove hardcoded value
denislavstanchev 45864df
Validate request bodies in the proper tests
denislavstanchev 74a6bc4
Verify request body in addProfileImage tests
denislavstanchev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,78 @@ | ||
| // Common User IDs | ||
| const TEST_USER_ID = 12345678; | ||
| const TEST_PLAN_ID = 1234567890123456; | ||
| const TEST_ACCOUNT_ID = 9876543210987654; | ||
|
|
||
| // Common Alternate Email ID | ||
| const TEST_ALTERNATE_EMAIL_ID = 9876543210987654; | ||
|
|
||
| // Common User Contact Information | ||
| const TEST_MOBILE_PHONE = '+1234567890'; | ||
| const TEST_EMAIL = 'test.user@smartsheet.com'; | ||
| const TEST_ALTERNATE_EMAIL = 'alternate.email@smartsheet.com'; | ||
|
|
||
| // Common User Names | ||
| const TEST_FIRST_NAME = 'Test'; | ||
| const TEST_LAST_NAME = 'User'; | ||
| const TEST_NAME = 'Test User'; | ||
|
|
||
| // Common User Timestamps | ||
| const TEST_CUSTOM_WELCOME_SCREEN_VIEWED = '2020-08-25T12:15:47Z'; | ||
| const TEST_LAST_LOGIN = '2020-10-04T18:32:47Z'; | ||
| const TEST_PROVISIONAL_EXPIRATION_DATE = '2026-12-13T12:17:52.525696Z'; | ||
| const TEST_SEAT_TYPE_LAST_CHANGED_AT = '2025-01-01T00:00:00.123456789Z'; | ||
|
|
||
| // Common Pagination Properties | ||
| const TEST_PAGE_NUMBER = 1; | ||
| const TEST_PAGE_SIZE = 100; | ||
| const TEST_TOTAL_PAGES = 1; | ||
| const TEST_TOTAL_COUNT = 1; | ||
|
|
||
| // Common User Properties | ||
| const TEST_SHEET_COUNT = -1; | ||
|
|
||
| // Common Profile Image Properties | ||
| const TEST_PROFILE_IMAGE_ID = 'u!1!nAtdn5RJB_o!k6_e_3h2R3w!wmYXPek-yVD'; | ||
| const TEST_PROFILE_IMAGE_HEIGHT = 1050; | ||
| const TEST_PROFILE_IMAGE_WIDTH = 1050; | ||
|
|
||
| // Common Success Response Values | ||
| const TEST_SUCCESS_MESSAGE = 'SUCCESS'; | ||
| const TEST_SUCCESS_RESULT_CODE = 0; | ||
|
|
||
| // Common Error Status Codes | ||
| const ERROR_500_STATUS_CODE = 500; | ||
| const ERROR_500_MESSAGE = 'Internal Server Error'; | ||
| const ERROR_400_STATUS_CODE = 400; | ||
| const ERROR_400_MESSAGE = 'Malformed Request'; | ||
|
|
||
| module.exports = { | ||
| TEST_USER_ID, | ||
| TEST_PLAN_ID, | ||
| TEST_ACCOUNT_ID, | ||
| TEST_ALTERNATE_EMAIL_ID, | ||
| TEST_MOBILE_PHONE, | ||
| TEST_EMAIL, | ||
| TEST_ALTERNATE_EMAIL, | ||
| TEST_FIRST_NAME, | ||
| TEST_LAST_NAME, | ||
| TEST_NAME, | ||
| TEST_CUSTOM_WELCOME_SCREEN_VIEWED, | ||
| TEST_LAST_LOGIN, | ||
| TEST_PROVISIONAL_EXPIRATION_DATE, | ||
| TEST_SEAT_TYPE_LAST_CHANGED_AT, | ||
| TEST_PAGE_NUMBER, | ||
| TEST_PAGE_SIZE, | ||
| TEST_TOTAL_PAGES, | ||
| TEST_TOTAL_COUNT, | ||
| TEST_SHEET_COUNT, | ||
| TEST_PROFILE_IMAGE_ID, | ||
| TEST_PROFILE_IMAGE_HEIGHT, | ||
| TEST_PROFILE_IMAGE_WIDTH, | ||
| TEST_SUCCESS_MESSAGE, | ||
| TEST_SUCCESS_RESULT_CODE | ||
| TEST_SUCCESS_RESULT_CODE, | ||
| ERROR_500_STATUS_CODE, | ||
| ERROR_500_MESSAGE, | ||
| ERROR_400_STATUS_CODE, | ||
| ERROR_400_MESSAGE | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| const assert = require('assert'); | ||
| const crypto = require('crypto'); | ||
| const { createClient, findWireMockRequest } = require('../utils/utils.js'); | ||
| const { | ||
| TEST_USER_ID, | ||
| TEST_ALTERNATE_EMAIL_ID, | ||
| TEST_SUCCESS_MESSAGE, | ||
| TEST_SUCCESS_RESULT_CODE, | ||
| ERROR_500_STATUS_CODE, | ||
| ERROR_500_MESSAGE, | ||
| ERROR_400_STATUS_CODE, | ||
| ERROR_400_MESSAGE | ||
| } = require('./common_test_constants.js'); | ||
|
|
||
| describe('Users - addAlternateEmail endpoint tests', function () { | ||
| let client = createClient(); | ||
| const TEST_EMAIL = 'alternate.email@smartsheet.com'; | ||
| const TEST_CONFIRMED = false; | ||
| const TEST_BODY = [{ email: TEST_EMAIL }]; | ||
|
|
||
| it('addAlternateEmail generated url is correct', async function () { | ||
| const requestId = crypto.randomUUID(); | ||
| const options = { | ||
| userId: TEST_USER_ID, | ||
| body: TEST_BODY, | ||
| customProperties: { | ||
| 'x-request-id': requestId, | ||
| 'x-test-name': '/users/alternate-emails/add-alternate-email/all-response-body-properties' | ||
| } | ||
| }; | ||
| await client.users.addAlternateEmail(options); | ||
| const matchedRequest = await findWireMockRequest(requestId); | ||
|
|
||
| assert.ok(matchedRequest.url.includes(`/users/${TEST_USER_ID}/alternateemails`)); | ||
| }); | ||
|
|
||
| it('addAlternateEmail all response body properties', async function () { | ||
| const requestId = crypto.randomUUID(); | ||
| const options = { | ||
| userId: TEST_USER_ID, | ||
| body: TEST_BODY, | ||
| customProperties: { | ||
| 'x-request-id': requestId, | ||
| 'x-test-name': '/users/alternate-emails/add-alternate-email/all-response-body-properties' | ||
| } | ||
| }; | ||
| const response = await client.users.addAlternateEmail(options); | ||
| const matchedRequest = await findWireMockRequest(requestId); | ||
|
|
||
| assert.ok(response); | ||
| assert.strictEqual(response.message, TEST_SUCCESS_MESSAGE); | ||
| assert.strictEqual(response.resultCode, TEST_SUCCESS_RESULT_CODE); | ||
| assert.ok(Array.isArray(response.data)); | ||
| assert.strictEqual(response.data.length, 1); | ||
| assert.strictEqual(response.data[0].id, TEST_ALTERNATE_EMAIL_ID); | ||
| assert.strictEqual(response.data[0].confirmed, TEST_CONFIRMED); | ||
| assert.strictEqual(response.data[0].email, TEST_EMAIL); | ||
|
|
||
| let body = JSON.parse(matchedRequest.body); | ||
| assert.deepStrictEqual(body, TEST_BODY); | ||
| }); | ||
|
|
||
| it('addAlternateEmail error 500 response', async function () { | ||
| const requestId = crypto.randomUUID(); | ||
| const options = { | ||
| userId: TEST_USER_ID, | ||
| body: TEST_BODY, | ||
| customProperties: { | ||
| 'x-request-id': requestId, | ||
| 'x-test-name': '/errors/500-response' | ||
| } | ||
| }; | ||
| try { | ||
| await client.users.addAlternateEmail(options); | ||
| assert.fail('Expected an error to be thrown'); | ||
| } catch (error) { | ||
| assert.strictEqual(error.statusCode, ERROR_500_STATUS_CODE); | ||
| assert.strictEqual(error.message, ERROR_500_MESSAGE); | ||
| } | ||
| }); | ||
|
|
||
| it('addAlternateEmail error 400 response', async function () { | ||
| const requestId = crypto.randomUUID(); | ||
| const options = { | ||
| userId: TEST_USER_ID, | ||
| body: TEST_BODY, | ||
| customProperties: { | ||
| 'x-request-id': requestId, | ||
| 'x-test-name': '/errors/400-response' | ||
| } | ||
| }; | ||
| try { | ||
| await client.users.addAlternateEmail(options); | ||
| assert.fail('Expected an error to be thrown'); | ||
| } catch (error) { | ||
| assert.strictEqual(error.statusCode, ERROR_400_STATUS_CODE); | ||
| assert.strictEqual(error.message, ERROR_400_MESSAGE); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| const assert = require('assert'); | ||
| const crypto = require('crypto'); | ||
| const { createClient, findWireMockRequest } = require('../utils/utils.js'); | ||
| const { | ||
| TEST_USER_ID, | ||
| TEST_EMAIL, | ||
| TEST_FIRST_NAME, | ||
| TEST_LAST_NAME, | ||
| TEST_NAME, | ||
| TEST_PROFILE_IMAGE_ID, | ||
| TEST_PROFILE_IMAGE_HEIGHT, | ||
| TEST_PROFILE_IMAGE_WIDTH, | ||
| TEST_SUCCESS_MESSAGE, | ||
| TEST_SUCCESS_RESULT_CODE, | ||
| ERROR_500_STATUS_CODE, | ||
| ERROR_500_MESSAGE, | ||
| ERROR_400_STATUS_CODE, | ||
| ERROR_400_MESSAGE | ||
| } = require('./common_test_constants.js'); | ||
|
|
||
| describe('Users - addProfileImage endpoint tests', function () { | ||
| let client = createClient(); | ||
| const imageId = TEST_PROFILE_IMAGE_ID; | ||
| const height = TEST_PROFILE_IMAGE_HEIGHT; | ||
| const width = TEST_PROFILE_IMAGE_WIDTH; | ||
| const email = TEST_EMAIL; | ||
| const name = TEST_NAME; | ||
| const firstName = TEST_FIRST_NAME; | ||
| const lastName = TEST_LAST_NAME; | ||
|
|
||
| it('addProfileImage generated url is correct', async function () { | ||
| const requestId = crypto.randomUUID(); | ||
| const mockImageBuffer = Buffer.from('fake-image-data'); | ||
| const options = { | ||
| userId: TEST_USER_ID, | ||
| body: { | ||
| file: mockImageBuffer | ||
| }, | ||
| customProperties: { | ||
| 'x-request-id': requestId, | ||
| 'x-test-name': '/users/add-profile-image/all-response-body-properties' | ||
| } | ||
| }; | ||
| await client.users.addProfileImage(options); | ||
| const matchedRequest = await findWireMockRequest(requestId); | ||
|
|
||
| assert.ok(matchedRequest.url.includes(`/users/${TEST_USER_ID}/profileimage`)); | ||
| }); | ||
|
|
||
| it('addProfileImage all response body properties', async function () { | ||
| const requestId = crypto.randomUUID(); | ||
| const mockImageBuffer = Buffer.from('fake-image-data'); | ||
| const options = { | ||
| userId: TEST_USER_ID, | ||
| body: { | ||
| file: mockImageBuffer | ||
| }, | ||
| customProperties: { | ||
| 'x-request-id': requestId, | ||
| 'x-test-name': '/users/add-profile-image/all-response-body-properties' | ||
| } | ||
| }; | ||
| const response = await client.users.addProfileImage(options); | ||
| const matchedRequest = await findWireMockRequest(requestId); | ||
|
|
||
| assert.ok(response); | ||
| assert.strictEqual(response.message, TEST_SUCCESS_MESSAGE); | ||
| assert.strictEqual(response.resultCode, TEST_SUCCESS_RESULT_CODE); | ||
| assert.ok(response.data); | ||
| assert.strictEqual(response.data.length, 1); | ||
| assert.strictEqual(response.data[0].id, TEST_USER_ID); | ||
| assert.strictEqual(response.data[0].email, email); | ||
| assert.strictEqual(response.data[0].name, name); | ||
| assert.strictEqual(response.data[0].firstName, firstName); | ||
| assert.strictEqual(response.data[0].lastName, lastName); | ||
| assert.ok(response.data[0].profileImage); | ||
| assert.strictEqual(response.data[0].profileImage.imageId, imageId); | ||
| assert.strictEqual(response.data[0].profileImage.height, height); | ||
| assert.strictEqual(response.data[0].profileImage.width, width); | ||
| assert.strictEqual(matchedRequest.body.includes('fake-image-data'), true); | ||
| }); | ||
|
|
||
| it('addProfileImage error 500 response', async function () { | ||
| const requestId = crypto.randomUUID(); | ||
| const mockImageBuffer = Buffer.from('fake-image-data'); | ||
| const options = { | ||
| userId: TEST_USER_ID, | ||
| body: { | ||
| file: mockImageBuffer | ||
| }, | ||
| customProperties: { | ||
| 'x-request-id': requestId, | ||
| 'x-test-name': '/errors/500-response' | ||
| } | ||
| }; | ||
| try { | ||
| await client.users.addProfileImage(options); | ||
| assert.fail('Expected an error to be thrown'); | ||
| } catch (error) { | ||
| assert.strictEqual(error.statusCode, ERROR_500_STATUS_CODE); | ||
| assert.strictEqual(error.message, ERROR_500_MESSAGE); | ||
| } | ||
| }); | ||
|
|
||
| it('addProfileImage error 400 response', async function () { | ||
| const requestId = crypto.randomUUID(); | ||
| const mockImageBuffer = Buffer.from('fake-image-data'); | ||
| const options = { | ||
| userId: TEST_USER_ID, | ||
| body: { | ||
| file: mockImageBuffer | ||
| }, | ||
| customProperties: { | ||
| 'x-request-id': requestId, | ||
| 'x-test-name': '/errors/400-response' | ||
| } | ||
| }; | ||
| try { | ||
| await client.users.addProfileImage(options); | ||
| assert.fail('Expected an error to be thrown'); | ||
| } catch (error) { | ||
| assert.strictEqual(error.statusCode, ERROR_400_STATUS_CODE); | ||
| assert.strictEqual(error.message, ERROR_400_MESSAGE); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.