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

Feature request: allow more control over parameter matching #43

Open
eamonnmcevoy opened this issue May 20, 2022 · 3 comments
Open

Feature request: allow more control over parameter matching #43

eamonnmcevoy opened this issue May 20, 2022 · 3 comments

Comments

@eamonnmcevoy
Copy link

It would be great if I could have more control over parameter matching. Lets say I have a query that creates a node and takes a random uuid as input:

MERGE (u:User { userId: $userId, name: $userName }) return u;

My input params might be in the form of

const params = {
  userId: newUuid(), // function to generate a random uuid
  name: "user name"
}

neo-forgery configuration

const querySet:QuerySpec[] = [
        {
            name: 'create_user',
            query: `
              MERGE (u:User { userId: $userId, name: $userName }) return u;
            `,
            output: wrapCopiedResults(createUserResponse),
            params: {
              userId: "test_user_id",
              name: "user name"
            }
        }
    ]

This will result in an error: Error: your query was matched in your QuerySpec. But your params were not matched:

I would like to have some control here, my idea is to allow a lambda on each parameter to control the param checking, for example:

const querySet:QuerySpec[] = [
        {
            name: 'create_user',
            query: `
              MERGE (u:User { userId: $userId, name: $userName }) return u;
            `,
            output: wrapCopiedResults(createUserResponse),
            params: {
              userId: (value) => typeof value === "string",
              name: (value) => value === "test_user_id",
            }
        }
    ]
@YizYah
Copy link
Owner

YizYah commented May 20, 2022

Hi @eamonnmcevoy, I hear. It does seem sensible.

Just to confirm that I understand the use case, you would generate the mocked response using the actual generated random id ?

@eamonnmcevoy
Copy link
Author

eamonnmcevoy commented May 20, 2022

Not necessarily, I just want to ignore the parameter check for some parameters. I imagine modifying the response would be a fair bit more complex

@YizYah
Copy link
Owner

YizYah commented May 20, 2022

You could use mockSessionFromFunction. But I get it.

(Just pointing out that as a workaround you could mock the newUuid() function now.)

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

No branches or pull requests

2 participants