-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: Add parameterization rule logic #256
Conversation
@@ -205,97 +186,6 @@ function generateRequestParams(request: ProxyData['request']): string { | |||
` | |||
} | |||
|
|||
// @ts-expect-error we have commonjs set as module option |
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've moved inline tests to codegen.test.ts
because of:
- Keep all tests related to codegen in one place
test:watch
would skip codegen.test.ts on change because of inline tests presence
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! I like the improvements 👍
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 great 🙌
Minor comments and I really like the instance concept 🚀
src/rules/correlation.ts
Outdated
export function createCorrelationRuleInstance( | ||
rule: CorrelationRule | ||
): CorrelationRuleInstance { | ||
const sequentialIdGenerator = generateSequentialInt() |
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.
should this be different for each instance ?
I think initially it was a single object shared between all rules to not have them generate the same id 🤔
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.
Good catch! Moved generator initialization up and added tests to verify ID generation
src/rules/correlation.ts
Outdated
rule, | ||
state, | ||
type: rule.type, | ||
apply: ( |
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: wouldn't it make it more readable to have the function defined separately and just pass the name here ? 🤔
b7e98ea
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.
🚀
Description
This is the first PR of parameterization rule implementation, includes rule logic, unit tests, and a refactor of how we currently apply rules.
Refactor rule application:
Some rules need to have a state to keep track of extracted value, requests matched and sequential variable IDs. Currently, it was done by using
correlationState
object, which was passed as argument when applying rules. Parameterization rule required a state to keep track of replaced requests and, while similar to correlation state, it didn't require all its properties.To address this, I've introduced Rule instances with the following structure:
This allowed to encapsulate state inside rule instance, reduce coupling because consumers applying rules no longer need to know about rule's state.
How to Test
Checklist
npm run lint
) and all checks pass.npm test
) and all tests pass.Screenshots (if appropriate):
Related PR(s)/Issue(s)