-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add link to app instance to body of correspondance message
- Loading branch information
Showing
5 changed files
with
131 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Altinn.App.Core.Configuration; | ||
using Altinn.App.Core.Models; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Altinn.App.Core.Helpers; | ||
|
||
internal class UrlHelper | ||
{ | ||
private readonly GeneralSettings _settings; | ||
|
||
public UrlHelper(IOptions<GeneralSettings> settings) | ||
{ | ||
_settings = settings.Value; | ||
} | ||
|
||
/// <summary> | ||
/// Get the url for an instance of an app | ||
/// </summary> | ||
/// <param name="app">The app identifier</param> | ||
/// <param name="instance">The instance identifier</param> | ||
/// <returns>The url for the app</returns> | ||
public string GetInstanceUrl(AppIdentifier app, InstanceIdentifier instance) | ||
{ | ||
string baseUrl = _settings.FormattedExternalAppBaseUrlWithTrailingPound(app); | ||
|
||
string url = $"{baseUrl}{instance.InstanceOwnerPartyId}/{instance.InstanceGuid}"; | ||
|
||
return url; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
test/Altinn.App.Core.Tests/Configuration/GeneralSettingsTests.cs
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,42 @@ | ||
using Altinn.App.Core.Configuration; | ||
using Altinn.App.Core.Models; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Altinn.App.Core.Tests.Configuration; | ||
|
||
public class GeneralSettingsTests | ||
{ | ||
private readonly GeneralSettings _settings; | ||
|
||
public GeneralSettingsTests() | ||
{ | ||
var options = Options.Create(new GeneralSettings { HostName = "localhost.altinn.cloud" }); | ||
_settings = options.Value; | ||
} | ||
|
||
[Fact] | ||
public void FormattedExternalAppBaseUrl_GivenAppIdentifier_ReturnsFormattedUrl() | ||
{ | ||
// Arrange | ||
AppIdentifier app = new("testOrg", "testApp"); | ||
|
||
// Act | ||
var result = _settings.FormattedExternalAppBaseUrl(app); | ||
|
||
// Assert | ||
Assert.Equal($"http://localhost.altinn.cloud/testOrg/testApp/", result); | ||
} | ||
|
||
[Fact] | ||
public void FormattedExternalAppBaseUrlWithTrailingPound_GivenAppIdentifier_ReturnsFormattedUrlWithTrailingPound() | ||
{ | ||
// Arrange | ||
AppIdentifier app = new("testOrg", "testApp"); | ||
|
||
// Act | ||
var result = _settings.FormattedExternalAppBaseUrlWithTrailingPound(app); | ||
|
||
// Assert | ||
Assert.Equal($"http://localhost.altinn.cloud/testOrg/testApp#/", result); | ||
} | ||
} |
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,34 @@ | ||
using Altinn.App.Core.Configuration; | ||
using Altinn.App.Core.Helpers; | ||
using Altinn.App.Core.Models; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Altinn.App.Core.Tests.Helpers; | ||
|
||
public class UrlHelperTests | ||
{ | ||
private readonly UrlHelper _urlHelper; | ||
|
||
public UrlHelperTests() | ||
{ | ||
var options = Options.Create(new GeneralSettings { HostName = "localhost.altinn.cloud" }); | ||
_urlHelper = new(options); | ||
} | ||
|
||
[Fact] | ||
public void GetInstanceUrl_ReturnsFormattedUrl() | ||
{ | ||
// Arrange | ||
AppIdentifier app = new("testOrg", "testApp"); | ||
InstanceIdentifier instance = new("50841220/7c811874-deca-428d-b238-019f1a149833"); | ||
|
||
// Act | ||
var result = _urlHelper.GetInstanceUrl(app, instance); | ||
|
||
// Assert | ||
Assert.Equal( | ||
"http://localhost.altinn.cloud/testOrg/testApp#/50841220/7c811874-deca-428d-b238-019f1a149833", | ||
result | ||
); | ||
} | ||
} |