Skip to content

Commit c13749c

Browse files
authored
Merge pull request #93 from masastack/feature/sapp
Refactor: Add MatchPattern property to GlobalNavigationNodeDto and implement GetMenusByPmIdentityAsync method in IGlobalNavService
2 parents 8bd667d + 49f26a2 commit c13749c

5 files changed

Lines changed: 52 additions & 0 deletions

File tree

src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/Model/GlobalNavigationNodeDto.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class GlobalNavigationNodeDto
1919

2020
public string Url { get; set; } = string.Empty;
2121

22+
public string MatchPattern { get; set; } = string.Empty;
23+
2224
public string Icon { get; set; } = string.Empty;
2325

2426
public bool IsHidden { get; set; }

src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/Service/IGlobalNavService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ public interface IGlobalNavService
77
{
88
Task<List<GlobalNavigationAppDto>> GetGlobalNavigationsByClientIdAsync(string clientId);
99

10+
Task<List<GlobalNavigationNodeDto>> GetMenusByPmIdentityAsync(string pmIdentity);
11+
1012
Task<List<AppEntryDto>> GetVisibleAppEntriesByClientIdAsync(string clientId);
1113
}

src/Contrib.Wasm/Masa.Contrib.StackSdks.Sapp.Wasm/Service/GlobalNavService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ public async Task<List<GlobalNavigationAppDto>> GetGlobalNavigationsByClientIdAs
2121
return result ?? new();
2222
}
2323

24+
public async Task<List<GlobalNavigationNodeDto>> GetMenusByPmIdentityAsync(string pmIdentity)
25+
{
26+
var requestUri = $"{GLOBAL_NAV_ROUTE_PREFIX}/menus/by-pm-identity/{pmIdentity}";
27+
var result = await _caller.GetAsync<List<GlobalNavigationNodeDto>>(requestUri);
28+
return result ?? new();
29+
}
30+
2431
public async Task<List<AppEntryDto>> GetVisibleAppEntriesByClientIdAsync(string clientId)
2532
{
2633
var requestUri = $"{GLOBAL_NAV_ROUTE_PREFIX}/app-entries/by-client-id/{clientId}";

src/Contrib/Masa.Contrib.StackSdks.Sapp/Service/GlobalNavService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ public async Task<List<GlobalNavigationAppDto>> GetGlobalNavigationsByClientIdAs
2121
return result ?? new();
2222
}
2323

24+
public async Task<List<GlobalNavigationNodeDto>> GetMenusByPmIdentityAsync(string pmIdentity)
25+
{
26+
var requestUri = $"{GLOBAL_NAV_ROUTE_PREFIX}/menus/by-pm-identity/{pmIdentity}";
27+
var result = await _caller.GetAsync<List<GlobalNavigationNodeDto>>(requestUri);
28+
return result ?? new();
29+
}
30+
2431
public async Task<List<AppEntryDto>> GetVisibleAppEntriesByClientIdAsync(string clientId)
2532
{
2633
var requestUri = $"{GLOBAL_NAV_ROUTE_PREFIX}/app-entries/by-client-id/{clientId}";

src/Contrib/Tests/Masa.Contrib.StackSdks.Sapp.Tests/GlobalNavServiceTest.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,38 @@ public async Task TestGetVisibleAppEntriesByClientIdWhenNullAsync(string clientI
7373

7474
Assert.AreEqual(0, result.Count);
7575
}
76+
77+
[TestMethod]
78+
[DataRow("pm.identity")]
79+
public async Task TestGetMenusByPmIdentityAsync(string pmIdentity)
80+
{
81+
var data = new List<GlobalNavigationNodeDto> { new() };
82+
83+
var requestUri = $"api/global-nav/menus/by-pm-identity/{pmIdentity}";
84+
var caller = new Mock<ICaller>();
85+
caller.Setup(provider => provider.GetAsync<List<GlobalNavigationNodeDto>>(requestUri, default)).ReturnsAsync(data).Verifiable();
86+
var sappClient = new SappClient(caller.Object);
87+
88+
var result = await sappClient.GlobalNavService.GetMenusByPmIdentityAsync(pmIdentity);
89+
caller.Verify(provider => provider.GetAsync<List<GlobalNavigationNodeDto>>(requestUri, default), Times.Once);
90+
91+
Assert.AreEqual(1, result.Count);
92+
}
93+
94+
[TestMethod]
95+
[DataRow("pm.identity")]
96+
public async Task TestGetMenusByPmIdentityWhenNullAsync(string pmIdentity)
97+
{
98+
List<GlobalNavigationNodeDto>? data = null;
99+
100+
var requestUri = $"api/global-nav/menus/by-pm-identity/{pmIdentity}";
101+
var caller = new Mock<ICaller>();
102+
caller.Setup(provider => provider.GetAsync<List<GlobalNavigationNodeDto>>(It.IsAny<string>(), default)).ReturnsAsync(data).Verifiable();
103+
var sappClient = new SappClient(caller.Object);
104+
105+
var result = await sappClient.GlobalNavService.GetMenusByPmIdentityAsync(pmIdentity);
106+
caller.Verify(provider => provider.GetAsync<List<GlobalNavigationNodeDto>>(requestUri, default), Times.Once);
107+
108+
Assert.AreEqual(0, result.Count);
109+
}
76110
}

0 commit comments

Comments
 (0)