-
Notifications
You must be signed in to change notification settings - Fork 10
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
PT-7293: Add a new Liquid 'where' filter to enable filtering collections #149
Conversation
…tification templates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Render_GetCurrentYear test is broken in this PR
src/VirtoCommerce.NotificationsModule.LiquidRenderer/Filters/ArrayFilter.cs
Outdated
Show resolved
Hide resolved
src/VirtoCommerce.NotificationsModule.LiquidRenderer/Filters/ArrayFilter.cs
Outdated
Show resolved
Hide resolved
src/VirtoCommerce.NotificationsModule.LiquidRenderer/Filters/ArrayFilter.cs
Outdated
Show resolved
Hide resolved
{ | ||
/// <summary> | ||
/// Filter the elements of an array by a given condition | ||
/// {% assign sorted = pages | where:"propName","==","value" %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change sorted
to filtered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/VirtoCommerce.NotificationsModule.LiquidRenderer/Filters/ArrayFilter.cs
Outdated
Show resolved
Hide resolved
tests/VirtoCommerce.NotificationsModule.Tests/UnitTests/LiquidTemplateRendererUnitTests.cs
Outdated
Show resolved
Hide resolved
@@ -152,6 +153,51 @@ public async Task RenderAsync_ContextHasLayoutId_LayoutRendered() | |||
Assert.Equal("header test_content footer", result); | |||
} | |||
|
|||
[Fact] | |||
public async Task RenderAsync_ContextHasLayoutId_ArrayContent_LayoutRendered() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to RenderAsync_FilterArray
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
public async Task RenderAsync_ContextHasLayoutId_ArrayContent_LayoutRendered() | ||
{ | ||
var layoutId = Guid.NewGuid().ToString(); | ||
var content = @"{% capture content %} Order Number: {{customer_order.number }}, Items Catalog Name: {{ var1 = customer_order.items | where: 'CatalogId' '==' '1' | array.first }} {{ var1.name }} {% endcapture %}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant code. (capture, order number) We need to test only filtering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
}; | ||
|
||
var result = await _liquidTemplateRenderer.RenderAsync(context); | ||
Assert.Equal("header Order Number: 123456, Items Catalog Name: Item1 footer", result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests for operations other than ==
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, I added a new test using greater than
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not fixed, there are more operations
tests/VirtoCommerce.NotificationsModule.Tests/UnitTests/LiquidTemplateRendererUnitTests.cs
Outdated
Show resolved
Hide resolved
…tification templates- update code for comments
Add a new Liquid 'where' filter to enable filtering collections in notification templates.
This new functionality allow the users filter arrays by conditions.
Example:
We have the following json
For example, if we wanted to filter the 'users' collection using the 'userId' and retrieve the first element from the list.
The sentence to make this is :
{{ var1 = users | where: 'userId' '==' '1' | array.first }} {{ var1.name }}
We filter the user collection based on the 'userId' property. When the 'userId' is 1, we retrieve the first element from the filtered results. Subsequently, we assign this result to a new variable, 'var1'. Following this, we write the user's name into the template.
Description
References
QA-test:
Jira-link:
https://virtocommerce.atlassian.net/browse/PT-7293
Artifact URL: