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

Sc 63647/submission of json objects to string fields #170

Merged

Conversation

henriquelakiap
Copy link
Contributor

Description of the change

Add string validation and is valid/invalid format operators to first_name type

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Configuration change
  • Technical Debt
  • Documentation

Related tickets

Ticket SC-63647

Checklists

Development and Testing

  • Lint rules pass locally.
  • The code changed/added as part of this pull request has been covered with tests, or this PR does not alter production code.
  • All tests related to the changed code pass in development, or tests are not applicable.

Code Review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached.
  • At least two engineers have been added as "Reviewers" on the pull request.
  • Changes have been reviewed by at least two other engineers who did not write the code.
  • This branch has been rebased off master to be current.

Tracking

  • Issue from Shortcut/Jira has a link to this pull request.
  • This PR has a link to the issue in Shortcut.

QA

  • This branch has been deployed to staging and tested.

@henriquelakiap henriquelakiap requested review from johnrb2 and cgrayson and removed request for johnrb2 April 11, 2024 14:33
@henriquelakiap henriquelakiap marked this pull request as draft April 11, 2024 14:34
@@ -10,6 +10,7 @@ const formats = [
'ddd MMM DD YYYY', // 'Mon Jun 02 2014'
'MMM DD YYYY', // 'Jun 02 2014'
'M/D/YYYY', // '6/2/2014', '06/02/2014'
'MM/DD/YYYY', // '06/02/2014'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This mapping scenario was missing here and was causing failures in the unit tests

@@ -20,6 +21,7 @@ const formats = [
'ddd DD MMM YYYY', // 'Fri 18 July 2014'
'DD MMM YYYY', // '18 July 2014'
'D/M/YYYY', // '18/7/2014'
'DD/MM/YYYY', // '18/07/2014'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This mapping scenario was missing here and was causing failures in the unit tests

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. This worries me some. I don't understand why these date tests started failing, after working fine as of the previous release (here). What changed?

I do see the failures locally, too. But when I applied just this change, for example, it caused other failures, such as:

       06/02/2014
         should return a Date object:

      AssertionError: expected '2014-02-06T00:00:00.000Z' to equal '2014-06-02T00:00:00.000Z'
      + expected - actual

      -2014-02-06T00:00:00.000Z
      +2014-06-02T00:00:00.000Z

Which I suppose your other changes fix. But that's a functional change, not just a test fix. Customers may be relying on LeadConduit treating 06/02/2014 as June 2nd, and not February 6th.

Copy link
Contributor Author

@henriquelakiap henriquelakiap Apr 11, 2024

Choose a reason for hiding this comment

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

It seems that something changed in moment from version 2.29.4 to 2.30.0. In our last versioning of types, version 2.29.4 was used. By enforcing it here, the tests pass without adding these two scenarios. There was likely a bug in this conversion that has been fixed.

Regarding clients sending dates like 06/02/2014 being converted to June 2nd and not Feb 6th, this might also be happening in cases with D/M/YYYY and M/D/YYYY formats already mapped previously. In such cases, the first format passed in the formats array will always be the one that moment returns.

-- new info: the change in moment was on isValid function; before v2.30, isValid('18/07/2014',['D/M/YYYY']) was returning true. Now we need to add the correct mask DD/MM/YYYY, otherwise it will return false. Moment conversion still working

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We were masking this issue in the tests for European formats because we were using a day that can't be a month (18).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this scenario, we would have to think about how to proceed, such as opting for (and accepting) a standard conversion to US format.

Copy link
Contributor

Choose a reason for hiding this comment

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

A change in moment, that explains it! Thank you for finding that!

I think the thing to do in this PR is lock moment to 2.29.4, and open another story to, just as you say, think about how to proceed.

@henriquelakiap henriquelakiap marked this pull request as ready for review April 11, 2024 15:05
Copy link
Contributor

@cgrayson cgrayson left a comment

Choose a reason for hiding this comment

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

The changes for first_name look good, but the fixes to the unit tests have me worried. I'd really like to know why those tests started failing.

I also wonder if other types that are basically just strings should get this same protection. I think that would just be last_name and city.

@@ -20,6 +21,7 @@ const formats = [
'ddd DD MMM YYYY', // 'Fri 18 July 2014'
'DD MMM YYYY', // '18 July 2014'
'D/M/YYYY', // '18/7/2014'
'DD/MM/YYYY', // '18/07/2014'
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. This worries me some. I don't understand why these date tests started failing, after working fine as of the previous release (here). What changed?

I do see the failures locally, too. But when I applied just this change, for example, it caused other failures, such as:

       06/02/2014
         should return a Date object:

      AssertionError: expected '2014-02-06T00:00:00.000Z' to equal '2014-06-02T00:00:00.000Z'
      + expected - actual

      -2014-02-06T00:00:00.000Z
      +2014-06-02T00:00:00.000Z

Which I suppose your other changes fix. But that's a functional change, not just a test fix. Customers may be relying on LeadConduit treating 06/02/2014 as June 2nd, and not February 6th.

cgrayson
cgrayson previously approved these changes Apr 11, 2024
Copy link
Contributor

@cgrayson cgrayson left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, I appreciate it. You left a stray .only in a test file but otherwise LGTM 👍

@@ -1,7 +1,7 @@
const { assert } = require('chai');
const date = require('../lib/types/date');

describe('Date', function () {
describe.only('Date', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops 🙂

@henriquelakiap henriquelakiap merged commit 237084a into master Apr 12, 2024
2 checks passed
@henriquelakiap henriquelakiap deleted the sc-63647/submission-of-json-objects-to-string-fields branch April 12, 2024 12:57
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.

2 participants