remoteAppConfig.test.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. getCommunityUrlFromConfig,
  4. getCommunityUrlFromConfigs,
  5. getFeedbackUrlFromConfig,
  6. getForceUpdateMinimalVersionFromConfig,
  7. } from "../src/remoteAppConfig.js";
  8. describe("remoteAppConfig", () => {
  9. it("读取 feedback_url", () => {
  10. expect(
  11. getFeedbackUrlFromConfig({
  12. feedback_url: "https://example.com/feedback",
  13. }),
  14. ).toBe("https://example.com/feedback");
  15. });
  16. it("中文界面只读取中文社群地址", () => {
  17. expect(
  18. getCommunityUrlFromConfig(
  19. {
  20. community_urls: {
  21. "zh-CN": "https://example.com/zh-community",
  22. "en-US": "https://example.com/en-community",
  23. },
  24. },
  25. "zh-CN",
  26. ),
  27. ).toBe("https://example.com/zh-community");
  28. expect(
  29. getCommunityUrlFromConfig(
  30. {
  31. community_urls: {
  32. "en-US": "https://example.com/en-community",
  33. },
  34. },
  35. "zh-CN",
  36. ),
  37. ).toBeUndefined();
  38. });
  39. it("英文界面只读取英文社群地址", () => {
  40. expect(
  41. getCommunityUrlFromConfig(
  42. {
  43. community_urls: {
  44. "zh-CN": "https://example.com/zh-community",
  45. "en-US": "https://example.com/en-community",
  46. },
  47. },
  48. "en-US",
  49. ),
  50. ).toBe("https://example.com/en-community");
  51. expect(
  52. getCommunityUrlFromConfig(
  53. {
  54. community_urls: {
  55. "zh-CN": "https://example.com/zh-community",
  56. },
  57. },
  58. "en-US",
  59. ),
  60. ).toBeUndefined();
  61. });
  62. it("两个语言渠道都缺失时返回 undefined", () => {
  63. expect(getCommunityUrlFromConfig({}, "zh-CN")).toBeUndefined();
  64. });
  65. it("远端缺少当前语言时优先使用内置同语言入口", () => {
  66. expect(
  67. getCommunityUrlFromConfigs(
  68. {
  69. community_urls: {
  70. "zh-CN": "https://remote.example.com/feishu",
  71. },
  72. },
  73. {
  74. community_urls: {
  75. "zh-CN": "https://local.example.com/feishu",
  76. "en-US": "https://local.example.com/discord",
  77. },
  78. },
  79. "en-US",
  80. ),
  81. ).toBe("https://local.example.com/discord");
  82. });
  83. it("读取 forceUpdate minimalVersion", () => {
  84. expect(
  85. getForceUpdateMinimalVersionFromConfig({
  86. forceUpdate: {
  87. minimalVersion: " 4.0.0 ",
  88. },
  89. }),
  90. ).toBe("4.0.0");
  91. expect(getForceUpdateMinimalVersionFromConfig({})).toBeUndefined();
  92. expect(
  93. getForceUpdateMinimalVersionFromConfig({
  94. forceUpdate: {
  95. minimalVersion: "",
  96. },
  97. }),
  98. ).toBeUndefined();
  99. });
  100. });