Skip to content

Enhc/dx 8641#191

Draft
OMpawar-21 wants to merge 2 commits into
enhc/betafrom
enhc/DX-8641
Draft

Enhc/dx 8641#191
OMpawar-21 wants to merge 2 commits into
enhc/betafrom
enhc/DX-8641

Conversation

@OMpawar-21
Copy link
Copy Markdown
Contributor

  • Remaining modules migrated and re-enabled — AuditLog, Extension, Label, Role, Taxonomy, Term, Webhook, DeliveryToken, ManagementToken, and CustomExtension fully re-enabled with STJ attributes; all corresponding Stack.*() accessor methods restored
  • All [JsonProperty] replaced with [JsonPropertyName] across all model classes; [JsonObject(ItemNullValueHandling)] removed in favour of global DefaultIgnoreCondition = WhenWritingNull
  • OAuth module enabled — OAuthHandler, OAuthTokenService, OAuthAppAuthorizationService, and OAuthAppRevocationService now active; auto token refresh wired into InvokeAsync pipeline via EnsureOAuthTokenIsValidAsync
  • CustomWidgetModel scope serialization migrated from JsonTextWriter to System.Text.Json.JsonSerializer.Serialize()
  • Asset extension upload tests — 3 previously skipped tests (Test002_Should_Create_Dashboard, Test003_Should_Create_Custom_Widget, Test004_Should_Create_Custom_field) now have real implementations using extension.html source
  • Unit test coverage expanded — 991 → 1,242 passing tests; 24 previously excluded test files re-enabled covering AuditLog, Extension, Label, Role, Taxonomy, Term, Webhook, DeliveryToken, CustomExtension, and all infrastructure tests (HTTP pipeline, converters, runtime contexts, utilities)
  • Integration test coverage expanded — 4 previously excluded integration test files re-enabled: ContentType Expanded (Contentstack012b), DeliveryToken (Contentstack016), Taxonomy (Contentstack017), Role (Contentstack019)

- Replace all [JsonProperty] attributes with [JsonPropertyName] across all model classes (LabelModel, ExtensionModel, RoleModel, OAuthResponse, OAuthAppAuthorizationResponse, ExtensionScope, RoleModel nested classes, Token models)
- Remove [JsonObject] attributes — null handling covered globally by DefaultIgnoreCondition = WhenWritingNull
- Replace Newtonsoft JsonSerializer/JsonConverter with System.Text.Json equivalents in all service constructors and model classes
- Migrate ParameterCollection.AddQuery(JObject) → AddQuery(JsonNode) and QueryParamValue.JObjectParameterValue to use JsonNode
- Remove OpenJObjectResponse() from IResponse and ContentstackResponse — replaced by OpenJsonObjectResponse() (System.Text.Json.Nodes.JsonObject)
- Rewrite NodeJsonConverterTest and TextNodeJsonConverterTest using STJ public API (JsonSerializer.Serialize/Deserialize)
- Rewrite CustomJsonConverter mock from Newtonsoft JsonConverter base to JsonConverter<object> (STJ)
- Migrate CustomWidgetModel scope serialization from JsonTextWriter to JsonSerializer.Serialize
- Remove Newtonsoft.Json 13.0.3 package reference from core csproj
- Re-enable all previously excluded model files (Role, Taxonomy, Term, Extension, Label, AuditLog, Webhook, Token, CustomExtension) and uncomment corresponding Stack accessor methods
- Re-enable 4 excluded integration test files and fix missing using directives
- Re-enable all 25 excluded unit test files; fix ArgumentException vs InvalidOperationException assertions for uid-empty guard methods
- Enable OAuth: remove Compile Remove for OAuthHandler.cs and Services/OAuth, uncomment OAuth methods and EnsureOAuthTokenIsValidAsync in ContentstackClient
- Fix service constructor calls in Term, Taxonomy, Webhook, Extension, AuditLog — remove legacy serializer first-arg pattern
- Update unit test count: 991 → 1,242 tests all passing
Fix 1 — Role serialization (13 tests + Test057 as side-effect)
New file: Contentstack.Management.Core/Utils/RuleJsonConverter.cs

System.Text.Json only serializes the declared type when iterating a List<Rule>, so subclass fields like module and branches were silently dropped. The custom converter serializes the actual runtime type on Write, and dispatches on the "module" discriminator on Read. It uses the existing WithoutConverter<T>() helper to avoid infinite recursion.

Edit: ContentstackClient.cs Initialize()

Added SerializerOptions.Converters.Add(new RuleJsonConverter()) alongside the existing NodeJsonConverter and TextNodeJsonConverter registrations.

Fix 2 — Extension upload wrong file type (3 tests)
The Contentstack Extensions API requires an HTML source file. All three tests were uploading contentTypeSchema.json, which the API rejected with error_code 344: "upload: Not a valid html file".

New file: Contentstack.Management.Core.Tests/Mock/extension.html

Minimal valid HTML file accepted by the Extensions API.

Edit: Contentstack013_AssetTest.cs

Test002, Test003, Test004 — changed path from contentTypeSchema.json → extension.html and content type from "application/json" → "text/html".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant