Zaista / cypress-mongodb

Cypress MongoDB plugin
MIT License
17 stars 8 forks source link

Couldn't find any documentation on querying data #27

Closed nohorbee closed 1 year ago

nohorbee commented 1 year ago

Hi! I'm working on a cypress & typescript project. I have installed cypress-mongodb and it's great. However, I struggled to find references on how to do things properly (examples of good practices).

For instance, I ended up doing something like this:

cy.findMany(
      { email: "myTestingEmail@mail.io" },
      { collection: "users" }
    ).should((result: any) => {
      expect(result?.length).to.equal(1);
      const firstElement = result[0];
      expect(firstElement.email).to.equal("myTestingEmail@mail.io");
      expect(firstElement.firstName).to.equal("Norberto");
      expect(firstElement.lastName).to.equal("Herz");
      expect(firstElement.provider).to.equal("password");
      expect(firstElement).not.to.have.property("password");
    });

Do you think this approach is correct? Is there any better option than typing result as any? Do you know if I am supposed to use then/should and that list of expects inside?

I got that working after hours of searching, not founding documentation, and trial and error.

P.S.: I'd love to start writing some docs once I have a clear idea of what I'm doing.

Zaista commented 1 year ago

Hi, thanks for the interest in this plugin and sorry for taking that long to answer :) Regarding the plugin documentation, currently the only thing to refer to is the README file here and potentially the source code itself. An addition to this can be a mongodb node driver documentation: https://www.mongodb.com/docs/drivers/node/current/usage-examples/ This is what's used under the hood of this plugin.

Regarding then/should and expects, this is relative to cypress and how you want to assert the results, expect is one way to do it. This plugin aims to give you the result of your query as an object or array (depending on the invoked function), and what you want to do with the results afterwards is entirely up to you (further queries, assertions, etc...).

Feel more than free to improve the README any time, would be appreciated :)