Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Invalid CarrierFields structure #558

Merged
merged 4 commits into from
Apr 12, 2024
Merged

[fix] Invalid CarrierFields structure #558

merged 4 commits into from
Apr 12, 2024

Conversation

nwithan8
Copy link
Member

@nwithan8 nwithan8 commented Apr 11, 2024

Description

This library was failing to deserialize a CarrierAccount from the API due to a failed deserialization of CarrierFields.

The previous assumption was that the API is returning "fields" in the JSON data for a CarrierAccount like so:

{
  "id": "ca_123",
  "object": "CarrierAccount",
  ...
  "fields": {
    "credentials": [
      {
        "key": "account_number",
        "visibility": "visible",
        "label": "DHL Account Number",
        "value": "123456"
      },
      {
        "key": "country",
        "visibility": "visible",
        "label": "Account Country Code (2 Letter)",
        "value": "US"
      }
    ]
  }
}

When in fact, the API is returning "fields" like so:

{
  "id": "ca_123",
  "object": "CarrierAccount",
  ...
  "fields": {
    "credentials": {
      "account_number": {
        "visibility": "visible",
        "label": "DHL Account Number",
        "value": "123456"
      },
      "country": {
        "visibility": "visible",
        "label": "Account Country Code (2 Letter)",
        "value": "US"
      }
    }
  }
}

Specifically, the "credentials" key under "fields" is not a list of dictionaries, but a dictionary of dictionaries, with the type of each credential field being the key in the key-value pair.

This PR updates the CarrierFields object structure to match the JSON schema.

Because the key for each type of credential field can by dynamic, users will have to access each credential field via a dictionary index:

string countryLabel = myCarrierAccount.Fields.Credentials["country"].Label

This PR also adds the missing "logo" property for a CarrierAccount.

Testing

  • Add unit test to confirm deserialization works as expected
    • The carrier accounts used in our existing unit tests do not have fields returned by the API, so the serialization issue was not previously caught.

Pull Request Type

Please select the option(s) that are relevant to this PR.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Improvement (fixing a typo, updating readme, renaming a variable name, etc)

@nwithan8 nwithan8 requested a review from a team as a code owner April 11, 2024 22:26
- Add unit test to confirm deserialization works as expected
- Add CHANGELOG entry
@nwithan8 nwithan8 merged commit a584bca into master Apr 12, 2024
14 checks passed
@nwithan8 nwithan8 deleted the carrier_fields branch April 12, 2024 17:55
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.

None yet

3 participants