Skip to content

Commit 393cef0

Browse files
authored
Merge pull request #95 from masastack/feature/sapp
Add GetI18NConfigByClientIdAsync method to IGlobalNavService and impl…
2 parents 8dbe947 + 00276fd commit 393cef0

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ public interface IGlobalNavService
1010
Task<List<GlobalNavigationNodeDto>> GetMenusByPmIdentityAsync(string pmIdentity);
1111

1212
Task<List<AppEntryDto>> GetVisibleAppEntriesByClientIdAsync(string clientId);
13+
14+
Task<Dictionary<string, string>> GetI18NConfigByClientIdAsync(string clientId, string culture);
1315
}

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
@@ -34,4 +34,11 @@ public async Task<List<AppEntryDto>> GetVisibleAppEntriesByClientIdAsync(string
3434
var result = await _caller.GetAsync<List<AppEntryDto>>(requestUri);
3535
return result ?? new();
3636
}
37+
38+
public async Task<Dictionary<string, string>> GetI18NConfigByClientIdAsync(string clientId, string culture)
39+
{
40+
var requestUri = $"{GLOBAL_NAV_ROUTE_PREFIX}/i18n-config/by-client-id/{clientId}?culture={culture}";
41+
var result = await _caller.GetAsync<Dictionary<string, string>>(requestUri);
42+
return result ?? new();
43+
}
3744
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ public async Task<List<AppEntryDto>> GetVisibleAppEntriesByClientIdAsync(string
3434
var result = await _caller.GetAsync<List<AppEntryDto>>(requestUri);
3535
return result ?? new();
3636
}
37+
38+
public async Task<Dictionary<string, string>> GetI18NConfigByClientIdAsync(string clientId, string culture)
39+
{
40+
var requestUri = $"{GLOBAL_NAV_ROUTE_PREFIX}/i18n-config/by-client-id/{clientId}?culture={culture}";
41+
var result = await _caller.GetAsync<Dictionary<string, string>>(requestUri);
42+
return result ?? new();
43+
}
3744
}

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,38 @@ public async Task TestGetMenusByPmIdentityWhenNullAsync(string pmIdentity)
107107

108108
Assert.AreEqual(0, result.Count);
109109
}
110+
111+
[TestMethod]
112+
[DataRow("MASA_STACK", "zh-CN")]
113+
public async Task TestGetI18NConfigByClientIdAsync(string clientId, string culture)
114+
{
115+
var data = new Dictionary<string, string> { { "key", "value" } };
116+
117+
var requestUri = $"api/global-nav/i18n-config/by-client-id/{clientId}?culture={culture}";
118+
var caller = new Mock<ICaller>();
119+
caller.Setup(provider => provider.GetAsync<Dictionary<string, string>>(requestUri, default)).ReturnsAsync(data).Verifiable();
120+
var sappClient = new SappClient(caller.Object);
121+
122+
var result = await sappClient.GlobalNavService.GetI18NConfigByClientIdAsync(clientId, culture);
123+
caller.Verify(provider => provider.GetAsync<Dictionary<string, string>>(requestUri, default), Times.Once);
124+
125+
Assert.AreEqual(1, result.Count);
126+
}
127+
128+
[TestMethod]
129+
[DataRow("MASA_STACK", "zh-CN")]
130+
public async Task TestGetI18NConfigByClientIdWhenNullAsync(string clientId, string culture)
131+
{
132+
Dictionary<string, string>? data = null;
133+
134+
var requestUri = $"api/global-nav/i18n-config/by-client-id/{clientId}?culture={culture}";
135+
var caller = new Mock<ICaller>();
136+
caller.Setup(provider => provider.GetAsync<Dictionary<string, string>>(It.IsAny<string>(), default)).ReturnsAsync(data).Verifiable();
137+
var sappClient = new SappClient(caller.Object);
138+
139+
var result = await sappClient.GlobalNavService.GetI18NConfigByClientIdAsync(clientId, culture);
140+
caller.Verify(provider => provider.GetAsync<Dictionary<string, string>>(requestUri, default), Times.Once);
141+
142+
Assert.AreEqual(0, result.Count);
143+
}
110144
}

0 commit comments

Comments
 (0)