-
Notifications
You must be signed in to change notification settings - Fork 4
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
[PB-3639]: fix/get existing customer #150
base: master
Are you sure you want to change the base?
Conversation
src/server.ts
Outdated
const start = async (mongoTestClient?: MongoClient): Promise<FastifyInstance> => { | ||
const start = async ( | ||
mongoTestClient?: MongoClient, | ||
mocksServices?: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This a very bad idea. Tests are for covering the real codebase, you cannot mix both things. What you need to do here involves mechanisms like sinon's stub method, which will save you from editing the codebase to have tests working.
tests/src/mocks/index.ts
Outdated
@@ -9,6 +9,16 @@ import { Tier } from '../../../src/core/users/MongoDBTiersRepository'; | |||
const randomDataGenerator = new Chance(); | |||
|
|||
export default function getMocks() { | |||
const user = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can use functions to instantiate mocks instead of having to create a const each time, that would be cleaner, easier to use and faster to work with. Example here where you can instantiate a user, by default it has as real as possible fields (using chance). It has of course things to improve, but it's far more scalable than this way of creating mocks.
|
Using the uuid to get the existing user from our DB if it exists before creating a new one in Stripe when calling
POST /create-customer
. Also, we get the user by uuid when payment invoices are completed to update it in the DB if needed.