-
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] Validate page and perPage parameters in find APIs #161111
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.
Great job. I left some comments.
x-pack/plugins/cases/common/api/cases/user_actions/operations/find.ts
Outdated
Show resolved
Hide resolved
Update pagination validation for find user actions. Update pagination validation for find comments. Added unit and e2e tests. Updated the documentation.
Remove code validation for paginations. Tests.
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 🚀!
`); | ||
}); | ||
|
||
it(`fails when page * perPage > ${MAX_DOCS_PER_PAGE}`, () => { |
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 this test is the same as the previous one. Probably you wanted to set the perPage
to MAX_DOCS_PER_PAGE
.
`); | ||
}); | ||
|
||
it('fails when page > maxPerPage', () => { |
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: fails when page
-> fails when perPage
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 was actually right, the schema doesMath.max(pageAsNumber, pageAsNumber * perPageAsNumber) > MAX_DOCS_PER_PAGE
so here I am testing the first half of the Math.max.
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 pass decode({ perPage: 4 })))
so I think it tests the perPage
and not the page
.
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.
ah, that is the mistake though :D
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 was looking at the similar named test fails when page > ${MAX_DOCS_PER_PAGE}
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.
ah, that is the mistake though :D
Depends on the angle you are looking at it hahahaha
`); | ||
}); | ||
|
||
it.skip('fails when page number is negative', () => { |
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 should unskip the tests, right?
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 wrote the tests before the feature so I skipped them. But I didn't implement this validation yet 😅
Maybe I'll delete and do it in a different PR.
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.
Oh, I thought it was part of this PR. We can leave them as it is and unskip them when you add the new validation.
const PageTypeRt = rt.union([rt.number, NumberFromString]); | ||
type PageNumberType = rt.TypeOf<typeof PageTypeRt>; | ||
|
||
export interface PaginationType { |
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: I found the Type
at the end a bit redundant.
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 I don't export this one we get a typescript error everywhere we use the paginationSchema
.
Exported variable '<whatever>' has or is using name 'PaginationType' from external module "/Users/adcoelho/Development/kibana/x-pack/plugins/cases/common/schema/types" but cannot be named.
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.
Exporting is fine. I think that the wording (naming of the type) is a bit confusing.
} | ||
|
||
export const PaginationSchemaRt = rt.exact(rt.partial({ page: PageTypeRt, perPage: PageTypeRt })); | ||
export type PartialPaginationType = Partial<PaginationType>; |
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: What about Pagination
?
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.
looks good 👍
💚 Build Succeeded
Metrics [docs]Module Count
Public APIs missing exports
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: cc @adcoelho |
Connected to #146945
Summary
Checklist
Delete any items that are not applicable to this PR.
Release Notes
Max value for perPage parameter in find Cases API is now 100.
Max value for perPage parameter in find User Actions API is now 100.
Max value for perPage parameter in find Comments API is now 100.