-
Notifications
You must be signed in to change notification settings - Fork 451
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
API environment endpoints #2529
Conversation
Your preview environment pr-2529-bttf has been deployed. |
Deploy preview for docs ready! ✅ Preview Built with commit 1a4ff32. |
}, | ||
], | ||
}, | ||
}, |
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.
Lots of copy/pasting in this test files makes it a little hard to follow and maintain. For example, if we add a new method to req.context that is needed under-the-hood, we will have to update it 13 times in this file.
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 actually the opposite, the context is only setting what's needed for the API call to consume. If a new method is added, the tests don't need to worry about it. The only case they'd need to be edited is if one of the API the implementation rely on changes, for instance if a permission method is modified, which is what we want to catch.
Generally speaking, I lean more and more toward making my tests more verbose and duplicated, contrary to actual code. This adds some maintenance burden but seems to make the tests more robust. The problem with factoring out too much is that abstract code is more prone to silent issues that would make all tests seemingly pass because, for instance, one higher order loop, is not operating the way it needs to. Having all tests be rigid and and less smart makes it more obvious when something breaks.
That being said, the code needs some factorization of the setup. I have added a api.setup.ts
utility function that handles the app and request context setup and teardown. Now the tests only have to specify what request context they want. Should make it more readable!
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.
Left a few small comments.
I'm less familiar/confident with the BaseModel changes, but overall looks good!
properties: | ||
description: | ||
type: string | ||
description: The description of the new environment |
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.
nit: Should probably remove the new
reference here.
} | ||
|
||
if (!req.context.permissions.canDeleteEnvironment(environment)) | ||
throw Error("You do not have permission to delete this environment!"); |
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.
We have a specific permissions error that we can use that provides better categorization of errors.
E.G.
if (!context.permissions.canDeleteEnvironment(environment)) {
context.permissions.throwPermissionError();
}
8fa9dde
to
26965c8
Compare
All PR comments have been addressed now! |
environments: environments.reduce( | ||
(ret, env) => [...ret, env.id === id ? updatedEnvironment : env], | ||
[] | ||
), |
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.
Minor code style, but map
makes a lot more sense here than reduce
. I tend to avoid reduce whenever possible since it's usually much harder to read and follow the logic compared to alternatives.
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.
100%
4cda76c
to
1a4ff32
Compare
No description provided.