Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class IntegrationTemplateContext(EventMessage eventMessage)

public string DomainName => Event.DomainName;
public string IpAddress => Event.IpAddress;
public DeviceType? DeviceType => Event.DeviceType;
public string? DeviceType => Event.DeviceType?.GetDisplayName();
public int? DeviceTypeId => Event.DeviceType is not null ? (int)Event.DeviceType : null;
public Guid? ActingUserId => Event.ActingUserId;
public Guid? OrganizationUserId => Event.OrganizationUserId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text.Json;
using Bit.Core.AdminConsole.Entities;
using Bit.Core.Dirt.Models.Data.EventIntegrations;
using Bit.Core.Enums;
using Bit.Core.Models.Data;
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
using Bit.Test.Common.AutoFixture.Attributes;
Expand Down Expand Up @@ -34,6 +35,43 @@ public void DateIso8601_ReturnsIso8601FormattedDate(EventMessage eventMessage)
Assert.True(DateTime.TryParse(result, out _));
}

[Theory, BitAutoData]
public void DeviceType_WhenSet_ReturnsDisplayName(EventMessage eventMessage)
{
eventMessage.DeviceType = DeviceType.ChromeExtension;
var sut = new IntegrationTemplateContext(eventMessage);

// Display name from [Display(Name = "...")], not the enum member identifier "ChromeExtension"
Assert.Equal("Chrome Extension", sut.DeviceType);
}

[Theory, BitAutoData]
public void DeviceType_WhenNull_ReturnsNull(EventMessage eventMessage)
{
eventMessage.DeviceType = null;
var sut = new IntegrationTemplateContext(eventMessage);

Assert.Null(sut.DeviceType);
}

[Theory, BitAutoData]
public void DeviceTypeId_WhenSet_ReturnsNumericValue(EventMessage eventMessage)
{
eventMessage.DeviceType = DeviceType.ChromeExtension;
var sut = new IntegrationTemplateContext(eventMessage);

Assert.Equal((int)DeviceType.ChromeExtension, sut.DeviceTypeId);
}

[Theory, BitAutoData]
public void DeviceTypeId_WhenNull_ReturnsNull(EventMessage eventMessage)
{
eventMessage.DeviceType = null;
var sut = new IntegrationTemplateContext(eventMessage);

Assert.Null(sut.DeviceTypeId);
}

[Theory, BitAutoData]
public void UserName_WhenUserIsSet_ReturnsName(EventMessage eventMessage, OrganizationUserUserDetails user)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
๏ปฟ#nullable enable

Check failure on line 1 in test/Core.Test/Dirt/Services/EventIntegrationHandlerTests.cs

View workflow job for this annotation

GitHub Actions / Lint

Fix imports ordering.

using System.Text.Json;
using System.Text.Json.Nodes;
Expand All @@ -6,6 +6,7 @@
using Bit.Core.AdminConsole.Repositories;
using Bit.Core.Dirt.Enums;
using Bit.Core.Dirt.Models.Data.EventIntegrations;
using Bit.Core.Enums;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Dirt.Services;
using Bit.Core.Dirt.Services.Implementations;
Expand Down Expand Up @@ -773,7 +774,7 @@
""actingUserId"": ""{eventMessage.ActingUserId}"",
""installationId"": ""{eventMessage.InstallationId}"",
""date"": ""{eventMessage.Date.ToString("o")}"",
""deviceType"": ""{eventMessage.DeviceType}"",
""deviceType"": ""{eventMessage.DeviceType?.GetDisplayName()}"",
""deviceTypeId"": ""{deviceTypeId}"",
""ipAddress"": ""{eventMessage.IpAddress}"",
""systemUser"": ""{systemUser}"",
Expand Down
Loading