-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b860f3
commit c76dc3f
Showing
12 changed files
with
159 additions
and
42 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
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
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
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
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,119 @@ | ||
// ========================================================================== | ||
// Squidex Headless CMS | ||
// ========================================================================== | ||
// Copyright (c) Squidex UG (haftungsbeschraenkt) | ||
// All rights reserved. Licensed under the MIT license. | ||
// ========================================================================== | ||
|
||
using Squidex.ClientLibrary; | ||
using Squidex.ClientLibrary.Management; | ||
using TestSuite.Fixtures; | ||
|
||
#pragma warning disable SA1300 // Element should begin with upper-case letter | ||
#pragma warning disable SA1507 // Code should not contain multiple blank lines in a row | ||
|
||
namespace TestSuite.ApiTests; | ||
|
||
public class RuleEventsTests : IClassFixture<ClientFixture> | ||
{ | ||
public ClientFixture _ { get; } | ||
|
||
public RuleEventsTests(ClientFixture fixture) | ||
{ | ||
_ = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task Should_cancel_event() | ||
{ | ||
// STEP 0: Create app. | ||
var (app, rule) = await CreateAppAndRuleAsync(); | ||
|
||
|
||
// STEP 1: Get events. | ||
var events_0 = await app.Rules.GetEventsAsync(rule.Id); | ||
|
||
Assert.Single(events_0.Items); | ||
Assert.Single(events_0.Items, x => x.NextAttempt != null); | ||
|
||
|
||
// STEP 2: Cancel event. | ||
await app.Rules.DeleteEventAsync(events_0.Items[0].Id); | ||
|
||
var events_1 = await app.Rules.GetEventsAsync(rule.Id); | ||
|
||
Assert.Single(events_1.Items); | ||
Assert.Single(events_1.Items, x => x.NextAttempt == null); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_cancel_event_by_rule() | ||
{ | ||
// STEP 0: Create app. | ||
var (app, rule) = await CreateAppAndRuleAsync(); | ||
|
||
|
||
// STEP 1: Get events. | ||
var events_0 = await app.Rules.GetEventsAsync(rule.Id); | ||
|
||
Assert.Single(events_0.Items); | ||
Assert.Single(events_0.Items, x => x.NextAttempt != null); | ||
|
||
|
||
// STEP 2: Cancel event. | ||
await app.Rules.DeleteRuleEventsAsync(rule.Id); | ||
|
||
var events_1 = await app.Rules.GetEventsAsync(rule.Id); | ||
|
||
Assert.Single(events_1.Items); | ||
Assert.Single(events_1.Items, x => x.NextAttempt == null); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_cancel_event_by_app() | ||
{ | ||
// STEP 0: Create app. | ||
var (app, rule) = await CreateAppAndRuleAsync(); | ||
|
||
|
||
// STEP 1: Get events. | ||
var events_0 = await app.Rules.GetEventsAsync(rule.Id); | ||
|
||
Assert.Single(events_0.Items); | ||
Assert.Single(events_0.Items, x => x.NextAttempt != null); | ||
|
||
|
||
// STEP 2: Cancel event. | ||
await app.Rules.DeleteEventsAsync(); | ||
|
||
var events_1 = await app.Rules.GetEventsAsync(rule.Id); | ||
|
||
Assert.Single(events_1.Items); | ||
Assert.Single(events_1.Items, x => x.NextAttempt == null); | ||
} | ||
|
||
private async Task<(ISquidexClient App, RuleDto)> CreateAppAndRuleAsync() | ||
{ | ||
var appName = Guid.NewGuid().ToString(); | ||
|
||
var (app, _) = await _.PostAppAsync(); | ||
|
||
var createRule = new CreateRuleDto | ||
{ | ||
Action = new WebhookRuleActionDto | ||
{ | ||
Method = WebhookMethod.POST, | ||
Payload = null, | ||
PayloadType = null, | ||
Url = new Uri("http://squidex.io") | ||
}, | ||
Trigger = new ManualRuleTriggerDto(), | ||
}; | ||
|
||
var rule = await app.Rules.PostRuleAsync(createRule); | ||
|
||
await app.Rules.TriggerRuleAsync(rule.Id); | ||
|
||
return (app, rule); | ||
} | ||
} |
Oops, something went wrong.