Skip to content

Commit

Permalink
Added UserPilot adapter. #4
Browse files Browse the repository at this point in the history
  • Loading branch information
jezzsantos committed Jul 15, 2024
1 parent 460e3e6 commit f56162a
Show file tree
Hide file tree
Showing 14 changed files with 2,187 additions and 33 deletions.
63 changes: 34 additions & 29 deletions docs/how-to-guides/100-build-adapter-third-party.md

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/ApiHost1/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"SenderEmailAddress": "[email protected]",
"SenderDisplayName": "Support"
},
"EventNotifications": {
"SubscriptionName": "ApiHost1"
},
"SSOProvidersService": {
"SSOUserTokens": {
"AesSecret": "V7z5SZnhHRa7z68adsvazQjeIbSiWWcR+4KuAUikhe0=::u4ErEVotb170bM8qKWyT8A=="
Expand All @@ -36,8 +39,8 @@
"Gravatar": {
"BaseUrl": "https://localhost:5656/gravatar/"
},
"EventNotifications": {
"SubscriptionName": "ApiHost1"
"UserPilot": {
"BaseUrl": "https://localhost:5656/userpilot/"
}
},
"Hosts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
using Application.Interfaces;
using Application.Resources.Shared;
using Common.Configuration;
using Common.Recording;
using Domain.Interfaces;
using Infrastructure.Shared.ApplicationServices.External;
using IntegrationTesting.WebApi.Common;
using Microsoft.Extensions.DependencyInjection;
using UnitTesting.Common;
using Xunit;

namespace Infrastructure.Shared.IntegrationTests.ApplicationServices.External;

[Trait("Category", "Integration.External")]
[Collection("External")]
public class UserPilotHttpServiceClientSpec : ExternalApiSpec
{
private readonly UserPilotHttpServiceClient _serviceClient;

public UserPilotHttpServiceClientSpec(ExternalApiSetup setup) : base(setup, OverrideDependencies)
{
var settings = setup.GetRequiredService<IConfigurationSettings>();
_serviceClient = new UserPilotHttpServiceClient(NoOpRecorder.Instance, settings, new TestHttpClientFactory());
}

[Fact]
public async Task WhenDeliverAsyncWithNonIdentifiableEventByAnonymousUntenanted_ThenTracksEvent()
{
var result = await _serviceClient.DeliverAsync(new TestCaller(), CallerConstants.AnonymousUserId, "aneventname",
new Dictionary<string, string>
{
{ "aname", "avalue" }
});

result.Should().BeSuccess();
}

[Fact]
public async Task WhenDeliverAsyncWithNonIdentifiableEventByUserUntenanted_ThenTracksEvent()
{
var result = await _serviceClient.DeliverAsync(new TestCaller(), "user_1234567890123456789012", "aneventname",
new Dictionary<string, string>
{
{ "aname", "avalue" }
});

result.Should().BeSuccess();
}

[Fact]
public async Task WhenDeliverAsyncWithNonIdentifiableEventByAnonymousTenanted_ThenTracksEvent()
{
var result = await _serviceClient.DeliverAsync(new TestCaller("org_1234567890123456789012"),
CallerConstants.AnonymousUserId, "aneventname",
new Dictionary<string, string>
{
{ "aname", "avalue" }
});

result.Should().BeSuccess();
}

[Fact]
public async Task WhenDeliverAsyncWithNonIdentifiableEventByUserTenanted_ThenTracksEvent()
{
var result = await _serviceClient.DeliverAsync(new TestCaller("org_1234567890123456789012"),
"user_1234567890123456789012", "aneventname",
new Dictionary<string, string>
{
{ "aname", "avalue" }
});

result.Should().BeSuccess();
}

[Fact]
public async Task WhenDeliverAsyncWithUserLoginEvent_ThenIdentifiesAndTracks()
{
var result = await _serviceClient.DeliverAsync(new TestCaller(), "auserid",
UsageConstants.Events.UsageScenarios.Generic.UserLogin, new Dictionary<string, string>
{
{ UsageConstants.Properties.UserIdOverride, "user_1234567890123456789012" },
{ UsageConstants.Properties.AuthProvider, "credentials" },
{ UsageConstants.Properties.Name, "aperson" },
{ UsageConstants.Properties.EmailAddress, "[email protected]" },
{ UsageConstants.Properties.DefaultOrganizationId, "org_1234567890123456789012" }
});

result.Should().BeSuccess();
}

[Fact]
public async Task WhenDeliverAsyncWithOrganizationCreatedEvent_ThenIdentifiesAndTracks()
{
var result = await _serviceClient.DeliverAsync(new TestCaller(), "auserid",
UsageConstants.Events.UsageScenarios.Generic.OrganizationCreated, new Dictionary<string, string>
{
{ UsageConstants.Properties.Id, "org_1234567890123456789012" },
{ UsageConstants.Properties.Name, "anorganization" },
{ UsageConstants.Properties.Ownership, OrganizationOwnership.Shared.ToString() },
{ UsageConstants.Properties.CreatedById, "user_1234567890123456789012" },
{ UsageConstants.Properties.UserIdOverride, "user_1234567890123456789012" }
});

result.Should().BeSuccess();
}

[Fact]
public async Task WhenDeliverAsyncWithMembershipAddedEvent_ThenIdentifiesAndTracks()
{
var result = await _serviceClient.DeliverAsync(new TestCaller(), "auserid",
UsageConstants.Events.UsageScenarios.Generic.MembershipAdded, new Dictionary<string, string>
{
{ UsageConstants.Properties.Id, "membership_1234567890123456789012" },
{ UsageConstants.Properties.TenantIdOverride, "org_1234567890123456789012" },
{ UsageConstants.Properties.UserIdOverride, "user_1234567890123456789012" }
});

result.Should().BeSuccess();
}

[Fact]
public async Task WhenDeliverAsyncWithMembershipChangedEvent_ThenIdentifiesAndTracks()
{
var result = await _serviceClient.DeliverAsync(new TestCaller(), "auserid",
UsageConstants.Events.UsageScenarios.Generic.MembershipChanged, new Dictionary<string, string>
{
{ UsageConstants.Properties.Id, "membership_1234567890123456789012" },
{ UsageConstants.Properties.TenantIdOverride, "org_1234567890123456789012" },
{ UsageConstants.Properties.UserIdOverride, "user_1234567890123456789012" },
{ UsageConstants.Properties.Name, "aperson" },
{ UsageConstants.Properties.EmailAddress, "[email protected]" }
});

result.Should().BeSuccess();
}

private static void OverrideDependencies(IServiceCollection services)
{
//Do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
}
},
"Flagsmith": {
"TODO": "You need to provide settings to a real 'testingonly' instance of Flagsmith here, or in appsettings.Testing,local.json",
"BaseUrl": "https://edge.api.flagsmith.com/api/v1/",
"EnvironmentKey": "",
"TestingOnly": {
Expand All @@ -24,6 +25,10 @@
},
"Gravatar": {
"BaseUrl": "https://www.gravatar.com"
},
"UserPilot": {
"TODO": "You need to provide settings to a real 'testingonly' instance of UserPilot here, or in appsettings.Testing,local.json",
"BaseUrl": "https://analytex-eu.userpilot.io/v1"
}
}
}
Loading

0 comments on commit f56162a

Please sign in to comment.