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

Add new constants, rename one and fix DueBy #583

Merged
merged 2 commits into from
Jun 11, 2018

Conversation

remi-stripe
Copy link
Contributor

While working on fixing #580, I started improving TestAccountUnmarshal to ensure we tried to deserialize a complex account object to catch any issue.

Doing that, I caught a few mistakes that I wanted to fix at the same time:

  • AccountRejectReason is now a type even though it's only used as a parameter. I should have fixed it when you asked me to, it's cleaner.
  • verification[disabled_reason] now has its own type: IdentityVerificationDisabledReason and related constants
  • verification[due_by] should not be a pointer so I fixed it back to a normal int64
  • PayoutIntervalDay has been renamed to PayoutIntervalDaily.

I think we should merge this one as a major version as it makes enough breaking changes.

If we want to unblock the other issue without a major version though we could merge #582 first.

r? @brandur-stripe
cc @stripe/api-libraries

"verification": map[string]interface{}{
"disabled_reason": "fields_needed",
"due_by": 1528573382,
"fields_needed": []interface{}{
Copy link
Contributor Author

@remi-stripe remi-stripe Jun 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have no idea how long I spent on figuring out the write right combination of [] string map interface and {} to make that one work 😓

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh god, haha.

assert.Equal(t, true, account.ExternalAccounts.HasMore)

assert.Equal(t, 2, len(account.ExternalAccounts.Data))
assert.Equal(t, "ba_123", account.ExternalAccounts.Data[0].ID)
assert.Equal(t, "card_123", account.ExternalAccounts.Data[1].ID)

// Ensure LegalEntity is fully deserialized
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made thorough tests of almost every property, not sure if too much or not, please let me know if I should cut those in half.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not necessary, but I think it's okay now that you've already written it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity what do you think would have been a good test? I think this large structure is fairly easy to mess up as there are so many edge-cases. You could end up deserializing the wrong property in the wrong place like maiden name as first_name or vice versa, or identification documents like I did.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably one check per "level" (i.e., level of structures which you descend to) is probably a good idea. Agree that it's easy to misname a JSON field, but I think to some degree you need to rely on the fact that these are likely to trend towards correctness over time. Adding tests gives you a little more guarantee, but the tests themselves are likely to be butchered during any sizable refactor, and so not end up testing for regressions as well as you might hope anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! I see where you're coming from. I think I had similar discussions with @ob-stripe on the stripe-java refactor so it is starting to make sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's definitely a little subjective :$

@nd2s
Copy link

nd2s commented Jun 10, 2018

@remi-stripe JFYI: There are more struct fields of type *string that should be a custom type instead. Like PayoutScheduleParams.Interval or .WeeklyAnchor.

Would be nice if these changes would find their way into the library soon.

@remi-stripe
Copy link
Contributor Author

remi-stripe commented Jun 10, 2018

JFYI: There are more struct fields of type *string that should be a custom type instead. Like PayoutScheduleParams.Interval or .WeeklyAnchor.

@nd2s That is expected. You can see that all parameters are *string and not *CustomType. The reason is that if we had used the custom types, we would have needed two custom functions for every single type which would have been unmanageable so we stuck with *string for all of those.

Instead your code should be:

    account, err := account.New(&stripe.AccountParams{
      Type:      stripe.String(string(stripe.AccountTypeCustom)),
      Country: stripe.String("US"),
      PayoutSchedule: &stripe.PayoutScheduleParams {
        Interval: stripe.String(string(stripe.PayoutIntervalManual)),
      },
    })

@brandur-stripe
Copy link
Contributor

If we want to unblock the other issue without a major version though we could merge #582 first.

+1.

This LGTM.

@brandur-stripe brandur-stripe merged commit b31813e into master Jun 11, 2018
@brandur-stripe brandur-stripe deleted the remi-fix-some-account-properties branch June 11, 2018 14:13
@brandur-stripe
Copy link
Contributor

Released as 33.0.0.

nadaismail-stripe pushed a commit that referenced this pull request Oct 18, 2024
Bumps [sorbet](https://github.com/sorbet/sorbet) from 0.5.10151 to 0.5.10172.
- [Release notes](https://github.com/sorbet/sorbet/releases)
- [Commits](https://github.com/sorbet/sorbet/commits)

---
updated-dependencies:
- dependency-name: sorbet
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants