using System.Text.Json.Nodes; namespace HrynCo.NotificationService.Web.IntegrationTests; public static class InvalidDefinitionApiBody { public static JsonObject Create(string scenario, Guid revision) { var body = DefinitionApiTestContext.Body(revision, "en"); body["removeLanguageCodes"] = new JsonArray("uk"); ApplyVariableScenario(scenario, body, (JsonArray)body["variables"]!); ApplyTranslationScenario(scenario, body, (JsonArray)body["translations"]!); return body; } private static void ApplyVariableScenario(string scenario, JsonObject body, JsonArray variables) { switch (scenario) { case "missingVariables": body.Remove("variables"); break; case "nullVariables": body["variables"] = null; break; case "nullVariable": variables.Add((JsonNode?)null); break; case "missingRequired": ((JsonObject)variables[0]!).Remove("required"); break; case "nonBooleanRequired": variables[0]!["required"] = "true"; break; case "duplicateVariable": variables.Add(variables[0]!.DeepClone()); break; case "blankVariable": variables[0]!["name"] = " "; break; } } private static void ApplyTranslationScenario(string scenario, JsonObject body, JsonArray translations) { switch (scenario) { case "missingTranslations": body.Remove("translations"); break; case "nullTranslations": body["translations"] = null; break; case "nullTranslation": translations.Add((JsonNode?)null); break; case "duplicateLanguage": translations.Add(translations[0]!.DeepClone()); break; case "unknownLanguage": translations[0]!["languageCode"] = "RU"; break; case "blankContent": translations[0]!["textBody"] = " "; break; case "missingContent": ((JsonObject)translations[0]!).Remove("htmlBody"); break; case "duplicateRemoval": body["removeLanguageCodes"] = new JsonArray("uk", "uk"); break; case "unknownRemoval": body["removeLanguageCodes"] = new JsonArray("UK"); break; case "nullRemoval": body["removeLanguageCodes"] = new JsonArray((JsonNode?)null); break; case "overlap": body["removeLanguageCodes"] = new JsonArray("en"); break; } } }