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

Support base structure for documents inserted into the DB #1

Closed
sitegui opened this issue Apr 5, 2015 · 2 comments
Closed

Support base structure for documents inserted into the DB #1

sitegui opened this issue Apr 5, 2015 · 2 comments

Comments

@sitegui
Copy link
Member

sitegui commented Apr 5, 2015

Most documents inserted into a given collection have the same base structure (like Schema in mongoose).

By now, the test writer must explicitly declare all those default values and this creates a lots of repeating boring boilerplate, like:

### order in Order
items: [] // <- boilerplate
totalPrice: 0 // <- boring...
isActive: true // <- ZzZZzz
client:
    name: 'Guilherme' // <- this is useful

It would be nice not to have to repeat myself in those cases 😜

@sitegui
Copy link
Member Author

sitegui commented Apr 5, 2015

My proposal is:

Add a new option called defaultDocuments that is a map from collection name to base document. An example:

require('api-test')('test/api-test', {
    // other options here
    defaultDocuments: {
        Order: { // the collection name is the key
            items: [],
            totalPrice: 0,
            IsActive: true
        }
    }
})

Every DB insertion would mixin with the base document (if present).

@sitegui
Copy link
Member Author

sitegui commented Apr 5, 2015

It would also be nice to expose the base document in the context, so the test writer can use it explicitly somewhere else than DB insertion.

An example:

### user is
    defaultDocuments.User with name: randomStr()

@sitegui sitegui closed this as completed in 5c58e19 Apr 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant