Beispiel #1
0
        public async Task Test_hooks_crud_sequence()
        {
            // Get all hooks
            var hooksBefore = await _apiClient.Hooks.GetAllAsync(new GetHooksRequest(), new PaginationInfo());

            // Add a new hook
            var newHookRequest = new HookCreateRequest()
            {
                Name         = $"integration-test-hook-{Guid.NewGuid():N}",
                Script       = @"module.exports = function(client, scope, audience, context, callback) { {
                              // TODO: implement your hook
                              callback(null, context);
                            }",
                Dependencies = JObject.Parse("{ \"auth0\": \"2.32.0\"}"),
                TriggerId    = "credentials-exchange"
            };
            var newHookResponse = await _apiClient.Hooks.CreateAsync(newHookRequest);

            newHookResponse.Should().NotBeNull();
            Assert.True(JObject.DeepEquals(newHookRequest.Dependencies, newHookResponse.Dependencies));

            // Get all the hooks again, and check that we now have one more
            var hooksAfter = await _apiClient.Hooks.GetAllAsync(new GetHooksRequest(), new PaginationInfo());

            hooksAfter.Count.Should().Be(hooksBefore.Count + 1);

            // Update the Hook
            var updateHookRequest = new HookUpdateRequest
            {
                Name    = $"integration-test-hook-2-{Guid.NewGuid():N}",
                Enabled = true
            };
            var updateHookResponse = await _apiClient.Hooks.UpdateAsync(newHookResponse.Id, updateHookRequest);

            updateHookResponse.Should().NotBeNull();
            // Because the Hooks endpoint changes the name of a Hook when using a Guid in the name,
            // we can only verify the name starts with the part without the Guid.
            updateHookResponse.Name.StartsWith("integration-test-hook-2-").Should().BeTrue();
            updateHookResponse.Enabled.Should().BeTrue();

            // Get a single hook
            var hook = await _apiClient.Hooks.GetAsync(newHookResponse.Id);

            hook.Should().NotBeNull();
            hook.Name.StartsWith("integration-test-hook-2").Should().BeTrue();
            hook.Enabled.Should().BeTrue();

            // Delete the hook, and ensure we get exception when trying to fetch it again
            await _apiClient.Hooks.DeleteAsync(hook.Id);

            Func <Task> getFunc = async() => await _apiClient.Hooks.GetAsync(hook.Id);

            getFunc.Should().Throw <ErrorApiException>().And.ApiError.ErrorCode.Should().Be("HookDoesNotExist");
        }
Beispiel #2
0
 /// <summary>
 /// Updates a hook.
 /// </summary>
 /// <param name="id">The ID of the hook to update.</param>
 /// <param name="request">A <see cref="HookUpdateRequest" /> containing the information to update.</param>
 /// <returns>The newly updated <see cref="Hook"/>.</returns>
 public Task <Hook> UpdateAsync(string id, HookUpdateRequest request)
 {
     return(Connection.SendAsync <Hook>(new HttpMethod("PATCH"), BuildUri($"hooks/{EncodePath(id)}"), request, DefaultHeaders));
 }
Beispiel #3
0
 void UpdateHook(string id, HookUpdateRequest request);