Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

133 linhas
3.8KB

  1. package buildsvc
  2. import "testing"
  3. func TestBuildGlobalData_OptionalFieldsAreOmittedWhenEmpty(t *testing.T) {
  4. got := BuildGlobalData(GlobalDataInput{
  5. CompanyName: "Acme AG",
  6. Email: "hello@acme.test",
  7. Username: "acme-admin",
  8. AddressLine1: " ",
  9. })
  10. if got["companyName"] != "Acme AG" {
  11. t.Fatalf("companyName mismatch: got=%v", got["companyName"])
  12. }
  13. if got["email"] != "hello@acme.test" {
  14. t.Fatalf("email mismatch: got=%v", got["email"])
  15. }
  16. if got["username"] != "acme-admin" {
  17. t.Fatalf("username mismatch: got=%v", got["username"])
  18. }
  19. if _, ok := got["phone"]; ok {
  20. t.Fatalf("phone should be omitted when empty")
  21. }
  22. if _, ok := got["address"]; ok {
  23. t.Fatalf("address should be omitted when empty")
  24. }
  25. }
  26. func TestBuildGlobalData_AddressAndOptionalFields(t *testing.T) {
  27. got := BuildGlobalData(GlobalDataInput{
  28. CompanyName: "Acme AG",
  29. BusinessType: "Healthcare",
  30. Username: "acme-admin",
  31. Email: "hello@acme.test",
  32. Phone: "+41 79 000 00 00",
  33. OrgNumber: "CHE-123.456.789",
  34. StartDate: "2019-08-01",
  35. Mission: "Make dental care simple.",
  36. DescriptionShort: "Modern clinic.",
  37. DescriptionLong: "Full-service clinic in central Zurich.",
  38. SiteLanguage: "de",
  39. AddressLine1: "Main Street 1",
  40. AddressLine2: "2nd Floor",
  41. AddressCity: "Zurich",
  42. AddressRegion: "ZH",
  43. AddressZIP: "8000",
  44. AddressCountry: "Switzerland",
  45. })
  46. addressRaw, ok := got["address"]
  47. if !ok {
  48. t.Fatalf("address should be present")
  49. }
  50. address, ok := addressRaw.(map[string]any)
  51. if !ok {
  52. t.Fatalf("address type mismatch: %T", addressRaw)
  53. }
  54. if address["line1"] != "Main Street 1" {
  55. t.Fatalf("line1 mismatch: got=%v", address["line1"])
  56. }
  57. if address["line2"] != "2nd Floor" {
  58. t.Fatalf("line2 mismatch: got=%v", address["line2"])
  59. }
  60. if address["region"] != "ZH" {
  61. t.Fatalf("region mismatch: got=%v", address["region"])
  62. }
  63. if got["businessType"] != "Healthcare" {
  64. t.Fatalf("businessType mismatch: got=%v", got["businessType"])
  65. }
  66. if got["phone"] != "+41 79 000 00 00" {
  67. t.Fatalf("phone mismatch: got=%v", got["phone"])
  68. }
  69. if got["siteLanguage"] != "de" {
  70. t.Fatalf("siteLanguage mismatch: got=%v", got["siteLanguage"])
  71. }
  72. if _, ok := got["business_category"]; ok {
  73. t.Fatalf("business_category must not be present")
  74. }
  75. }
  76. func TestFilterGlobalData_RemovesUnsupportedKeys(t *testing.T) {
  77. got := FilterGlobalData(map[string]any{
  78. "companyName": " Acme AG ",
  79. "username": " admin ",
  80. "email": " hi@example.test ",
  81. "mobile": "+41 79 000 00 00",
  82. "business_category": "Healthcare",
  83. "siteLanguage": " de ",
  84. "address": map[string]any{
  85. "line1": " Main Street 1 ",
  86. "line2": "",
  87. "city": " Zurich ",
  88. "region": " ZH ",
  89. "zip": " 8000 ",
  90. "country": " Switzerland ",
  91. "country_code": "CH",
  92. "street": "Unsupported Street Key",
  93. },
  94. })
  95. if got["companyName"] != "Acme AG" {
  96. t.Fatalf("companyName mismatch: got=%v", got["companyName"])
  97. }
  98. if got["siteLanguage"] != "de" {
  99. t.Fatalf("siteLanguage mismatch: got=%v", got["siteLanguage"])
  100. }
  101. if _, ok := got["mobile"]; ok {
  102. t.Fatalf("mobile must not be present")
  103. }
  104. if _, ok := got["business_category"]; ok {
  105. t.Fatalf("business_category must not be present")
  106. }
  107. addressRaw, ok := got["address"]
  108. if !ok {
  109. t.Fatalf("address should be present")
  110. }
  111. address, ok := addressRaw.(map[string]any)
  112. if !ok {
  113. t.Fatalf("address type mismatch: %T", addressRaw)
  114. }
  115. if address["line1"] != "Main Street 1" {
  116. t.Fatalf("line1 mismatch: got=%v", address["line1"])
  117. }
  118. if _, ok := address["country_code"]; ok {
  119. t.Fatalf("address.country_code must not be present")
  120. }
  121. if _, ok := address["street"]; ok {
  122. t.Fatalf("address.street must not be present")
  123. }
  124. }