Skip to content
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

Fix test cases failing due to Hooks and Rules becoming Read-Only #748

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 25 additions & 60 deletions tests/Auth0.ManagementApi.IntegrationTests/HooksTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Auth0.ManagementApi.Paging;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;

namespace Auth0.ManagementApi.IntegrationTests
{
Expand All @@ -34,59 +35,36 @@ public HooksTests(HooksTestsFixture fixture)
this.fixture = fixture;
}

/// <summary>
/// Hooks are deprecated as on 18th November 2024.
/// All the existing hooks can still be accessed in a read-only mode.
/// The users can delete an existing hook OR update an existing hook to
/// only enable/disable it (None of the other properties can be updated).
/// Modifying the below test case to work with the existing hooks.
/// </summary>
[Fact]
public async Task Test_hooks_crud_sequence()
{
// Get all hooks
var hooksBefore = await fixture.ApiClient.Hooks.GetAllAsync(new GetHooksRequest(), new PaginationInfo());
var existingHook = (await fixture.ApiClient.Hooks.GetAllAsync(new GetHooksRequest(), new PaginationInfo())).FirstOrDefault();

// Add a new hook
var newHookRequest = new HookCreateRequest()
{
Name = $"{TestingConstants.HooksPrefix}-{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 fixture.ApiClient.Hooks.CreateAsync(newHookRequest);

fixture.TrackIdentifier(CleanUpType.Hooks, newHookResponse.Id);
existingHook.Should().NotBeNull();

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 fixture.ApiClient.Hooks.GetAllAsync(new GetHooksRequest(), new PaginationInfo());
hooksAfter.Count.Should().Be(hooksBefore.Count + 1);

// Update the Hook
// Update the Hook - Disable the hook
var updateHookRequest = new HookUpdateRequest
{
Name = $"{TestingConstants.HooksPrefix}-2-{Guid.NewGuid():N}",
Enabled = true
Enabled = false
};
var updateHookResponse = await fixture.ApiClient.Hooks.UpdateAsync(newHookResponse.Id, updateHookRequest);

var updateHookResponse = await fixture.ApiClient.Hooks.UpdateAsync(existingHook.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($"{TestingConstants.HooksPrefix}-2-".ToLower()).Should().BeTrue();
updateHookResponse.Enabled.Should().BeTrue();
updateHookResponse.Enabled.Should().BeFalse();
updateHookResponse.Id.Should().Be(existingHook.Id);

// Get a single hook
var hook = await fixture.ApiClient.Hooks.GetAsync(newHookResponse.Id);
var hook = await fixture.ApiClient.Hooks.GetAsync(existingHook.Id);
hook.Should().NotBeNull();
hook.Name.StartsWith($"{TestingConstants.HooksPrefix}-2").Should().BeTrue();
hook.Enabled.Should().BeTrue();

// Delete the hook, and ensure we get exception when trying to fetch it again
await fixture.ApiClient.Hooks.DeleteAsync(hook.Id);
Func<Task> getFunc = async () => await fixture.ApiClient.Hooks.GetAsync(hook.Id);
getFunc.Should().Throw<ErrorApiException>().And.ApiError.ErrorCode.Should().Be("HookDoesNotExist");

fixture.UnTrackIdentifier(CleanUpType.Hooks, newHookResponse.Id);
hook.Enabled.Should().BeFalse();
}

[Fact]
Expand Down Expand Up @@ -119,34 +97,21 @@ public async Task Test_paging_includes_totals()
Assert.NotNull(hooks.Paging);
}

/// <summary>
/// Hooks are deprecated as on 18th November 2024.
/// All the existing hooks can still be accessed in a read-only mode.
/// The users can delete an existing hook OR update an existing hook to
/// only enable/disable it (None of the other properties can be updated).
/// Modifying the below test case to work with the existing hooks.
/// </summary>
[Fact]
public async Task Test_without_paging()
{
// Add a new hook
var newHook = await fixture.ApiClient.Hooks.CreateAsync(new HookCreateRequest()
{
Name = $"{TestingConstants.HooksPrefix}-{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"
});

fixture.TrackIdentifier(CleanUpType.Hooks, newHook.Id);

newHook.Should().NotBeNull();

// Act
var hooks = await fixture.ApiClient.Hooks.GetAllAsync(new GetHooksRequest());

hooks.Paging.Should().BeNull();
hooks.Count.Should().BeGreaterThan(0);

await fixture.ApiClient.Hooks.DeleteAsync(newHook.Id);

fixture.UnTrackIdentifier(CleanUpType.Hooks, newHook.Id);
}
}
}
4 changes: 2 additions & 2 deletions tests/Auth0.ManagementApi.IntegrationTests/RulesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public RulesTests(RulesTestsFixture fixture)
this.fixture = fixture;
}

[Fact]
[Fact(Skip = "Rules have been deprecated as on 18th November 2024")]
public async Task Test_rules_crud_sequence()
{
// Get all rules
Expand Down Expand Up @@ -111,7 +111,7 @@ public async Task Test_paging_includes_totals()
Assert.NotNull(rules.Paging);
}

[Fact]
[Fact(Skip = "Rules have been deprecated as on 18th November 2024")]
public async Task Test_without_paging()
{
// Add a new rule
Expand Down
Loading