Repository navigation
Customer accounts: register, profile, update, deactivate (#51, #53) - #70
Conversation
Customer is what gets stored (with the password hash), CustomerResponse is what the API returns (no hash). CustomerCreate/CustomerUpdate validate input, lowercase emails and keep passwords exactly as typed.
Register (hashes the password with argon2 via pwdlib, rejects a used email), get, update info/address and deactivate (soft delete, isActive=false). get_active_customer is for the auth dependency and cart/checkout to use.
POST /customers, and GET/PATCH/DELETE /customers/me. The /me routes use get_current_customer, which rejects everything with 401 until the JWT login is merged. Tests fake a signed-in customer with dependency_overrides. Added customers.json to test-data, sample-data and the conftest file list.
Two registrations at the same time could both pass the email check and the second save would drop the first customer. Register/update/deactivate now hold the file lock around load -> change -> save, and the password is hashed before taking it. Also rejects passwords that are only spaces.
|
separate the json file for customer tests! |
CookieLynx
left a comment
There was a problem hiding this comment.
Looking good!
All tests pass, and using the endpoints you can do all of the current customer actions (creating account, deleting account, modifiying).
Passwords and emails are validated to be in the correct format (I know I mentioned this during out meeting that it was not but I was mistaken)
Hashing looks like a good start for the auth I'm working on!
All requirements from M2 are covered for accounts!
One thing I would consider adding is a test for a passwords beyond 128 characters, the current testing for spaces and too-short passwords works great but is missing this edgecase! Otherwise the data is correctly copied from our production data files to temp copied ones during testing for customers.json as well!
Overall looking great! I approve, I'll keep open for now in case anyone else has other changes they want!
From Nathan's review: 128 characters is accepted, 129 is rejected.
|
thanks! added the test for passwords over 128 chars (and one for exactly 128 so the limit is checked both ways). also merged main in since #69 is merged now |
- get_customer and get_active_customer did the same lookup, kept one - shorter comments, removed a duplicate import and a duplicate test
Added an ErrorResponse model so 401/409 show their body in /docs, and a description for GET /customers/me.
- role and password tests now send a valid field too, so the 422 really comes from the forbidden field - added repository tests for lookups by id/email and stable ids - removed a lower() in the service that never did anything (emails are already lowercased by the request model)
|
New changes to error handling on routes looks good for purposefully thrown errors! New tests all look good! Merging! |
Customer accounts for M2. Closes #49, closes #51 (except Token), part of #53 (login is in the auth PR).