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: NedbClient #21

Closed
86 tasks done
AlexStormwood opened this issue Sep 2, 2024 · 1 comment · Fixed by #18
Closed
86 tasks done

feat: NedbClient #21

AlexStormwood opened this issue Sep 2, 2024 · 1 comment · Fixed by #18
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@AlexStormwood
Copy link
Contributor

AlexStormwood commented Sep 2, 2024

This feature mostly already exists in v0.4.4. This issue is for tracking progress for this feature in the TypeScript rewrite of this package.

Tests to confirm this feature should be:

Golden Path Tests

  • A NedbClient instance exists in the SuperCamo static client list, when connected.
  • A NedbClient instance can be retrieved using a SuperCamo static method, when connected.
    • A NedbClient instance retrieved from the SuperCamo static class has a valid database folder path.
    • A NedbClient instance retrieved from the SuperCamo static class has a valid database name.
  • A NedbClient instance should be able to perform database document Create operations. (Note: this section needs more tests!)
    • insertOne (returns object)
      • valid data leads to a successful document creation
      • passes along any errors from document creation as-is
    • insertMany (returns object array)
      • valid data leads to a successful document creation
      • passes along any errors from document creation as-is
    • createOne (returns document)
      • valid data leads to a successful document creation
      • passes along any errors from document creation as-is
    • createMany (returns document array)
      • valid data leads to a successful document creation
      • passes along any errors from document creation as-is
  • A NedbClient instance should be able to perform database document Read operations.
    • findOneDocument
      • empty query returns a random document in the specified database collection
      • query for top-level data keys in a document returns appropriately
      • query for nested-level data keys in a document returns appropriately
      • query for data keys that do not exist in the document returns nothing
      • throws an error if the collection to be queried does not exist in the database
    • findOneObject
      • empty query returns a random object in the specified database collection
      • query for top-level data keys in a object returns appropriately
      • query for nested-level data keys in a object returns appropriately
      • query for data keys that do not exist in the object returns nothing
      • query given an option with a projection object returns an object containing appropriate keys per the projection
      • throws an error if the collection to be queried does not exist in the database
    • findManyDocuments
      • empty query returns ALL documents in the database
      • query for top-level data keys in a document returns appropriately
      • query for nested-level data keys in a document returns appropriately
      • query for data keys that do not exist in the document returns an empty array
      • if a limit option is provided, the returned array of documents should be no larger than the specified limit
      • throws an error if the collection to be queried does not exist in the database
    • findManyObjects
      • empty query returns ALL documents in the database
      • query for top-level data keys in a document returns appropriately
      • query for nested-level data keys in a document returns appropriately
      • query for data keys that do not exist in the document returns an empty array
      • if a limit option is provided, the returned array of documents should be no larger than the specified limit
      • query given an option with a projection object returns an object containing appropriate keys per the projection
      • throws an error if the collection to be queried does not exist in the database
  • A NedbClient instance should be able to perform database document Update operations.
    • findAndUpdateOneDocument
      • returns null when given a query returns no documents
      • returns an appropriately-modified document when given a valid query for top-level document properties and valid new document data
      • returns an appropriately-modified document when given a valid query for nested-level document properties and valid new document data
      • upsert option causes a new record to be created in the database if no existing document matches the query, with a document returned
      • when the upsert option is used, no document matches, and invalid data is provided, then the function passes along any errors from document creation as-is
    • findAndUpdateManyDocuments
      • returns an empty array when given a query returns no documents
      • returns an array of appropriately-modified document when given a valid query for top-level document properties and valid new document data
      • returns an array of appropriately-modified document when given a valid query for nested-level document properties and valid new document data
      • if a limit option is provided, the returned array of modified documents should be no larger than the specified limit
      • if an upsert option is provided alongside valid data and a query with no matches, an array containing one new database entry is returned
      • invalid update data causes the function to throw an error
      • data that is invalid for some documents but not all will throw an error, but successfully apply to some documents
        • eg. unique property on a document should work for one document, but not two
    • findAndUpdateOneObject
      • returns null when given a query returns no documents
      • returns an appropriately-modified document object when given a valid query for top-level document properties and valid new document data
      • returns an appropriately-modified document object when given a valid query for nested-level document properties and valid new document data
      • upsert option causes a new record to be created in the database if no existing document matches the query, with an object returned
      • when the upsert option is used, no document matches, and invalid data is provided, then the function passes along any errors from document creation as-is
    • findAndUpdateManyObjects
      • returns an empty array when given a query returns no documents
      • returns an array of appropriately-modified document when given a valid query for top-level document properties and valid new document data
      • returns an array of appropriately-modified document when given a valid query for nested-level document properties and valid new document data
      • if a limit option is provided, the returned array of modified documents should be no larger than the specified limit
      • if an upsert option is provided alongside valid data and a query with no matches, an array containing one new database entry is returned
      • invalid update data causes the function to throw an error
      • data that is invalid for some documents but not all will throw an error, but successfully apply to some documents
        • eg. unique property on a document should work for one document, but not two
  • A NedbClient instance should be able to perform database document Delete operations.
    • findAndDeleteOne
      • returns 0 when given a query returns no documents
      • returns the number of documents deleted when given a valid query that matches a document
    • findAndDeleteMany
      • returns 0 when given a query returns no documents
      • returns the number of documents deleted when given a valid query that matches a document
  • A NedbClient instance method can count the occurrences of Documents that match a given query.
    • empty query counts all docs in collection
    • query for top-level properties works appropriately
    • query for nested-level properties works appropriately
@AlexStormwood AlexStormwood added this to the v1.0.0 milestone Sep 2, 2024
@AlexStormwood AlexStormwood self-assigned this Sep 2, 2024
@AlexStormwood AlexStormwood linked a pull request Sep 2, 2024 that will close this issue
@AlexStormwood AlexStormwood added the enhancement New feature or request label Sep 2, 2024
@AlexStormwood
Copy link
Contributor Author

And this is a simplified task list. Gonna handle document and embedded document validation tests separately, as documents can exist separately from the NedbClient.

Otherwise there would've been many, many, many more tests to write in this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant