c.visible)} rows={prepareRows(tableData.rows)} />
)
: (
- {localization.integrations.algolia.messages.norecords}
+ {Localization.integrations.algolia.messages.norecords}
)}
diff --git a/src/Kentico.Xperience.Algolia/Admin/Components/AlgoliaIndexConfigurationComponent.cs b/src/Kentico.Xperience.Algolia/Admin/Components/AlgoliaIndexConfigurationComponent.cs
index 35cc60b..645f327 100644
--- a/src/Kentico.Xperience.Algolia/Admin/Components/AlgoliaIndexConfigurationComponent.cs
+++ b/src/Kentico.Xperience.Algolia/Admin/Components/AlgoliaIndexConfigurationComponent.cs
@@ -19,7 +19,7 @@ public class AlgoliaIndexConfigurationComponentProperties : FormComponentPropert
public class AlgoliaIndexConfigurationComponentClientProperties : FormComponentClientProperties>
{
- public IEnumerable? PossibleItems { get; set; }
+ public IEnumerable? PossibleContentTypeItems { get; set; }
}
public sealed class AlgoliaIndexConfigurationComponentAttribute : FormComponentAttribute
@@ -81,14 +81,14 @@ public Task> AddPath(string path)
protected override async Task ConfigureClientProperties(AlgoliaIndexConfigurationComponentClientProperties properties)
{
- var allWebsiteContentTypes = await DataClassInfoProvider
- .GetClasses()
- .WhereEquals(nameof(DataClassInfo.ClassContentTypeType), "Website")
- .Columns(nameof(DataClassInfo.ClassName))
- .GetEnumerableTypedResultAsync();
-
- properties.Value = Value ?? new();
- properties.PossibleItems = allWebsiteContentTypes.Select(x => x.ClassName).ToList();
+ var allWebsiteContentTypes = DataClassInfoProvider.ProviderObject
+ .Get()
+ .WhereEquals(nameof(DataClassInfo.ClassContentTypeType), "Website")
+ .GetEnumerableTypedResult()
+ .Select(x => new AlgoliaIndexContentType(x.ClassName, x.ClassDisplayName));
+
+ properties.Value = Value ?? [];
+ properties.PossibleContentTypeItems = allWebsiteContentTypes.ToList();
await base.ConfigureClientProperties(properties);
}
diff --git a/src/Kentico.Xperience.Algolia/Admin/DefaultAlgoliaConfigurationStorageService.cs b/src/Kentico.Xperience.Algolia/Admin/DefaultAlgoliaConfigurationStorageService.cs
index 70f8d24..f1f6048 100644
--- a/src/Kentico.Xperience.Algolia/Admin/DefaultAlgoliaConfigurationStorageService.cs
+++ b/src/Kentico.Xperience.Algolia/Admin/DefaultAlgoliaConfigurationStorageService.cs
@@ -87,11 +87,11 @@ public bool TryCreateIndex(AlgoliaConfigurationModel configuration)
if (path.ContentTypes is not null)
{
- foreach (string? contentType in path.ContentTypes)
+ foreach (var contentType in path.ContentTypes)
{
var contentInfo = new AlgoliaContentTypeItemInfo()
{
- AlgoliaContentTypeItemContentTypeName = contentType,
+ AlgoliaContentTypeItemContentTypeName = contentType.ContentTypeName,
AlgoliaContentTypeItemIncludedPathItemId = pathInfo.AlgoliaIncludedPathItemId,
AlgoliaContentTypeItemIndexItemId = newInfo.AlgoliaIndexItemId
};
@@ -112,7 +112,23 @@ public bool TryCreateIndex(AlgoliaConfigurationModel configuration)
}
var paths = pathProvider.Get().WhereEquals(nameof(AlgoliaIncludedPathItemInfo.AlgoliaIncludedPathItemIndexItemId), indexInfo.AlgoliaIndexItemId).GetEnumerableTypedResult();
- var contentTypes = contentTypeProvider.Get().WhereEquals(nameof(AlgoliaContentTypeItemInfo.AlgoliaContentTypeItemIndexItemId), indexInfo.AlgoliaIndexItemId).GetEnumerableTypedResult();
+
+ var contentTypesInfoItems = contentTypeProvider
+ .Get()
+ .WhereEquals(nameof(AlgoliaContentTypeItemInfo.AlgoliaContentTypeItemIndexItemId), indexInfo.AlgoliaIndexItemId)
+ .GetEnumerableTypedResult();
+
+ var contentTypes = DataClassInfoProvider.ProviderObject
+ .Get()
+ .WhereIn(
+ nameof(DataClassInfo.ClassName),
+ contentTypesInfoItems
+ .Select(x => x.AlgoliaContentTypeItemContentTypeName)
+ .ToArray()
+ ).GetEnumerableTypedResult()
+ .Select(x => new AlgoliaIndexContentType(x.ClassName, x.ClassDisplayName));
+
+
var languages = languageProvider.Get().WhereEquals(nameof(AlgoliaIndexLanguageItemInfo.AlgoliaIndexLanguageItemIndexItemId), indexInfo.AlgoliaIndexItemId).GetEnumerableTypedResult();
return new AlgoliaConfigurationModel(indexInfo, languages, paths, contentTypes);
@@ -128,7 +144,21 @@ public IEnumerable GetAllIndexData()
}
var paths = pathProvider.Get().ToList();
- var contentTypes = contentTypeProvider.Get().ToList();
+
+ var contentTypesInfoItems = contentTypeProvider
+ .Get()
+ .GetEnumerableTypedResult();
+
+ var contentTypes = DataClassInfoProvider.ProviderObject
+ .Get()
+ .WhereIn(
+ nameof(DataClassInfo.ClassName),
+ contentTypesInfoItems
+ .Select(x => x.AlgoliaContentTypeItemContentTypeName)
+ .ToArray()
+ ).GetEnumerableTypedResult()
+ .Select(x => new AlgoliaIndexContentType(x.ClassName, x.ClassDisplayName));
+
var languages = languageProvider.Get().ToList();
return indexInfos.Select(index => new AlgoliaConfigurationModel(index, languages, paths, contentTypes));
@@ -185,11 +215,11 @@ public bool TryEditIndex(AlgoliaConfigurationModel configuration)
if (path.ContentTypes != null)
{
- foreach (string? contentType in path.ContentTypes)
+ foreach (var contentType in path.ContentTypes)
{
var contentInfo = new AlgoliaContentTypeItemInfo()
{
- AlgoliaContentTypeItemContentTypeName = contentType ?? "",
+ AlgoliaContentTypeItemContentTypeName = contentType.ContentTypeName ?? "",
AlgoliaContentTypeItemIncludedPathItemId = pathInfo.AlgoliaIncludedPathItemId,
AlgoliaContentTypeItemIndexItemId = indexInfo.AlgoliaIndexItemId,
};
diff --git a/src/Kentico.Xperience.Algolia/Indexing/DefaultAlgoliaClient.cs b/src/Kentico.Xperience.Algolia/Indexing/DefaultAlgoliaClient.cs
index d9eb07c..7468504 100644
--- a/src/Kentico.Xperience.Algolia/Indexing/DefaultAlgoliaClient.cs
+++ b/src/Kentico.Xperience.Algolia/Indexing/DefaultAlgoliaClient.cs
@@ -141,9 +141,9 @@ private async Task RebuildInternal(AlgoliaIndex algoliaIndex, CancellationToken
if (includedPathAttribute.ContentTypes != null && includedPathAttribute.ContentTypes.Count > 0)
{
- foreach (string contentType in includedPathAttribute.ContentTypes)
+ foreach (var contentType in includedPathAttribute.ContentTypes)
{
- queryBuilder.ForContentType(contentType, config => config.ForWebsite(algoliaIndex.WebSiteChannelName, includeUrlPath: true));
+ queryBuilder.ForContentType(contentType.ContentTypeName, config => config.ForWebsite(algoliaIndex.WebSiteChannelName, includeUrlPath: true));
}
}
queryBuilder.InLanguage(language);
diff --git a/src/Kentico.Xperience.Algolia/Indexing/IndexedItemModelExtensions.cs b/src/Kentico.Xperience.Algolia/Indexing/IndexedItemModelExtensions.cs
index fd591c7..c81f941 100644
--- a/src/Kentico.Xperience.Algolia/Indexing/IndexedItemModelExtensions.cs
+++ b/src/Kentico.Xperience.Algolia/Indexing/IndexedItemModelExtensions.cs
@@ -42,7 +42,7 @@ public static bool IsIndexedByIndex(this IndexEventWebPageItemModel indexedItemM
return algoliaIndex.IncludedPaths.Any(path =>
{
- bool matchesContentType = path.ContentTypes.Contains(indexedItemModel.ContentTypeName, StringComparer.OrdinalIgnoreCase);
+ bool matchesContentType = path.ContentTypes.Exists(x => string.Equals(x.ContentTypeName, indexedItemModel.ContentTypeName));
if (!matchesContentType)
{
diff --git a/src/Kentico.Xperience.Algolia/Kentico.Xperience.Algolia.csproj b/src/Kentico.Xperience.Algolia/Kentico.Xperience.Algolia.csproj
index 1653b23..349940f 100644
--- a/src/Kentico.Xperience.Algolia/Kentico.Xperience.Algolia.csproj
+++ b/src/Kentico.Xperience.Algolia/Kentico.Xperience.Algolia.csproj
@@ -11,6 +11,7 @@
kentico
Kentico.Xperience.Algolia
$(NoWarn);S1075
+ latest
disable
diff --git a/tests/Kentico.Xperience.Algolia.Tests/Data/MockDataProvider.cs b/tests/Kentico.Xperience.Algolia.Tests/Data/MockDataProvider.cs
index 1954052..0fd0081 100644
--- a/tests/Kentico.Xperience.Algolia.Tests/Data/MockDataProvider.cs
+++ b/tests/Kentico.Xperience.Algolia.Tests/Data/MockDataProvider.cs
@@ -5,23 +5,22 @@
namespace Kentico.Xperience.Algolia.Tests.Base;
internal static class MockDataProvider
{
- public static IndexEventWebPageItemModel WebModel => new(
- itemID: 0,
- itemGuid: Guid.NewGuid(),
- languageName: CzechLanguageName,
- contentTypeName: ArticlePage.CONTENT_TYPE_NAME,
- name: "Name",
- isSecured: false,
- contentTypeID: 1,
- contentLanguageID: 1,
- websiteChannelName: DefaultChannel,
- webPageItemTreePath: "/",
- order: 0
- );
+ public static IndexEventWebPageItemModel WebModel(IndexEventWebPageItemModel item)
+ {
+ item.LanguageName = CzechLanguageName;
+ item.ContentTypeName = ArticlePage.CONTENT_TYPE_NAME;
+ item.Name = "Name";
+ item.ContentTypeID = 1;
+ item.ContentLanguageID = 1;
+ item.WebsiteChannelName = DefaultChannel;
+ item.WebPageItemTreePath = "/%";
+
+ return item;
+ }
public static AlgoliaIndexIncludedPath Path => new("/%")
{
- ContentTypes = [ArticlePage.CONTENT_TYPE_NAME]
+ ContentTypes = [new AlgoliaIndexContentType(ArticlePage.CONTENT_TYPE_NAME, nameof(ArticlePage))]
};
@@ -31,7 +30,8 @@ internal static class MockDataProvider
IndexName = DefaultIndex,
ChannelName = DefaultChannel,
LanguageNames = new List() { EnglishLanguageName, CzechLanguageName },
- Paths = new List() { Path }
+ Paths = new List() { Path },
+ StrategyName = "strategy"
},
[]
);
diff --git a/tests/Kentico.Xperience.Algolia.Tests/Indexing/IndexedItemModelExtensionsTests.cs b/tests/Kentico.Xperience.Algolia.Tests/Indexing/IndexedItemModelExtensionsTests.cs
index 9ca7a6c..b8249bb 100644
--- a/tests/Kentico.Xperience.Algolia.Tests/Indexing/IndexedItemModelExtensionsTests.cs
+++ b/tests/Kentico.Xperience.Algolia.Tests/Indexing/IndexedItemModelExtensionsTests.cs
@@ -1,7 +1,9 @@
using CMS.Core;
using CMS.EventLog;
using CMS.Tests;
+
using FluentAssertions;
+
using Kentico.Xperience.Algolia.Admin;
using Kentico.Xperience.Algolia.Indexing;
@@ -54,7 +56,7 @@ public void IsIndexedByIndex_Will_Return_False_When_The_Matching_Index_Has_No_Ma
{
var log = Substitute.For();
- IEnumerable paths = [new("/path") { ContentTypes = ["contentType"], Identifier = "1" }];
+ IEnumerable paths = [new("/path") { ContentTypes = [new("contentType", "contentType")], Identifier = "1" }];
var index = new AlgoliaIndex(new AlgoliaConfigurationModel
{
@@ -80,7 +82,7 @@ public void IsIndexedByIndex_Will_Return_False_When_The_Matching_Index_Has_No_Ma
var log = Substitute.For();
List contentTypes = ["contentType"];
- IEnumerable exactPaths = [new("/path") { ContentTypes = contentTypes, Identifier = "1" }];
+ IEnumerable exactPaths = [new("/path") { ContentTypes = [new("contentType", "contentType")], Identifier = "1" }];
var index1 = new AlgoliaIndex(new AlgoliaConfigurationModel
{
@@ -94,7 +96,7 @@ public void IsIndexedByIndex_Will_Return_False_When_The_Matching_Index_Has_No_Ma
}, new() { { "strategy", typeof(DefaultAlgoliaIndexingStrategy) } });
AlgoliaIndexStore.Instance.AddIndex(index1);
- IEnumerable wildcardPaths = [new("/home/%") { ContentTypes = contentTypes, Identifier = "1" }];
+ IEnumerable wildcardPaths = [new("/home/%") { ContentTypes = [new("contentType", "contentType")], Identifier = "1" }];
var index2 = new AlgoliaIndex(new AlgoliaConfigurationModel
{
ChannelName = "channel",
@@ -119,7 +121,7 @@ public void IsIndexedByIndex_Will_Return_False_When_The_Matching_Index_Has_No_Ma
public void IsIndexedByIndex_Will_Return_True_When_The_Matching_Index_Has_An_Exact_Path_Match()
{
var log = Substitute.For();
- List contentTypes = ["contentType"];
+ List contentTypes = [new("contentType", "contentType")];
IEnumerable exactPaths = [new("/path/abc/def") { ContentTypes = contentTypes, Identifier = "1" }];
@@ -135,7 +137,7 @@ public void IsIndexedByIndex_Will_Return_True_When_The_Matching_Index_Has_An_Exa
}, new() { { "strategy", typeof(DefaultAlgoliaIndexingStrategy) } });
AlgoliaIndexStore.Instance.AddIndex(index1);
- IEnumerable wildcardPaths = [new("/path/%") { ContentTypes = ["contentType"], Identifier = "1" }];
+ IEnumerable wildcardPaths = [new("/path/%") { ContentTypes = [new("contentType", "contentType")], Identifier = "1" }];
var index2 = new AlgoliaIndex(new AlgoliaConfigurationModel
{
@@ -150,7 +152,7 @@ public void IsIndexedByIndex_Will_Return_True_When_The_Matching_Index_Has_An_Exa
AlgoliaIndexStore.Instance.AddIndex(index2);
var sut = GetDefaultIndexEventWebPageItemModel();
- sut.ContentTypeName = contentTypes[0];
+ sut.ContentTypeName = contentTypes[0].ContentTypeName;
sut.WebPageItemTreePath = exactPaths.First().AliasPath;
sut.IsIndexedByIndex(log, index1.IndexName, "event").Should().BeTrue();
diff --git a/tests/Kentico.Xperience.Algolia.Tests/Tests/IndexStoreTests.cs b/tests/Kentico.Xperience.Algolia.Tests/Tests/IndexStoreTests.cs
index a98e012..c3755de 100644
--- a/tests/Kentico.Xperience.Algolia.Tests/Tests/IndexStoreTests.cs
+++ b/tests/Kentico.Xperience.Algolia.Tests/Tests/IndexStoreTests.cs
@@ -1,9 +1,11 @@
-using Kentico.Xperience.Algolia.Admin;
+using CMS.Tests;
+
+using Kentico.Xperience.Algolia.Admin;
using Kentico.Xperience.Algolia.Indexing;
using Kentico.Xperience.Algolia.Tests.Base;
namespace Kentico.Xperience.Algolia.Tests.Tests;
-internal class IndexStoreTests
+internal class IndexStoreTests : UnitTests
{
[Test]
@@ -24,6 +26,7 @@ public void AddAndGetIndex()
[Test]
public void AddIndex_AlreadyExists()
{
+ var fixture = new Fixture();
AlgoliaIndexStore.Instance.SetIndicies(new List());
AlgoliaIndexStore.Instance.AddIndex(MockDataProvider.Index);
@@ -55,4 +58,7 @@ public void SetIndicies()
Assert.That(AlgoliaIndexStore.Instance.GetIndex(simpleIndex.IndexName) is not null);
});
}
+
+ [TearDown]
+ public void TearDown() => AlgoliaIndexStore.Instance.SetIndicies([]);
}
diff --git a/tests/Kentico.Xperience.Algolia.Tests/Tests/IndexedItemModelExtensionsTests.cs b/tests/Kentico.Xperience.Algolia.Tests/Tests/IndexedItemModelExtensionsTests.cs
index c3752d9..d2f45f2 100644
--- a/tests/Kentico.Xperience.Algolia.Tests/Tests/IndexedItemModelExtensionsTests.cs
+++ b/tests/Kentico.Xperience.Algolia.Tests/Tests/IndexedItemModelExtensionsTests.cs
@@ -1,45 +1,47 @@
using CMS.Core;
+using CMS.Tests;
+
using DancingGoat.Models;
+
using Kentico.Xperience.Algolia.Admin;
using Kentico.Xperience.Algolia.Indexing;
using Kentico.Xperience.Algolia.Tests.Base;
namespace Kentico.Xperience.Algolia.Tests.Tests;
-internal class MockEventLogService : IEventLogService
-{
- public void LogEvent(EventLogData eventLogData)
- {
- // Method intentionally left empty.
- }
-}
-
-internal class IndexedItemModelExtensionsTests
+internal class IndexedItemModelExtensionsTests : UnitTests
{
- private readonly IEventLogService log;
-
- public IndexedItemModelExtensionsTests() => log = new MockEventLogService();
-
[Test]
public void IsIndexedByIndex()
{
+ Service.InitializeContainer();
+ var log = Substitute.For();
+
AlgoliaIndexStore.Instance.SetIndicies(new List());
AlgoliaIndexStore.Instance.AddIndex(MockDataProvider.Index);
- Assert.That(MockDataProvider.WebModel.IsIndexedByIndex(log, MockDataProvider.DefaultIndex, MockDataProvider.EventName));
+ var fixture = new Fixture();
+ var item = fixture.Create();
+
+ var model = MockDataProvider.WebModel(item);
+ Assert.That(model.IsIndexedByIndex(log, MockDataProvider.DefaultIndex, MockDataProvider.EventName));
}
[Test]
public void WildCard()
{
- var model = MockDataProvider.WebModel;
+ Service.InitializeContainer();
+ var log = Substitute.For();
+ var fixture = new Fixture();
+ var item = fixture.Create();
+
+ var model = MockDataProvider.WebModel(item);
model.WebPageItemTreePath = "/Home";
var index = MockDataProvider.Index;
- var path = new AlgoliaIndexIncludedPath("/%") { ContentTypes = [ArticlePage.CONTENT_TYPE_NAME] };
+ var path = new AlgoliaIndexIncludedPath("/%") { ContentTypes = [new(ArticlePage.CONTENT_TYPE_NAME, nameof(ArticlePage))] };
index.IncludedPaths = new List() { path };
- AlgoliaIndexStore.Instance.SetIndicies(new List());
AlgoliaIndexStore.Instance.AddIndex(index);
Assert.That(model.IsIndexedByIndex(log, MockDataProvider.DefaultIndex, MockDataProvider.EventName));
@@ -48,11 +50,17 @@ public void WildCard()
[Test]
public void WrongWildCard()
{
- var model = MockDataProvider.WebModel;
+ Service.InitializeContainer();
+ var log = Substitute.For();
+
+ var fixture = new Fixture();
+ var item = fixture.Create();
+
+ var model = MockDataProvider.WebModel(item);
model.WebPageItemTreePath = "/Home";
var index = MockDataProvider.Index;
- var path = new AlgoliaIndexIncludedPath("/Index/%") { ContentTypes = [ArticlePage.CONTENT_TYPE_NAME] };
+ var path = new AlgoliaIndexIncludedPath("/Index/%") { ContentTypes = [new("contentType", "contentType")] };
index.IncludedPaths = new List() { path };
@@ -65,11 +73,17 @@ public void WrongWildCard()
[Test]
public void WrongPath()
{
- var model = MockDataProvider.WebModel;
+ Service.InitializeContainer();
+ var log = Substitute.For();
+
+ var fixture = new Fixture();
+ var item = fixture.Create();
+
+ var model = MockDataProvider.WebModel(item);
model.WebPageItemTreePath = "/Home";
var index = MockDataProvider.Index;
- var path = new AlgoliaIndexIncludedPath("/Index") { ContentTypes = [ArticlePage.CONTENT_TYPE_NAME] };
+ var path = new AlgoliaIndexIncludedPath("/Index") { ContentTypes = [new("contentType", "contentType")] };
index.IncludedPaths = new List() { path };
@@ -82,7 +96,13 @@ public void WrongPath()
[Test]
public void WrongContentType()
{
- var model = MockDataProvider.WebModel;
+ Service.InitializeContainer();
+ var log = Substitute.For();
+
+ var fixture = new Fixture();
+ var item = fixture.Create();
+
+ var model = MockDataProvider.WebModel(item);
model.ContentTypeName = "DancingGoat.HomePage";
AlgoliaIndexStore.Instance.SetIndicies(new List());
@@ -94,16 +114,29 @@ public void WrongContentType()
[Test]
public void WrongIndex()
{
+ Service.InitializeContainer();
+ var log = Substitute.For();
+
AlgoliaIndexStore.Instance.SetIndicies(new List());
AlgoliaIndexStore.Instance.AddIndex(MockDataProvider.Index);
- Assert.That(!MockDataProvider.WebModel.IsIndexedByIndex(log, "NewIndex", MockDataProvider.EventName));
+ var fixture = new Fixture();
+ var item = fixture.Create();
+
+ var model = MockDataProvider.WebModel(item);
+ Assert.That(!model.IsIndexedByIndex(log, "NewIndex", MockDataProvider.EventName));
}
[Test]
public void WrongLanguage()
{
- var model = MockDataProvider.WebModel;
+ Service.InitializeContainer();
+ var log = Substitute.For();
+
+ var fixture = new Fixture();
+ var item = fixture.Create();
+
+ var model = MockDataProvider.WebModel(item);
model.LanguageName = "sk";
AlgoliaIndexStore.Instance.SetIndicies(new List());