Skip to content

Commit 040402b

Browse files
Merge pull request #129 from smartsheet/add-upgrade-downgrade-tests
Add user upgrade and downgrade wiremock tests, refactor folder and file structure for User endpoints tests
2 parents 5abf211 + 0ac6ec7 commit 040402b

File tree

6 files changed

+476
-274
lines changed

6 files changed

+476
-274
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [4.8.0] - Unreleased
99
### Added
10-
- Wiremock integration tests for contract testing for GET /2.0/users/{userId}/plans and GET /2.0/users endpoints
10+
- WiremMock integration tests for contract testing for GET /2.0/users/{userId}/plans and GET /2.0/users endpoints
11+
- WireMock integration tests for contract testing for POST /2.0/users/{userId}/plans/{planId}/upgrade and POST /2.0/users/{userId}/plans/{planId}/downgrade
1112
### Updated
1213
- listAllUsers url generation
14+
- Folder structure for the Users related WireMock tests
1315

1416
## [4.7.0] - 2025-06-30
1517
### Added
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const TEST_USER_ID = 12345678;
2+
const TEST_PLAN_ID = 1234567890123456;
3+
const TEST_SUCCESS_MESSAGE = 'SUCCESS';
4+
const TEST_SUCCESS_RESULT_CODE = 0;
5+
6+
module.exports = {
7+
TEST_USER_ID,
8+
TEST_PLAN_ID,
9+
TEST_SUCCESS_MESSAGE,
10+
TEST_SUCCESS_RESULT_CODE
11+
};
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
const assert = require('assert');
2+
const crypto = require('crypto');
3+
const { createClient, findWireMockRequest } = require('../utils/utils.js');
4+
const { TEST_USER_ID, TEST_PLAN_ID } = require('./common_test_constants.js');
5+
6+
describe('Users - listUserPlans endpoint tests', function () {
7+
const client = createClient();
8+
const lastKey = '12345678901234569';
9+
const maxItems = 100;
10+
const seatType = 'MEMBER';
11+
const seatTypeLastChangedAt = '2025-01-01T00:00:00.123456789Z';
12+
const provisionalExpirationDate = '2026-12-13T12:17:52.525696Z';
13+
const isInternalTrue = false;
14+
15+
it('listUserPlans generated url is correct', async function () {
16+
const requestId = crypto.randomUUID();
17+
const options = {
18+
userId: TEST_USER_ID,
19+
queryParameters: {
20+
lastKey: lastKey,
21+
maxItems: maxItems
22+
},
23+
customProperties: {
24+
'x-request-id': requestId,
25+
'x-test-name': '/users/list-user-plans/all-response-body-properties'
26+
}
27+
};
28+
await client.users.listUserPlans(options);
29+
const matchedRequest = await findWireMockRequest(requestId);
30+
const queryParams = matchedRequest.queryParams;
31+
const lastKeyActual = queryParams.lastKey.values[0];
32+
const maxItemsActual = parseInt(queryParams.maxItems.values[0]);
33+
34+
assert.ok(matchedRequest.url.includes(`/users/${TEST_USER_ID}/plans`));
35+
assert.strictEqual(lastKeyActual, lastKey);
36+
assert.strictEqual(maxItemsActual, maxItems);
37+
});
38+
39+
it('listUserPlans all response body properties', async function () {
40+
const requestId = crypto.randomUUID();
41+
const options = {
42+
userId: TEST_USER_ID,
43+
queryParameters: {
44+
lastKey: lastKey,
45+
maxItems: maxItems
46+
},
47+
customProperties: {
48+
'x-request-id': requestId,
49+
'x-test-name': '/users/list-user-plans/all-response-body-properties'
50+
}
51+
};
52+
const response = await client.users.listUserPlans(options);
53+
54+
assert.ok(response);
55+
assert.strictEqual(response.lastKey, lastKey);
56+
assert.strictEqual(response.data[0].planId, TEST_PLAN_ID);
57+
assert.strictEqual(response.data[0].seatType, seatType);
58+
assert.strictEqual(response.data[0].seatTypeLastChangedAt, seatTypeLastChangedAt);
59+
assert.strictEqual(response.data[0].provisionalExpirationDate, provisionalExpirationDate);
60+
assert.strictEqual(response.data[0].isInternal, isInternalTrue);
61+
});
62+
63+
it('listUserPlans required response body properties', async function () {
64+
const requestId = crypto.randomUUID();
65+
const options = {
66+
userId: TEST_USER_ID,
67+
customProperties: {
68+
'x-request-id': requestId,
69+
'x-test-name': '/users/list-user-plans/required-response-body-properties'
70+
}
71+
};
72+
const response = await client.users.listUserPlans(options);
73+
74+
assert.ok(response);
75+
assert.strictEqual(response.data[0].planId, TEST_PLAN_ID);
76+
assert.strictEqual(response.data[0].seatType, seatType);
77+
assert.strictEqual(response.data[0].seatTypeLastChangedAt, undefined);
78+
assert.strictEqual(response.data[0].provisionalExpirationDate, undefined);
79+
assert.strictEqual(response.data[0].isInternal, isInternalTrue);
80+
});
81+
82+
it('listUserPlans error 500 response', async function () {
83+
const requestId = crypto.randomUUID();
84+
const options = {
85+
userId: TEST_USER_ID,
86+
customProperties: {
87+
'x-request-id': requestId,
88+
'x-test-name': '/errors/500-response'
89+
}
90+
};
91+
try {
92+
await client.users.listUserPlans(options);
93+
assert.fail('Expected an error to be thrown');
94+
} catch (error) {
95+
assert.strictEqual(error.statusCode, 500);
96+
assert.strictEqual(error.message, 'Internal Server Error');
97+
}
98+
});
99+
100+
it('listUserPlans error 400 response', async function () {
101+
const requestId = crypto.randomUUID();
102+
const options = {
103+
userId: TEST_USER_ID,
104+
customProperties: {
105+
'x-request-id': requestId,
106+
'x-test-name': '/errors/400-response'
107+
}
108+
};
109+
try {
110+
await client.users.listUserPlans(options);
111+
assert.fail('Expected an error to be thrown');
112+
} catch (error) {
113+
assert.strictEqual(error.statusCode, 400);
114+
assert.strictEqual(error.message, 'Malformed Request');
115+
}
116+
});
117+
});
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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

Comments
 (0)