From 33f7d4470418b4f3727117098240ffcf3f5f28db Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Sun, 29 Oct 2017 22:05:58 +0100 Subject: [PATCH] Tests for rule enqueuer. --- .../Rules/RuleEnqueuer.cs | 8 +- .../Webhooks/WebhookEnqueuerTests.cs | 123 ------------------ 2 files changed, 3 insertions(+), 128 deletions(-) delete mode 100644 tests/Squidex.Domain.Apps.Read.Tests/Webhooks/WebhookEnqueuerTests.cs diff --git a/src/Squidex.Domain.Apps.Read/Rules/RuleEnqueuer.cs b/src/Squidex.Domain.Apps.Read/Rules/RuleEnqueuer.cs index ad962157c..01870edb7 100644 --- a/src/Squidex.Domain.Apps.Read/Rules/RuleEnqueuer.cs +++ b/src/Squidex.Domain.Apps.Read/Rules/RuleEnqueuer.cs @@ -29,7 +29,7 @@ namespace Squidex.Domain.Apps.Read.Rules public string EventsFilter { - get { return "^content-"; } + get { return ".*"; } } public RuleEnqueuer( @@ -61,12 +61,10 @@ namespace Squidex.Domain.Apps.Read.Rules { var job = ruleService.CreateJob(ruleEntity.Rule, @event); - if (job == null) + if (job != null) { - continue; + await ruleEventRepository.EnqueueAsync(job, job.Created); } - - await ruleEventRepository.EnqueueAsync(job, job.Created); } } } diff --git a/tests/Squidex.Domain.Apps.Read.Tests/Webhooks/WebhookEnqueuerTests.cs b/tests/Squidex.Domain.Apps.Read.Tests/Webhooks/WebhookEnqueuerTests.cs deleted file mode 100644 index d33bf4c8c..000000000 --- a/tests/Squidex.Domain.Apps.Read.Tests/Webhooks/WebhookEnqueuerTests.cs +++ /dev/null @@ -1,123 +0,0 @@ -// ========================================================================== -// WebhookEnqueuerTests.cs -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex Group -// All rights reserved. -// ========================================================================== - -/* -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using FakeItEasy; -using Newtonsoft.Json; -using NodaTime; -using Squidex.Domain.Apps.Core.Webhooks; -using Squidex.Domain.Apps.Events.Contents; -using Squidex.Domain.Apps.Read.Webhooks.Repositories; -using Squidex.Infrastructure; -using Squidex.Infrastructure.CQRS.Events; -using Xunit; - -namespace Squidex.Domain.Apps.Read.Webhooks -{ - public class WebhookEnqueuerTests - { - private readonly IClock clock = A.Fake(); - private readonly IWebhookRepository webhookRepository = A.Fake(); - private readonly IWebhookEventRepository webhookEventRepository = A.Fake(); - private readonly TypeNameRegistry typeNameRegisty = new TypeNameRegistry(); - private readonly Instant now = SystemClock.Instance.GetCurrentInstant(); - private readonly NamedId appId = new NamedId(Guid.NewGuid(), "my-app"); - private readonly NamedId schemaId = new NamedId(Guid.NewGuid(), "my-schema"); - private readonly WebhookEnqueuer sut; - - public WebhookEnqueuerTests() - { - A.CallTo(() => clock.GetCurrentInstant()).Returns(now); - - typeNameRegisty.Map(typeof(ContentCreated)); - - sut = new WebhookEnqueuer( - typeNameRegisty, - webhookEventRepository, - webhookRepository, - clock, new JsonSerializer()); - } - - [Fact] - public void Should_return_contents_filter_for_events_filter() - { - Assert.Equal("^content-", sut.EventsFilter); - } - - [Fact] - public void Should_return_type_name_for_name() - { - Assert.Equal(typeof(WebhookEnqueuer).Name, sut.Name); - } - - [Fact] - public Task Should_do_nothing_on_clear() - { - return sut.ClearAsync(); - } - - [Fact] - public async Task Should_update_repositories_on_successful_requests() - { - var @event = Envelope.Create(new ContentCreated { AppId = appId, SchemaId = schemaId }); - - var webhook1 = CreateWebhook(1); - var webhook2 = CreateWebhook(2); - - A.CallTo(() => webhookRepository.QueryCachedByAppAsync(appId.Id)) - .Returns(new List { webhook1, webhook2 }); - - await sut.On(@event); - - A.CallTo(() => webhookEventRepository.EnqueueAsync( - A.That.Matches(webhookJob => - !string.IsNullOrWhiteSpace(webhookJob.RequestSignature) - && !string.IsNullOrWhiteSpace(webhookJob.RequestBody) - && webhookJob.Id != Guid.Empty - && webhookJob.Expires == now.Plus(Duration.FromDays(2)) - && webhookJob.AppId == appId.Id - && webhookJob.EventName == "MySchemaCreatedEvent" - && webhookJob.RequestUrl == webhook1.Url - && webhookJob.WebhookId == webhook1.Id), now)).MustHaveHappened(); - - A.CallTo(() => webhookEventRepository.EnqueueAsync( - A.That.Matches(webhookJob => - !string.IsNullOrWhiteSpace(webhookJob.RequestSignature) - && !string.IsNullOrWhiteSpace(webhookJob.RequestBody) - && webhookJob.Id != Guid.Empty - && webhookJob.Expires == now.Plus(Duration.FromDays(2)) - && webhookJob.AppId == appId.Id - && webhookJob.EventName == "MySchemaCreatedEvent" - && webhookJob.RequestUrl == webhook2.Url - && webhookJob.WebhookId == webhook2.Id), now)).MustHaveHappened(); - } - - private IWebhookEntity CreateWebhook(int offset) - { - var webhook = A.Dummy(); - - var schema = new WebhookSchema - { - SchemaId = schemaId.Id, - SendCreate = true, - SendUpdate = true - }; - - A.CallTo(() => webhook.Id).Returns(Guid.NewGuid()); - A.CallTo(() => webhook.Url).Returns(new Uri($"http://domain{offset}.com")); - A.CallTo(() => webhook.Schemas).Returns(new[] { schema }); - A.CallTo(() => webhook.SharedSecret).Returns($"secret{offset}"); - - return webhook; - } - } -} -*/ \ No newline at end of file