-
Notifications
You must be signed in to change notification settings - Fork 76
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
Test backend yingjun #101
base: master
Are you sure you want to change the base?
Test backend yingjun #101
Conversation
1. nodemon for hot reload during development. 2. use prisma as orm framework 3. use nestjs as base framework 4. additional lib(s): bytenode protect code in production.
…which is user can updated with existed email address.
…equest, they should generated and handle by database orm
In the high-level design diagram, what's the meaning of "->" arrow, is it a directed association? |
const { method, originalUrl: url } = req; | ||
|
||
res.on("finish", () => { | ||
const startTime = now("micro"); |
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.
can you explain why the startTime
variable is placed inside the finish callback
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.
- I meant to 'Aggregation' I think in current requirements user controller should has strong dependency with user service.
- this a bug, I found this issue yesterday after I commit. it should be in upper block. and the reason why use micro time b/c of it is too fast when executing on local. if you seconds it will always be 0ms.
), | ||
() => this.dbHealth.isHealthy("mongodb"), | ||
() => | ||
this.disk.checkStorage("diskStorage", { |
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.
why monitor disk storage in the backend service?
does it store anything on disk to support certain feature?
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.
not really, just my coding routine. actually I just meant to monitor the database status.
mongo1: | ||
image: mongo:5 | ||
container_name: mongo1 | ||
command: ["--replSet", "my-replica-set", "--bind_ip_all", "--port", "30001"] |
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.
does default configuration support replica set?
where to config the database if we want to use single node mongo db in local, while use replica set in QA / Staging / Production?
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.
here is the story.
this is my first time use Prisma orm, I know it is bit risk use new lib/framework which I don't familiar during interview project. But I always want to learn something new from each interview. I spent few hours read the doc and I found it is only supports replica. Also I think it is generally considered a good practice using MongoDB in a replica set configuration.
and if we really need use single node mongodb, we can easily replaced it with other orm framework, that is why I use interface injected to the userService instead of inject concrete prismaService class. the code can be much more simplified if I directly inject prismaService to userService but I think it lots the flexibility and maintainability.
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.
it's ok to use replica set, does the default configuration support replica set?
where to configure it if another environment uses more nodes or other ports?
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.
In controller level test, dependency in service level is mocked. |
pros: mock service layer during controller testing we can focusing controller's behavior in isolation. Also some times service layer is not implemented yet in this case we need mock it. pros: for the service testing sometimes we need mock database since database server is not accessible, also the memory db is much more faster, if we have lots of tests it may has very long execution time. also real database is highly relay on environment. |
expect(createdUser.id).toBeDefined(); | ||
userEquals(newUser, createdUser); | ||
}); | ||
it("should create user failed, duplicated email address", async () => { |
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.
in which test setup step is index created?
in deployment process of QA/Staging/Production, how to create required index?
and how to know index is created successfully, or failure reason?
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.
there is no index added in this project. I think it is not good practices add index at beginning of the new project, unless it has fairly a mount of preloaded data in db otherwise Create index in empty db may cause slowness insertion.
To create required index usually it should be done by db migration scripts instead add indexes directly on database, and we can use post deployment script check if index created properly. Or use db monitor tool, if it is not first release we also need do the regression test make sure everything works fine.
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.
you declared user's email
field to be unique, even without index, the app still checks in slower way to find if there is another user with same email
when insert / update.
would the index make insertion faster in this case?
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.
you declared user's email field to be unique, even without index, the app still checks in slower way to find if there is another user with same email when insert / update.
would the index make insertion faster in this case?
lol I think I misunderstood your question previously and also in my code I did something wrong, I didnt mean to add unique index, I'm trying to add comment to email field. it should be //unique instead of @unique.
for the database index it really depends on cases. so I didn't try add any in this project.
there is one e2e test in
with docker, it's easy to setup database server. there are 10 ~ 20 tests in this project, not so many. |
there is one e2e test in test/app.e2e-spec.ts, but just a hello world api test. what blocks you from adding e2e test there?
with docker, it's easy to setup database server. there are 10 ~ 20 tests in this project, not so many.
what do you think about using real database in e2e test in local or CI runner, before deploy to shared environment (qa/uat/stg)?
|
Tech used:
How to run
docker-compose up -d
nvm use
yarn dev
High level design diagram