-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Cases] Add guardrails for add and update comment API #161200
[Cases] Add guardrails for add and update comment API #161200
Conversation
Pinging @elastic/response-ops (Team:ResponseOps) |
Pinging @elastic/response-ops-cases (Feature:Cases) |
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.
OAS LGTM, thanks!
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.
Nice work! Can you add a test in x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts
?
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.
Let's add some tests for the CommentRequestRt
to verify the validation. In general, I think it is nice if we created a strong linked chain of tests. For example, we test the CommentRequestRt
with all possible testing scenarios. Then we test the addComment
and bulkCreate
but there there is no need to check all possible testing scenarios (unless there is new logic on top of it). One is enough to ensure the integration between the function and the schema. The chain now is addComment
-> CommentRequestRt
. If the tests in CommentRequestRt
pass we are sure that addComment
will work correctly because we have at least one test that tests the integration between the two. Lastly, with integration tests, we check the integration between the addComment
and the route.
This article explains the concept in detail: https://www.jamesshore.com/v2/projects/nullables/testing-without-mocks#sociable-tests
cc @adcoelho
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.
Then we test the addComment and bulkCreate but there there is no need to check all possible testing scenarios (unless there is new logic on top of it).
I wondered about this but we need to guarantee somehow that (in this case) CommentRequestRt
is being used by addComment
and bulkCreate
.
Is this what you mean with
because we have at least one test that tests the integration between the two.
?
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.
Ahh okay, so just checking if I understood it correctly,
- all the tests of errors like
long comment, empty string
etc should be part ofCommentRequestRt
tests inx-pack/plugins/cases/common/api/cases/comment/index.test.ts
- where as
addComment, update and bulk create
just tests the integration withCommentRequestRt
with one test - and same with api integration tests to test
route
andpost_comment, patch_comment, bulk_create_attachments
integration with one test?
}); | ||
|
||
describe('actions', () => { | ||
const updateActionComment = { ...actionComment, id: 'comment-id', version: 'WzAsMV0=' }; |
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.
what is the difference between updateComment
and actionComment
?
Edit: I know it is the type 😅 but more specifically, how are they different in practice?
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 think @cnasikas can answer it 😄
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 a user isolates a host from the alerts flyout the security solution team adds a comment to a case + some information about the host etc. At the time we did not have the attachment framework so this became a core attachment type.
x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/patch_comment.ts
Show resolved
Hide resolved
…-ref HEAD~1..HEAD --fix'
…/js-jankisalvi/kibana into guardrail-api-comment-characters
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Connected to #146945
Summary
Checklist
Delete any items that are not applicable to this PR.
Release Notes
The total number of characters per comment is limited to 30000