accounts icon indicating copy to clipboard operation
accounts copied to clipboard

fix(typeorm): make the services attribute consistent with mongodb

Open blessanabraham opened this issue 3 years ago • 9 comments

  • Updated the getServices method on the User entity to construct objects for the top level fields
  • Added special handling for email.verificationTokens and password.reset
  • Updated tests to match the mongodb tests

Fixes: #1110

blessanabraham avatar Feb 05 '21 14:02 blessanabraham

The fix is ugly because I had to add special handling for some hard coded fields, namely email.verificationTokens and password.reset.

I am open to suggestions if there is a better way to do this. The only idea I have in my head right now is, these fields should be in their own tables and I would recommend the same for mongodb as well, since a document has a size limit of 16 MB with the default storage.

Since we do not have control over the no: of times a password might get reset for a user or the number of email verification tokens sent out, these might exceed the limits.

blessanabraham avatar Feb 05 '21 14:02 blessanabraham

Codecov Report

Merging #1111 (0802624) into master (232de32) will increase coverage by 0.05%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1111      +/-   ##
==========================================
+ Coverage   95.53%   95.59%   +0.05%     
==========================================
  Files          91       91              
  Lines        2152     2155       +3     
  Branches      418      420       +2     
==========================================
+ Hits         2056     2060       +4     
+ Misses         95       94       -1     
  Partials        1        1              
Impacted Files Coverage Δ
packages/database-typeorm/src/typeorm.ts 99.52% <ø> (+0.47%) :arrow_up:
packages/database-typeorm/src/entity/User.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 2450f33...a9e36df. Read the comment docs.

codecov[bot] avatar Feb 05 '21 14:02 codecov[bot]

The only idea I have in my head right now is, these fields should be in their own tables and I would recommend the same for mongodb as well, since a document has a size limit of 16 MB with the default storage.

Yes totally agree, for mongo this is already in progress https://github.com/accounts-js/accounts/pull/1081

pradel avatar Feb 06 '21 17:02 pradel

@blessanabraham can you add some tests with various services for this function? As I am not super familiar with this part of the code I am afraid of breaking stuff. Also from my understanding, this is a breaking change regarding the user format returned right?

pradel avatar Feb 06 '21 17:02 pradel

sure, will add some tests if they are missing.I had to modify the tests that I previously added. from mongodb to match the response from typeorm. After this change, the tests. from mongodb and typeorm match up. I tested and made sure that TwoFactor works now with typeorm and after this change. But you are right, I think we are missing some integration tests.

blessanabraham avatar Feb 07 '21 04:02 blessanabraham

Regarding breaking change, no, this change keeps it consistent with what mongodb returns and what the services expect the User entity to look like. typeorm was broken before this change.

blessanabraham avatar Feb 07 '21 04:02 blessanabraham

@blessanabraham if you have time to add the tests I can create a release after it's merged with the changes :)

pradel avatar May 06 '21 09:05 pradel

Hey @pradel , really sorry for the delay on this. Work was a bit hectic. I'll get to it this week

blessanabraham avatar May 09 '21 06:05 blessanabraham

@blessanabraham could you please rebase against current master and add some tests so that we can get this in the upcoming 1.0?

darkbasic avatar Nov 23 '23 09:11 darkbasic