Skip to content

Commit

Permalink
Rule events.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed May 24, 2023
1 parent 9b860f3 commit c76dc3f
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 42 deletions.
4 changes: 2 additions & 2 deletions tools/TestSuite/TestSuite.ApiTests/AnonymousTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task Should_create_app_with_anonymous_read_access()


// STEP 3: Check anonymous permission.
var url = $"{_.Client.Options.Url}api/apps/{appName}/settings";
var url = $"{_.Client.Options.Url}api/apps/{app.Options.AppName}/settings";

using (var httpClient = new HttpClient())
{
Expand Down Expand Up @@ -89,7 +89,7 @@ public async Task Should_create_app_with_anonymous_write_access()


// STEP 3: Create a content.
var url = $"{_.Client.Options.Url}api/content/{appName}/my-content";
var url = $"{_.Client.Options.Url}api/content/{app.Options.AppName}/my-content";

using (var httpClient = new HttpClient())
{
Expand Down
6 changes: 3 additions & 3 deletions tools/TestSuite/TestSuite.ApiTests/AppClientsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public AppClientsTests(ClientFixture fixture)
public async Task Should_create_client()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 1: Create client.
Expand All @@ -51,7 +51,7 @@ await Verify(client)
public async Task Should_update_client()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 0: Create client.
Expand Down Expand Up @@ -86,7 +86,7 @@ await Verify(clients_2)
public async Task Should_delete_client()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 0: Create client.
Expand Down
8 changes: 4 additions & 4 deletions tools/TestSuite/TestSuite.ApiTests/AppContributorsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public AppContributorsTests(ClientFixture fixture)
public async Task Should_not_invite_contributor_if_flag_is_false()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 1: Do not invite contributors when flag is false.
Expand All @@ -52,7 +52,7 @@ public async Task Should_not_invite_contributor_if_flag_is_false()
public async Task Should_invite_contributor()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 1: Assign contributor.
Expand All @@ -70,7 +70,7 @@ await Verify(contributor_1)
public async Task Should_update_contributor()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 1: Assign contributor.
Expand All @@ -95,7 +95,7 @@ public async Task Should_update_contributor()
public async Task Should_remove_contributor()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 1: Assign contributor.
Expand Down
10 changes: 5 additions & 5 deletions tools/TestSuite/TestSuite.ApiTests/AppLanguagesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public AppLanguagesTests(ClientFixture fixture)
public async Task Should_add_language()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 1: Add languages.
Expand All @@ -48,7 +48,7 @@ public async Task Should_add_language()
public async Task Should_add_custom_language()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 1: Add languages.
Expand All @@ -66,7 +66,7 @@ public async Task Should_add_custom_language()
public async Task Should_update_language()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 1: Add languages.
Expand Down Expand Up @@ -97,7 +97,7 @@ public async Task Should_update_language()
public async Task Should_update_master_language()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 1: Add languages.
Expand Down Expand Up @@ -146,7 +146,7 @@ public async Task Should_update_master_language()
public async Task Should_delete_language()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 1: Add languages.
Expand Down
19 changes: 9 additions & 10 deletions tools/TestSuite/TestSuite.ApiTests/AppWorkflowsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ namespace TestSuite.ApiTests;
[UsesVerify]
public sealed class AppWorkflowsTests : IClassFixture<ClientFixture>
{
private readonly string appName = Guid.NewGuid().ToString();
private readonly string name = Guid.NewGuid().ToString();
private readonly string workflowName = Guid.NewGuid().ToString();

public ClientFixture _ { get; }

Expand All @@ -31,7 +30,7 @@ public AppWorkflowsTests(ClientFixture fixture)
public async Task Should_create_workflow()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 1: Create workflow.
Expand All @@ -48,7 +47,7 @@ public async Task Should_create_workflow()
public async Task Should_update_workflow()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 0: Create workflow.
Expand All @@ -70,11 +69,11 @@ public async Task Should_update_workflow()
},
["Published"] = new WorkflowStepDto(),
},
Name = name
Name = workflowName
};

var workflows_2 = await app.Apps.PutWorkflowAsync(workflow.Id, updateRequest);
var workflow_2 = workflows_2.Items.Find(x => x.Name == name);
var workflow_2 = workflows_2.Items.Find(x => x.Name == workflowName);

Assert.NotNull(workflow_2);
Assert.NotNull(workflow_2.Name);
Expand All @@ -87,7 +86,7 @@ public async Task Should_update_workflow()
public async Task Should_delete_workflow()
{
// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 0: Create workflow.
Expand All @@ -97,7 +96,7 @@ public async Task Should_delete_workflow()
// STEP 1: Delete workflow.
var workflows_2 = await app.Apps.DeleteWorkflowAsync(workflow.Id);

Assert.DoesNotContain(workflows_2.Items, x => x.Name == name);
Assert.DoesNotContain(workflows_2.Items, x => x.Name == workflowName);

await Verify(workflows_2);
}
Expand All @@ -106,11 +105,11 @@ private async Task<WorkflowDto> CreateAsync(ISquidexClient app)
{
var createRequest = new AddWorkflowDto
{
Name = name
Name = workflowName
};

var workflows = await app.Apps.PostWorkflowAsync(createRequest);
var workflow = workflows.Items.Find(x => x.Name == name);
var workflow = workflows.Items.Find(x => x.Name == workflowName);

return workflow;
}
Expand Down
6 changes: 2 additions & 4 deletions tools/TestSuite/TestSuite.ApiTests/AssetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,8 @@ public async Task Should_protect_asset()
[Fact]
public async Task Should_protect_asset_with_script()
{
var appName = Guid.NewGuid().ToString();

// STEP 0: Create app.
var (app, _) = await _.PostAppAsync(appName);
var (app, _) = await _.PostAppAsync();


// STEP 1: Create folder.
Expand Down Expand Up @@ -667,7 +665,7 @@ public async Task Should_delete_asset(bool permanent)
Filter = "isDeleted eq true"
});

Assert.Equal(!permanent, deleted.Items.Any(x => x.Id == asset.Id));
Assert.Equal(!permanent, deleted.Items.Exists(x => x.Id == asset.Id));
}

[Theory]
Expand Down
2 changes: 1 addition & 1 deletion tools/TestSuite/TestSuite.ApiTests/BackupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ await contents.CreateAsync(new TestEntityData
// Create a workflow
var workflowRequest = new AddWorkflowDto
{
Name = appName
Name = "workflow"
};

await app.Apps.PostWorkflowAsync(workflowRequest);
Expand Down
2 changes: 1 addition & 1 deletion tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public async Task Should_delete_content(Strategies.Deletion strategy)

var deleted = await _.Contents.GetAsync(q, QueryContext.Default.Unpublished(true));

Assert.Equal(strategy is Strategies.Deletion.SingleSoft or Strategies.Deletion.BulkSoft, deleted.Items.Any(x => x.Id == content.Id));
Assert.Equal(strategy is Strategies.Deletion.SingleSoft or Strategies.Deletion.BulkSoft, deleted.Items.Exists(x => x.Id == content.Id));
}

[Theory]
Expand Down
119 changes: 119 additions & 0 deletions tools/TestSuite/TestSuite.ApiTests/RuleEventsTests.cs
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);
}
}
Loading

0 comments on commit c76dc3f

Please sign in to comment.