remoteAppConfig.test.ts 2.4 KB

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