diff --git a/src/management/__generated/managers/connections-manager.ts b/src/management/__generated/managers/connections-manager.ts index 0c122d5d7..125f4a760 100644 --- a/src/management/__generated/managers/connections-manager.ts +++ b/src/management/__generated/managers/connections-manager.ts @@ -5,13 +5,28 @@ import type { ConnectionCreate, ConnectionUpdate, GetConnections200Response, + GetDefaultMapping200Response, + GetScimConfiguration200Response, + GetScimTokens200ResponseInner, + PatchScimConfigurationRequest, + PostScimConfigurationRequest, + PostScimToken201Response, + PostScimTokenRequest, GetConnections200ResponseOneOf, DeleteConnectionsByIdRequest, + DeleteScimConfigurationRequest, + DeleteTokensByTokenIdRequest, DeleteUsersByEmailRequest, GetConnectionsRequest, GetConnectionsByIdRequest, + GetDefaultMappingRequest, + GetScimConfigurationRequest, + GetScimTokensRequest, GetStatusRequest, PatchConnectionsByIdRequest, + PatchScimConfigurationOperationRequest, + PostScimConfigurationOperationRequest, + PostScimTokenOperationRequest, } from '../models/index.js'; const { BaseAPI } = runtime; @@ -44,6 +59,59 @@ export class ConnectionsManager extends BaseAPI { return runtime.VoidApiResponse.fromResponse(response); } + /** + * Deletes a scim configuration by its connectionId. + * + * Delete a connection's SCIM configuration + * + * @throws {RequiredError} + */ + async deleteScimConfiguration( + requestParameters: DeleteScimConfigurationRequest, + initOverrides?: InitOverride + ): Promise> { + runtime.validateRequiredRequestParams(requestParameters, ['id']); + + const response = await this.request( + { + path: `/connections/{id}/scim-configuration`.replace( + '{id}', + encodeURIComponent(String(requestParameters.id)) + ), + method: 'DELETE', + }, + initOverrides + ); + + return runtime.VoidApiResponse.fromResponse(response); + } + + /** + * Deletes a scim token by its connection id and tokenId. + * + * Delete a connection's SCIM token + * + * @throws {RequiredError} + */ + async deleteScimToken( + requestParameters: DeleteTokensByTokenIdRequest, + initOverrides?: InitOverride + ): Promise> { + runtime.validateRequiredRequestParams(requestParameters, ['id', 'tokenId']); + + const response = await this.request( + { + path: `/connections/{id}/scim-configuration/tokens/{tokenId}` + .replace('{id}', encodeURIComponent(String(requestParameters.id))) + .replace('{tokenId}', encodeURIComponent(String(requestParameters.tokenId))), + method: 'DELETE', + }, + initOverrides + ); + + return runtime.VoidApiResponse.fromResponse(response); + } + /** * Deletes a specified connection user by its email (you cannot delete all users from specific connection). Currently, only Database Connections are supported. * @@ -204,6 +272,87 @@ export class ConnectionsManager extends BaseAPI { return runtime.JSONApiResponse.fromResponse(response); } + /** + * Retrieves a scim configuration's default mapping by its connectionId. + * + * Get a connection's default SCIM mapping + * + * @throws {RequiredError} + */ + async getDefaultScimMapping( + requestParameters: GetDefaultMappingRequest, + initOverrides?: InitOverride + ): Promise> { + runtime.validateRequiredRequestParams(requestParameters, ['id']); + + const response = await this.request( + { + path: `/connections/{id}/scim-configuration/default-mapping`.replace( + '{id}', + encodeURIComponent(String(requestParameters.id)) + ), + method: 'GET', + }, + initOverrides + ); + + return runtime.JSONApiResponse.fromResponse(response); + } + + /** + * Retrieves a scim configuration by its connectionId. + * + * Get a connection's SCIM configuration + * + * @throws {RequiredError} + */ + async getScimConfiguration( + requestParameters: GetScimConfigurationRequest, + initOverrides?: InitOverride + ): Promise> { + runtime.validateRequiredRequestParams(requestParameters, ['id']); + + const response = await this.request( + { + path: `/connections/{id}/scim-configuration`.replace( + '{id}', + encodeURIComponent(String(requestParameters.id)) + ), + method: 'GET', + }, + initOverrides + ); + + return runtime.JSONApiResponse.fromResponse(response); + } + + /** + * Retrieves all scim tokens by its connection id. + * + * Get a connection's SCIM tokens + * + * @throws {RequiredError} + */ + async getScimTokens( + requestParameters: GetScimTokensRequest, + initOverrides?: InitOverride + ): Promise>> { + runtime.validateRequiredRequestParams(requestParameters, ['id']); + + const response = await this.request( + { + path: `/connections/{id}/scim-configuration/tokens`.replace( + '{id}', + encodeURIComponent(String(requestParameters.id)) + ), + method: 'GET', + }, + initOverrides + ); + + return runtime.JSONApiResponse.fromResponse(response); + } + /** * Retrieves the status of an ad/ldap connection referenced by its ID. 200 OK http status code response is returned when the connection is online, otherwise a 404 status code is returned along with an error message * Check connection status @@ -261,6 +410,40 @@ export class ConnectionsManager extends BaseAPI { return runtime.JSONApiResponse.fromResponse(response); } + /** + * Update a scim configuration by its connectionId. + * + * Patch a connection's SCIM configuration + * + * @throws {RequiredError} + */ + async updateScimConfiguration( + requestParameters: PatchScimConfigurationOperationRequest, + bodyParameters: PatchScimConfigurationRequest, + initOverrides?: InitOverride + ): Promise> { + runtime.validateRequiredRequestParams(requestParameters, ['id']); + + const headerParameters: runtime.HTTPHeaders = {}; + + headerParameters['Content-Type'] = 'application/json'; + + const response = await this.request( + { + path: `/connections/{id}/scim-configuration`.replace( + '{id}', + encodeURIComponent(String(requestParameters.id)) + ), + method: 'PATCH', + headers: headerParameters, + body: bodyParameters, + }, + initOverrides + ); + + return runtime.JSONApiResponse.fromResponse(response); + } + /** * Creates a new connection according to the JSON object received in body. * @@ -288,4 +471,72 @@ export class ConnectionsManager extends BaseAPI { return runtime.JSONApiResponse.fromResponse(response); } + + /** + * Create a scim configuration for a connection. + * + * Create a SCIM configuration + * + * @throws {RequiredError} + */ + async createScimConfiguration( + requestParameters: PostScimConfigurationOperationRequest, + bodyParameters: PostScimConfigurationRequest | null, + initOverrides?: InitOverride + ): Promise> { + runtime.validateRequiredRequestParams(requestParameters, ['id']); + + const headerParameters: runtime.HTTPHeaders = {}; + + headerParameters['Content-Type'] = 'application/json'; + + const response = await this.request( + { + path: `/connections/{id}/scim-configuration`.replace( + '{id}', + encodeURIComponent(String(requestParameters.id)) + ), + method: 'POST', + headers: headerParameters, + body: bodyParameters, + }, + initOverrides + ); + + return runtime.JSONApiResponse.fromResponse(response); + } + + /** + * Create a scim token for a scim client. + * + * Create a SCIM Token + * + * @throws {RequiredError} + */ + async createScimToken( + requestParameters: PostScimTokenOperationRequest, + bodyParameters: PostScimTokenRequest, + initOverrides?: InitOverride + ): Promise> { + runtime.validateRequiredRequestParams(requestParameters, ['id']); + + const headerParameters: runtime.HTTPHeaders = {}; + + headerParameters['Content-Type'] = 'application/json'; + + const response = await this.request( + { + path: `/connections/{id}/scim-configuration/tokens`.replace( + '{id}', + encodeURIComponent(String(requestParameters.id)) + ), + method: 'POST', + headers: headerParameters, + body: bodyParameters, + }, + initOverrides + ); + + return runtime.JSONApiResponse.fromResponse(response); + } } diff --git a/src/management/__generated/models/index.ts b/src/management/__generated/models/index.ts index ab67e7b4d..58f8adac0 100644 --- a/src/management/__generated/models/index.ts +++ b/src/management/__generated/models/index.ts @@ -4766,6 +4766,16 @@ export const GetCredentials200ResponseInnerAlgEnum = { export type GetCredentials200ResponseInnerAlgEnum = (typeof GetCredentials200ResponseInnerAlgEnum)[keyof typeof GetCredentials200ResponseInnerAlgEnum]; +/** + * + */ +export interface GetDefaultMapping200Response { + /** + * The mapping between auth0 and SCIM + * + */ + mapping: Array; +} /** * */ @@ -6397,6 +6407,98 @@ export interface GetRulesConfigs200ResponseInner { */ key: string; } +/** + * + */ +export interface GetScimConfiguration200Response { + /** + * The connection's identifier + * + */ + connection_id: string; + /** + * The connection's identifier + * + */ + connection_name: string; + /** + * The connection's strategy + * + */ + strategy: string; + /** + * The tenant's name + * + */ + tenant_name: string; + /** + * User ID attribute for generating unique user ids + * + */ + user_id_attribute: string; + /** + * The mapping between auth0 and SCIM + * + */ + mapping: Array; + /** + * The Date Time Scim Configuration was created + * + */ + created_at: string; + /** + * The Date Time Scim Configuration was last updated + * + */ + updated_on: string; +} +/** + * + */ +export interface GetScimConfiguration200ResponseMappingInner { + [key: string]: any | any; + /** + * The field location in the auth0 schema + * + */ + auth0: string; + /** + * The field location in the SCIM schema + * + */ + scim: string; +} +/** + * + */ +export interface GetScimTokens200ResponseInner { + [key: string]: any | any; + /** + * The token's identifier + * + */ + token_id: string; + /** + * The scopes of the scim token + * + */ + scopes: Array; + /** + * The token's created at timestamp + * + */ + created_at: string; + /** + * The token's valid until timestamp + * + */ + valid_until: string; + /** + * The token's last used at timestamp + * + */ + last_used_at: string; +} /** * */ @@ -7721,6 +7823,21 @@ export interface PatchOrganizationsByIdRequestBranding { */ colors?: GetOrganizations200ResponseOneOfInnerBrandingColors; } +/** + * + */ +export interface PatchScimConfigurationRequest { + /** + * User ID attribute for generating unique user ids + * + */ + user_id_attribute: string; + /** + * The mapping between auth0 and SCIM + * + */ + mapping: Array; +} /** * */ @@ -9710,6 +9827,82 @@ export interface PostRoleUsersRequest { */ users: Array; } +/** + * + */ +export interface PostScimConfigurationRequest { + /** + * User ID attribute for generating unique user ids + * + */ + user_id_attribute?: string; + /** + * The mapping between auth0 and SCIM + * + */ + mapping?: Array; +} +/** + * + */ +export interface PostScimConfigurationRequestMappingInner { + [key: string]: any | any; + /** + * The field location in the auth0 schema + * + */ + auth0?: string; + /** + * The field location in the SCIM schema + * + */ + scim?: string; +} +/** + * + */ +export interface PostScimToken201Response { + /** + * The token's identifier + * + */ + token_id: string; + /** + * The scim client's token + * + */ + token: string; + /** + * The scopes of the scim token + * + */ + scopes: Array; + /** + * The token's created at timestamp + * + */ + created_at: string; + /** + * The token's valid until at timestamp + * + */ + valid_until: string; +} +/** + * SCIM Token + */ +export interface PostScimTokenRequest { + /** + * The scopes of the scim token + * + */ + scopes?: Array; + /** + * Lifetime of the token in seconds. Must be greater than 900 + * + */ + token_lifetime?: number | null; +} /** * */ @@ -12533,6 +12726,31 @@ export interface DeleteConnectionsByIdRequest { */ id: string; } +/** + * + */ +export interface DeleteScimConfigurationRequest { + /** + * The id of the connection to delete its SCIM configuration + * + */ + id: string; +} +/** + * + */ +export interface DeleteTokensByTokenIdRequest { + /** + * The connection id that owns the SCIM token to delete + * + */ + id: string; + /** + * The id of the scim token to delete + * + */ + tokenId: string; +} /** * */ @@ -12689,6 +12907,36 @@ export interface GetConnectionsByIdRequest { */ include_fields?: boolean; } +/** + * + */ +export interface GetDefaultMappingRequest { + /** + * The id of the connection to retrieve its default SCIM mapping + * + */ + id: string; +} +/** + * + */ +export interface GetScimConfigurationRequest { + /** + * The id of the connection to retrieve its SCIM configuration + * + */ + id: string; +} +/** + * + */ +export interface GetScimTokensRequest { + /** + * The id of the connection to retrieve its SCIM configuration + * + */ + id: string; +} /** * */ @@ -12709,6 +12957,36 @@ export interface PatchConnectionsByIdRequest { */ id: string; } +/** + * + */ +export interface PatchScimConfigurationOperationRequest { + /** + * The id of the connection to update its SCIM configuration + * + */ + id: string; +} +/** + * + */ +export interface PostScimConfigurationOperationRequest { + /** + * The id of the connection to create its SCIM configuration + * + */ + id: string; +} +/** + * + */ +export interface PostScimTokenOperationRequest { + /** + * The id of the connection to create its SCIM token + * + */ + id: string; +} /** * */ diff --git a/test/management/connections.test.ts b/test/management/connections.test.ts index 1e87eb017..debaab3a6 100644 --- a/test/management/connections.test.ts +++ b/test/management/connections.test.ts @@ -577,4 +577,664 @@ describe('ConnectionsManager', () => { }); }); }); + + describe('#createScimConfiguration', () => { + const connectionId = 'con_KYp633cmKtnEQ31C'; + const payload = { + mapping: [ + { + scim: 'userName', + auth0: 'username', + }, + { + scim: 'emails[primary eq true].value', + auth0: 'email', + }, + ], + user_id_attribute: 'externalId', + }; + + const response = { + connection_id: 'test_connection', + connection_name: 'Test Connection', + strategy: 'auth0', + tenant_name: 'test_connection_id', + user_id_attribute: 'externalId', + mapping: [ + { + scim: 'userName', + auth0: 'username', + }, + { + scim: 'emails[primary eq true].value', + auth0: 'email', + }, + ], + created_at: false, + updated_on: '25/06/2024', + }; + + let request: nock.Scope; + beforeEach(() => { + request = nock(API_URL) + .post(`/connections/${connectionId}/scim-configuration`, payload) + .reply(201, response); + }); + + it('should return a promise if no callback is given', (done) => { + connections + .createScimConfiguration({ id: connectionId }, payload) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should pass any errors to the promise catch handler', (done) => { + nock.cleanAll(); + nock(API_URL).post(`/connections/${connectionId}/scim-configuration`).reply(500, {}); + connections.createScimConfiguration({ id: connectionId }, payload).catch((err) => { + expect(err).toBeDefined(); + + done(); + }); + }); + + it('should perform a POST request to /api/v2/connections/${connectionId}/scim-configuration', (done) => { + connections.createScimConfiguration({ id: connectionId }, payload).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + + it('should pass the data in the body of the request', (done) => { + connections.createScimConfiguration({ id: connectionId }, payload).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + + it('should pass the body of the response to the "then" handler', (done) => { + nock.cleanAll(); + nock(API_URL).post(`/connections/${connectionId}/scim-configuration`).reply(201, response); + + connections.createScimConfiguration({ id: connectionId }, payload).then((connection) => { + expect(connection.data.connection_id).toBe(response.connection_id); + expect(connection.data.connection_name).toBe(response.connection_name); + expect(connection.data.strategy).toBe(response.strategy); + expect(connection.data.tenant_name).toBe(response.tenant_name); + expect(connection.data.user_id_attribute).toBe(response.user_id_attribute); + expect(connection.data.mapping).toStrictEqual(response.mapping); + expect(connection.data.created_at).toBe(response.created_at); + expect(connection.data.updated_on).toBe(response.updated_on); + + done(); + }); + }); + + it('should include the token in the Authorization header', (done) => { + nock.cleanAll(); + + const request = nock(API_URL) + .post(`/connections/${connectionId}/scim-configuration`) + .matchHeader('Authorization', `Bearer ${token}`) + .reply(201, response); + + connections.createScimConfiguration({ id: connectionId }, payload).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + }); + + describe('#updateScimConfiguration', () => { + const connectionId = 'con_KYp633cmKtnEQ31C'; + const payload = { + mapping: [ + { + scim: 'userName', + auth0: 'username', + }, + { + scim: 'emails[primary eq true].value', + auth0: 'email', + }, + ], + user_id_attribute: 'externalId', + }; + + const response = { + connection_id: 'test_connection', + connection_name: 'Test Connection', + strategy: 'auth0', + tenant_name: 'test_connection_id', + user_id_attribute: 'externalId', + mapping: [ + { + scim: 'userName', + auth0: 'username', + }, + { + scim: 'emails[primary eq true].value', + auth0: 'email', + }, + ], + created_at: false, + updated_on: '25/06/2024', + }; + + let request: nock.Scope; + beforeEach(() => { + request = nock(API_URL) + .patch(`/connections/${connectionId}/scim-configuration`, payload) + .reply(200, response); + }); + + it('should return a promise if no callback is given', (done) => { + connections + .updateScimConfiguration({ id: connectionId }, payload) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should pass any errors to the promise catch handler', (done) => { + nock.cleanAll(); + nock(API_URL).patch(`/connections/${connectionId}/scim-configuration`).reply(500, {}); + connections.updateScimConfiguration({ id: connectionId }, payload).catch((err) => { + expect(err).toBeDefined(); + + done(); + }); + }); + + it('should perform a PATCH request to /api/v2/connections/${connectionId}/scim-configuration', (done) => { + connections.updateScimConfiguration({ id: connectionId }, payload).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + + it('should pass the data in the body of the request', (done) => { + connections.updateScimConfiguration({ id: connectionId }, payload).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + + it('should pass the body of the response to the "then" handler', (done) => { + nock.cleanAll(); + nock(API_URL).patch(`/connections/${connectionId}/scim-configuration`).reply(200, response); + + connections.updateScimConfiguration({ id: connectionId }, payload).then((connection) => { + expect(connection.data.connection_id).toBe(response.connection_id); + expect(connection.data.connection_name).toBe(response.connection_name); + expect(connection.data.strategy).toBe(response.strategy); + expect(connection.data.tenant_name).toBe(response.tenant_name); + expect(connection.data.user_id_attribute).toBe(response.user_id_attribute); + expect(connection.data.mapping).toStrictEqual(response.mapping); + expect(connection.data.created_at).toBe(response.created_at); + expect(connection.data.updated_on).toBe(response.updated_on); + + done(); + }); + }); + + it('should include the token in the Authorization header', (done) => { + nock.cleanAll(); + + const request = nock(API_URL) + .patch(`/connections/${connectionId}/scim-configuration`) + .matchHeader('Authorization', `Bearer ${token}`) + .reply(200, response); + + connections.updateScimConfiguration({ id: connectionId }, payload).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + }); + + describe('#getScimConfiguration', () => { + const connectionId = 'con_KYp633cmKtnEQ31C'; + const response = { + connection_id: 'test_connection', + connection_name: 'Test Connection', + strategy: 'auth0', + tenant_name: 'test_connection_id', + user_id_attribute: 'externalId', + mapping: [ + { + scim: 'userName', + auth0: 'username', + }, + { + scim: 'emails[primary eq true].value', + auth0: 'email', + }, + ], + created_at: false, + updated_on: '25/06/2024', + }; + + let request: nock.Scope; + beforeEach(() => { + request = nock(API_URL) + .get(`/connections/${connectionId}/scim-configuration`) + .reply(200, response); + }); + + it('should return a promise if no callback is given', (done) => { + connections + .getScimConfiguration({ id: connectionId }) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should pass any errors to the promise catch handler', (done) => { + nock.cleanAll(); + nock(API_URL).get(`/connections/${connectionId}/scim-configuration`).reply(500, {}); + connections.getScimConfiguration({ id: connectionId }).catch((err) => { + expect(err).toBeDefined(); + + done(); + }); + }); + + it('should perform a GET request to /api/v2/connections/${connectionId}/scim-configuration', (done) => { + connections.getScimConfiguration({ id: connectionId }).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + + it('should pass the body of the response to the "then" handler', (done) => { + nock.cleanAll(); + nock(API_URL).get(`/connections/${connectionId}/scim-configuration`).reply(200, response); + + connections.getScimConfiguration({ id: connectionId }).then((connection) => { + expect(connection.data.connection_id).toBe(response.connection_id); + expect(connection.data.connection_name).toBe(response.connection_name); + expect(connection.data.strategy).toBe(response.strategy); + expect(connection.data.tenant_name).toBe(response.tenant_name); + expect(connection.data.user_id_attribute).toBe(response.user_id_attribute); + expect(connection.data.mapping).toStrictEqual(response.mapping); + expect(connection.data.created_at).toBe(response.created_at); + expect(connection.data.updated_on).toBe(response.updated_on); + + done(); + }); + }); + + it('should include the token in the Authorization header', (done) => { + nock.cleanAll(); + + const request = nock(API_URL) + .get(`/connections/${connectionId}/scim-configuration`) + .matchHeader('Authorization', `Bearer ${token}`) + .reply(200, response); + + connections.getScimConfiguration({ id: connectionId }).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + }); + + describe('#deleteScimConfiguration', () => { + const connectionId = 'con_KYp633cmKtnEQ31C'; + const response = {}; + + let request: nock.Scope; + beforeEach(() => { + request = nock(API_URL) + .delete(`/connections/${connectionId}/scim-configuration`) + .reply(204, {}); + }); + + it('should return a promise if no callback is given', (done) => { + connections + .deleteScimConfiguration({ id: connectionId }) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should pass any errors to the promise catch handler', (done) => { + nock.cleanAll(); + nock(API_URL).delete(`/connections/${connectionId}/scim-configuration`).reply(500, {}); + connections.deleteScimConfiguration({ id: connectionId }).catch((err) => { + expect(err).toBeDefined(); + + done(); + }); + }); + + it('should perform a DELETE request to /api/v2/connections/${connectionId}/scim-configuration', (done) => { + connections.deleteScimConfiguration({ id: connectionId }).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + + it('should include the token in the Authorization header', (done) => { + nock.cleanAll(); + + const request = nock(API_URL) + .delete(`/connections/${connectionId}/scim-configuration`) + .matchHeader('Authorization', `Bearer ${token}`) + .reply(200, response); + + connections.deleteScimConfiguration({ id: connectionId }).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + }); + + describe('#createScimToken', () => { + const connectionId = 'con_KYp633cmKtnEQ31C'; + const payload = { + scopes: ['get:users', 'post:users'], + token_lifetime: 950, + }; + + const response = { + token_id: 'tok_Gf3Q54Mjm88rifWy', + token: + 'tok_Gf3Q54Mjm88rifWy.1a76dccc1de257668e6f071b557ee282671ae31ed5c1d07c3a85262ce88e161a', + scopes: ['get:users', 'post:users'], + created_at: '2024-07-07T17:02:43.527Z', + valid_until: '2024-07-07T19:32:43.527Z', + }; + + let request: nock.Scope; + beforeEach(() => { + request = nock(API_URL) + .post(`/connections/${connectionId}/scim-configuration/tokens`, payload) + .reply(201, response); + }); + + it('should return a promise if no callback is given', (done) => { + connections + .createScimToken({ id: connectionId }, payload) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should pass any errors to the promise catch handler', (done) => { + nock.cleanAll(); + nock(API_URL).post(`/connections/${connectionId}/scim-configuration/tokens`).reply(500, {}); + connections.createScimToken({ id: connectionId }, payload).catch((err) => { + expect(err).toBeDefined(); + + done(); + }); + }); + + it('should perform a POST request to /api/v2/connections/${connectionId}/scim-configuration/tokens', (done) => { + connections.createScimToken({ id: connectionId }, payload).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + + it('should pass the data in the body of the request', (done) => { + connections.createScimToken({ id: connectionId }, payload).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + + it('should pass the body of the response to the "then" handler', (done) => { + nock.cleanAll(); + nock(API_URL) + .post(`/connections/${connectionId}/scim-configuration/tokens`) + .reply(201, response); + + connections.createScimToken({ id: connectionId }, payload).then((connection) => { + expect(connection.data.token_id).toBe(response.token_id); + expect(connection.data.token).toBe(response.token); + expect(connection.data.scopes).toStrictEqual(response.scopes); + expect(connection.data.created_at).toBe(response.created_at); + expect(connection.data.valid_until).toBe(response.valid_until); + + done(); + }); + }); + + it('should include the token in the Authorization header', (done) => { + nock.cleanAll(); + + const request = nock(API_URL) + .post(`/connections/${connectionId}/scim-configuration/tokens`) + .matchHeader('Authorization', `Bearer ${token}`) + .reply(201, response); + + connections.createScimToken({ id: connectionId }, payload).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + }); + + describe('#getScimTokens', () => { + const connectionId = 'con_KYp633cmKtnEQ31C'; + const response = [ + { + token_id: 'tok_WT39vSnAo4Xi4rrn', + created_at: '2024-07-07T17:02:41.622Z', + scopes: ['get:users', 'post:users'], + valid_until: '2024-07-07T19:32:41.622Z', + }, + { + token_id: 'tok_Gf3Q54Mjm88rifWy', + created_at: '2024-07-07T17:02:43.527Z', + scopes: ['get:users', 'post:users'], + valid_until: '2024-07-07T19:32:43.527Z', + }, + ]; + + let request: nock.Scope; + beforeEach(() => { + request = nock(API_URL) + .get(`/connections/${connectionId}/scim-configuration/tokens`) + .reply(200, response); + }); + + it('should return a promise if no callback is given', (done) => { + connections + .getScimTokens({ id: connectionId }) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should pass any errors to the promise catch handler', (done) => { + nock.cleanAll(); + nock(API_URL).get(`/connections/${connectionId}/scim-configuration/tokens`).reply(500, {}); + connections.getScimTokens({ id: connectionId }).catch((err) => { + expect(err).toBeDefined(); + + done(); + }); + }); + + it('should perform a GET request to /api/v2/connections/${connectionId}/scim-configuration/tokens', (done) => { + connections.getScimTokens({ id: connectionId }).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + + it('should pass the body of the response to the "then" handler', (done) => { + nock.cleanAll(); + nock(API_URL) + .get(`/connections/${connectionId}/scim-configuration/tokens`) + .reply(200, response); + + connections.getScimTokens({ id: connectionId }).then((connection) => { + expect(connection.data).toStrictEqual(response); + + done(); + }); + }); + + it('should include the token in the Authorization header', (done) => { + nock.cleanAll(); + + const request = nock(API_URL) + .get(`/connections/${connectionId}/scim-configuration/tokens`) + .matchHeader('Authorization', `Bearer ${token}`) + .reply(200, response); + + connections.getScimTokens({ id: connectionId }).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + }); + + describe('#deleteScimToken', () => { + const connectionId = 'con_KYp633cmKtnEQ31C'; + const tokenId = 'tok_WT39vSnAo4Xi4rrn'; + const response = {}; + + let request: nock.Scope; + beforeEach(() => { + request = nock(API_URL) + .delete(`/connections/${connectionId}/scim-configuration/tokens/${tokenId}`) + .reply(204, {}); + }); + + it('should return a promise if no callback is given', (done) => { + connections + .deleteScimToken({ id: connectionId, tokenId }) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should pass any errors to the promise catch handler', (done) => { + nock.cleanAll(); + nock(API_URL) + .delete(`/connections/${connectionId}/scim-configuration/tokens/${tokenId}`) + .reply(500, {}); + connections.deleteScimToken({ id: connectionId, tokenId }).catch((err) => { + expect(err).toBeDefined(); + + done(); + }); + }); + + it('should perform a DELETE request to /api/v2/connections/${connectionId}/scim-configuration/tokens/${tokenId}`', (done) => { + connections.deleteScimToken({ id: connectionId, tokenId }).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + + it('should include the token in the Authorization header', (done) => { + nock.cleanAll(); + + const request = nock(API_URL) + .delete(`/connections/${connectionId}/scim-configuration/tokens/${tokenId}`) + .matchHeader('Authorization', `Bearer ${token}`) + .reply(200, response); + + connections.deleteScimToken({ id: connectionId, tokenId }).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + }); + + describe('#getDefaultScimMapping', () => { + const connectionId = 'con_KYp633cmKtnEQ31C'; + const response = { + mapping: [ + { + auth0: 'preferred_username', + scim: 'userName', + }, + { + auth0: 'email', + scim: 'emails[primary eq true].value', + }, + ], + }; + + let request: nock.Scope; + beforeEach(() => { + request = nock(API_URL) + .get(`/connections/${connectionId}/scim-configuration/default-mapping`) + .reply(200, response); + }); + + it('should return a promise if no callback is given', (done) => { + connections + .getDefaultScimMapping({ id: connectionId }) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should pass any errors to the promise catch handler', (done) => { + nock.cleanAll(); + nock(API_URL) + .get(`/connections/${connectionId}/scim-configuration/default-mapping`) + .reply(500, {}); + connections.getDefaultScimMapping({ id: connectionId }).catch((err) => { + expect(err).toBeDefined(); + + done(); + }); + }); + + it('should perform a GET request to /api/v2/connections/${connectionId}/scim-configuration/tokens', (done) => { + connections.getDefaultScimMapping({ id: connectionId }).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + + it('should pass the body of the response to the "then" handler', (done) => { + nock.cleanAll(); + nock(API_URL) + .get(`/connections/${connectionId}/scim-configuration/default-mapping`) + .reply(200, response); + + connections.getDefaultScimMapping({ id: connectionId }).then((connection) => { + expect(connection.data).toStrictEqual(response); + + done(); + }); + }); + + it('should include the token in the Authorization header', (done) => { + nock.cleanAll(); + + const request = nock(API_URL) + .get(`/connections/${connectionId}/scim-configuration/default-mapping`) + .matchHeader('Authorization', `Bearer ${token}`) + .reply(200, response); + + connections.getDefaultScimMapping({ id: connectionId }).then(() => { + expect(request.isDone()).toBe(true); + + done(); + }); + }); + }); });