-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: In App Message Template is Rendered for Email Step while fetchin…
…g workflow data #90
- Loading branch information
todd
committed
Feb 9, 2025
1 parent
287f592
commit 772570f
Showing
3 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
src/Novu.Tests/MicroTests/JsonConverters/MessageTemplateConverterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using FluentAssertions; | ||
using Newtonsoft.Json; | ||
using Novu.Domain.JsonConverters; | ||
using Novu.Domain.Models.Workflows.Step.Message; | ||
using Xunit; | ||
|
||
namespace Novu.Tests.MicroTests.JsonConverters; | ||
|
||
public class MessageTemplateConverterTests | ||
{ | ||
public static IEnumerable<object[]> Data => | ||
new List<object[]> | ||
{ | ||
new object[] | ||
{ | ||
"empty type throws exception", | ||
@"{ ""type"": """", }", | ||
typeof(InAppMessageTemplate), | ||
true, | ||
}, | ||
new object[] | ||
{ | ||
nameof(InAppMessageTemplate), | ||
@" | ||
{ | ||
""type"": ""in_app"", | ||
} | ||
", | ||
typeof(InAppMessageTemplate), | ||
false, | ||
}, | ||
new object[] | ||
{ | ||
nameof(EmailMessageTemplate), | ||
@" | ||
{ | ||
""type"": ""email"", | ||
} | ||
", | ||
typeof(EmailMessageTemplate), | ||
false, | ||
}, | ||
new object[] | ||
{ | ||
nameof(SmsMessageTemplate), | ||
@" | ||
{ | ||
""type"": ""sms"", | ||
} | ||
", | ||
typeof(SmsMessageTemplate), | ||
false, | ||
}, | ||
new object[] | ||
{ | ||
nameof(ChatMessageTemplate), | ||
@" | ||
{ | ||
""type"": ""chat"", | ||
} | ||
", | ||
typeof(ChatMessageTemplate), | ||
false, | ||
}, | ||
new object[] | ||
{ | ||
nameof(DigestMessageTemplate), | ||
@" | ||
{ | ||
""type"": ""digest"", | ||
} | ||
", | ||
typeof(DigestMessageTemplate), | ||
false, | ||
}, | ||
new object[] | ||
{ | ||
nameof(TriggerMessageTemplate), | ||
@" | ||
{ | ||
""type"": ""trigger"", | ||
} | ||
", | ||
typeof(TriggerMessageTemplate), | ||
false, | ||
}, | ||
new object[] | ||
{ | ||
nameof(DelayMessageTemplate), | ||
@" | ||
{ | ||
""type"": ""delay"", | ||
} | ||
", | ||
typeof(DelayMessageTemplate), | ||
false, | ||
}, | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(Data))] | ||
public void MessageTemplateType(string test, string json, Type t, bool throws) | ||
{ | ||
JsonReader reader = new JsonTextReader(new StringReader(json)); | ||
while (reader.TokenType == JsonToken.None) | ||
{ | ||
if (!reader.Read()) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
if (throws) | ||
{ | ||
Assert.ThrowsAny<Exception>(() => | ||
new MessageTemplateConverter() | ||
.ReadJson(reader, t, null, JsonSerializer.CreateDefault())); | ||
} | ||
else | ||
{ | ||
new MessageTemplateConverter() | ||
.ReadJson(reader, t, null, JsonSerializer.CreateDefault()) | ||
.GetType() | ||
.Should() | ||
.Be(t); | ||
} | ||
} | ||
} |