Skip to content

Commit fe63ccf

Browse files
committed
Added test cases
1 parent 9874be8 commit fe63ccf

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed

src/management/__generated/managers/users-manager.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as runtime from '../../../lib/runtime.js';
22
import type { InitOverride, ApiResponse } from '../../../lib/runtime.js';
33
import type {
4+
ClearAssessorsRequestContent,
45
DeletePermissionsRequest,
56
DeleteUserIdentityByUserId200ResponseInner,
67
DeleteUserRolesRequest,
@@ -64,6 +65,7 @@ import type {
6465
PatchAuthenticationMethodsByAuthenticationMethodIdOperationRequest,
6566
PatchUsersByIdRequest,
6667
PostAuthenticationMethodsOperationRequest,
68+
PostClearAssessorsRequest,
6769
PostIdentitiesOperationRequest,
6870
PostInvalidateRememberBrowserRequest,
6971
PostPermissionsOperationRequest,
@@ -1069,6 +1071,38 @@ export class UsersManager extends BaseAPI {
10691071
return runtime.JSONApiResponse.fromResponse(response);
10701072
}
10711073

1074+
/**
1075+
* Clear risk assessment assessors for a specific user
1076+
*
1077+
* @throws {RequiredError}
1078+
*/
1079+
async clearRiskAssessors(
1080+
requestParameters: PostClearAssessorsRequest,
1081+
bodyParameters: ClearAssessorsRequestContent,
1082+
initOverrides?: InitOverride
1083+
): Promise<ApiResponse<void>> {
1084+
runtime.validateRequiredRequestParams(requestParameters, ['id']);
1085+
1086+
const headerParameters: runtime.HTTPHeaders = {};
1087+
1088+
headerParameters['Content-Type'] = 'application/json';
1089+
1090+
const response = await this.request(
1091+
{
1092+
path: `/users/{id}/risk-assessments/clear`.replace(
1093+
'{id}',
1094+
encodeURIComponent(String(requestParameters.id))
1095+
),
1096+
method: 'POST',
1097+
headers: headerParameters,
1098+
body: bodyParameters,
1099+
},
1100+
initOverrides
1101+
);
1102+
1103+
return runtime.VoidApiResponse.fromResponse(response);
1104+
}
1105+
10721106
/**
10731107
* Link two user accounts together forming a primary and secondary relationship. On successful linking, the endpoint returns the new array of the primary account identities.
10741108
*

src/management/__generated/models/index.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ export interface ActionsDraftUpdate {
88
*/
99
update_draft?: boolean;
1010
}
11+
12+
/**
13+
*
14+
*/
15+
export const AssessorsTypeEnum = {
16+
new_device: 'new-device',
17+
} as const;
18+
export type AssessorsTypeEnum = (typeof AssessorsTypeEnum)[keyof typeof AssessorsTypeEnum];
19+
1120
/**
1221
* Certificate information. This object is relevant only for Custom Domains with Auth0-Managed Certificates.
1322
*/
@@ -50,6 +59,21 @@ export const CertificateCertificateAuthorityEnum = {
5059
export type CertificateCertificateAuthorityEnum =
5160
(typeof CertificateCertificateAuthorityEnum)[keyof typeof CertificateCertificateAuthorityEnum];
5261

62+
/**
63+
*
64+
*/
65+
export interface ClearAssessorsRequestContent {
66+
/**
67+
* The name of the connection containing the user whose assessors should be cleared.
68+
*
69+
*/
70+
connection: string;
71+
/**
72+
* List of assessors to clear.
73+
*
74+
*/
75+
assessors: Array<AssessorsTypeEnum>;
76+
}
5377
/**
5478
*
5579
*/
@@ -23062,6 +23086,16 @@ export interface PostAuthenticationMethodsOperationRequest {
2306223086
*/
2306323087
id: string;
2306423088
}
23089+
/**
23090+
*
23091+
*/
23092+
export interface PostClearAssessorsRequest {
23093+
/**
23094+
* ID of the user to clear assessors for.
23095+
*
23096+
*/
23097+
id: string;
23098+
}
2306523099
/**
2306623100
*
2306723101
*/
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {
2+
RiskAssessmentsManager,
3+
ManagementClient,
4+
UpdateRiskAssessmentsSettingsRequestContent,
5+
UpdateRiskAssessmentsSettingsNewDeviceRequestContent,
6+
} from '../../src/index.js';
7+
8+
import { checkMethod } from './tests.util.js';
9+
10+
const DOMAIN = `tenant.auth0.com`;
11+
const token = 'TOKEN';
12+
13+
describe('RiskAssessmentsManager', () => {
14+
const riskAssessmentsManager: RiskAssessmentsManager = new ManagementClient({
15+
domain: DOMAIN,
16+
token,
17+
}).riskAssessments;
18+
19+
describe('getSetting', () => {
20+
const operation = riskAssessmentsManager.getSettings();
21+
const uri = `/risk-assessments/settings`;
22+
const method = 'get';
23+
24+
checkMethod({ operation, uri, method });
25+
});
26+
27+
describe('updateSettings', () => {
28+
const requestBody: UpdateRiskAssessmentsSettingsRequestContent = {
29+
enabled: true,
30+
};
31+
const operation = riskAssessmentsManager.updateSettings(requestBody);
32+
const uri = `/risk-assessments/settings`;
33+
const method = 'patch';
34+
35+
checkMethod({ operation, uri, method });
36+
});
37+
38+
describe('getNewDeviceSettings', () => {
39+
const operation = riskAssessmentsManager.getNewDeviceSettings();
40+
const uri = `/risk-assessments/settings/new-device`;
41+
const method = 'get';
42+
43+
checkMethod({ operation, uri, method });
44+
});
45+
46+
describe('updateNewDeviceSettings', () => {
47+
const requestParameters: UpdateRiskAssessmentsSettingsNewDeviceRequestContent = {
48+
remember_for: 10,
49+
};
50+
const operation = riskAssessmentsManager.updateNewDeviceSettings(requestParameters);
51+
const uri = `/risk-assessments/settings/new-device`;
52+
const method = 'patch';
53+
54+
checkMethod({ operation, uri, method });
55+
});
56+
});

test/management/users.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
DeleteMultifactorByProviderProviderEnum,
1111
ManagementClient,
1212
RequiredError,
13+
ClearAssessorsRequestContent,
1314
} from '../../src/index.js';
1415

1516
describe('UsersManager', () => {
@@ -1675,4 +1676,55 @@ describe('UsersManager', () => {
16751676
expect(request.isDone()).toBe(true);
16761677
});
16771678
});
1679+
describe('#clearRiskAssessors', () => {
1680+
const data = {
1681+
id: 'USER_ID',
1682+
};
1683+
1684+
const body: ClearAssessorsRequestContent = {
1685+
connection: 'CONNECTION_ID',
1686+
assessors: ['new-device'],
1687+
};
1688+
1689+
let scope: nock.Scope;
1690+
1691+
beforeEach(() => {
1692+
scope = nock(API_URL).post(`/users/${data.id}/risk-assessments/clear`).reply(200, {});
1693+
});
1694+
1695+
it('should return a promise if no callback is given', (done) => {
1696+
expect(usersManager.clearRiskAssessors(data, body).then(() => done())).toBeInstanceOf(
1697+
Promise
1698+
);
1699+
});
1700+
1701+
it('should pass any errors to the promise catch handler', async () => {
1702+
nock.cleanAll();
1703+
1704+
nock(API_URL).post(`/users/${data.id}/risk-assessments/clear`).reply(500, {});
1705+
1706+
try {
1707+
await usersManager.clearRiskAssessors(data, body);
1708+
} catch (err) {
1709+
expect(err).toBeDefined();
1710+
}
1711+
});
1712+
1713+
it('should perform a POST request to /api/v2/users/:id/risk-assessments/clear', async () => {
1714+
await usersManager.clearRiskAssessors(data, body);
1715+
expect(scope.isDone()).toBe(true);
1716+
});
1717+
1718+
it('should include the token in the Authorization header', async () => {
1719+
nock.cleanAll();
1720+
1721+
const request = nock(API_URL)
1722+
.post(`/users/${data.id}/risk-assessments/clear`)
1723+
.matchHeader('Authorization', `Bearer ${token}`)
1724+
.reply(200, {});
1725+
1726+
await usersManager.clearRiskAssessors(data, body);
1727+
expect(request.isDone()).toBe(true);
1728+
});
1729+
});
16781730
});

0 commit comments

Comments
 (0)