Skip to content
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

Merged
merged 8 commits into from
Oct 17, 2024
Merged

Conversation

e-fisher
Copy link
Collaborator

@e-fisher e-fisher commented Oct 16, 2024

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:

export interface RuleInstance {
  apply: (request: RequestSnippetSchema) => RequestSnippetSchema
  rule: TestRule
  state: CorrelationState | ParameterizationState | other 
}

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

  1. Verify correlation and other existing rules still works as expected.
  2. The parameterization rule could be tested by manually adding rules to the generator, but it will be easier to do in the follow PR which adds UI

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (npm run lint) and all checks pass.
  • I have run tests locally (npm test) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Screenshots (if appropriate):

Related PR(s)/Issue(s)

@@ -205,97 +186,6 @@ function generateRequestParams(request: ProxyData['request']): string {
`
}

// @ts-expect-error we have commonjs set as module option
Copy link
Collaborator Author

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:

  1. Keep all tests related to codegen in one place
  2. test:watch would skip codegen.test.ts on change because of inline tests presence

@e-fisher e-fisher marked this pull request as ready for review October 16, 2024 13:26
@e-fisher e-fisher requested a review from a team as a code owner October 16, 2024 13:26
@e-fisher e-fisher requested review from going-confetti and Llandy3d and removed request for a team October 16, 2024 13:26
going-confetti
going-confetti previously approved these changes Oct 17, 2024
Copy link
Collaborator

@going-confetti going-confetti left a 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 👍

Llandy3d
Llandy3d previously approved these changes Oct 17, 2024
Copy link
Member

@Llandy3d Llandy3d left a 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 🚀

export function createCorrelationRuleInstance(
rule: CorrelationRule
): CorrelationRuleInstance {
const sequentialIdGenerator = generateSequentialInt()
Copy link
Member

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 🤔

Copy link
Collaborator Author

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

rule,
state,
type: rule.type,
apply: (
Copy link
Member

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 ? 🤔

@e-fisher e-fisher dismissed stale reviews from Llandy3d and going-confetti via b7e98ea October 17, 2024 14:21
@e-fisher e-fisher requested a review from Llandy3d October 17, 2024 14:24
Copy link
Member

@Llandy3d Llandy3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@going-confetti going-confetti self-requested a review October 17, 2024 15:07
@e-fisher e-fisher merged commit d45b1f2 into main Oct 17, 2024
2 checks passed
@e-fisher e-fisher deleted the feat/add-parameterization-logic branch October 17, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants