Skip to content

Commit

Permalink
Fixed queue jobs title
Browse files Browse the repository at this point in the history
  • Loading branch information
joaofx committed Nov 8, 2023
1 parent 25689a9 commit ae21f4d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
22 changes: 18 additions & 4 deletions src/Miru/FeatureInfo.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Miru.Mailing;

namespace Miru;

Expand Down Expand Up @@ -54,11 +55,19 @@ public string GetIdsQueryString()

var properties = Instance.GetType().GetProperties();

foreach (var property in properties)
if (Instance is EmailJob emailJob)
{
if (property.Name.EndsWith("Id") && property.PropertyType == typeof(long))
propertyValues.Add("Subject", emailJob.Email.Subject);
propertyValues.Add("To", emailJob.Email.ToAddresses.Join(","));
}
else
{
foreach (var property in properties)
{
propertyValues[property.Name] = property.GetValue(Instance);
if (property.Name.EndsWith("Id") && property.PropertyType == typeof(long))
{
propertyValues[property.Name] = property.GetValue(Instance);
}
}
}

Expand All @@ -85,8 +94,13 @@ public string GetIdsProperties()
public string GetTitle()
{
var name = GetName();

var queryString = GetIdsQueryString();

if (string.IsNullOrEmpty(queryString))
return name;

return $"{name}?{GetIdsQueryString()}";
return $"{name}?{queryString}";
}

public string GetName()
Expand Down
8 changes: 8 additions & 0 deletions tests/Miru.Tests/FeatureInfoTest.cs
Expand Up @@ -38,6 +38,10 @@ public void Should_return_title_with_class_name_and_ids_query_string()
new FeatureInfo(new ShipmentDelivered { ShipmentId = 456, OrderId = 789 })
.GetTitle()
.ShouldBe("ShipmentDelivered?ShipmentId=456&OrderId=789");

new FeatureInfo(new OrderClean())
.GetTitle()
.ShouldBe("OrderClean");
}

[Test]
Expand All @@ -49,6 +53,10 @@ public void Should_return_feature_group()
}
}

public class OrderClean : IBaseRequest
{
}

public class OrderPurge : IBaseRequest
{
public long OrderId { get; set; }
Expand Down
27 changes: 27 additions & 0 deletions tests/Miru.Tests/Mailing/EmailJobTest.cs
@@ -0,0 +1,27 @@
using FluentEmail.Core.Models;
using FluentValidation;
using Miru.Mailing;
using Miru.Storages;

namespace Miru.Tests.Mailing;

[TestFixture]
public class EmailJobTest
{
public class Getting_job_title
{
[Test]
public void Should_return_subject_and_recipient()
{
new FeatureInfo(
new EmailJob(
new Email()
{
Subject = "Welcome",
ToAddresses = new[] { new Address("bill@gates.com") }
}))
.GetTitle()
.ShouldBe("EmailJob?Subject=Welcome&To=bill@gates.com");
}
}
}
2 changes: 1 addition & 1 deletion tests/Miru.Tests/Queuing/QueueingTest.cs
Expand Up @@ -9,7 +9,7 @@

namespace Miru.Tests.Queuing;

[Ignore("WIP")]
// [Ignore("WIP")]
public class QueueingTest : MiruCoreTest
{
private BackgroundJobServer _server;
Expand Down

0 comments on commit ae21f4d

Please sign in to comment.