-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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): 4246 nnnnat new mocks factory #4276
Conversation
…o the tags schema and integration test as a demo
…nat-new-mocks-factory
…il file that adds mock factories from our schemas
… all test are failing because the mongo cursors chnage on every run
… a mocks custom property
…tAdmin container in favor of doing it on the server, updated createProduct util fruntion for create a random handle when new products are created
…uct has a child variant, created hasChildVariant test
…schema, added Error check for invalid inventoryQuantity when updating product fields
… getSlug helper func in the server/shop methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor inline comments, but everything looks good in testing. Specifically
- Created and published product. New product has default handle
- Updated handle. The entered value is properly slugified
- Made sure I can't submit an empty inventory quantity when inventory tracking is enabled
@@ -0,0 +1,7 @@ | |||
import SimpleSchema from "simpl-schema"; | |||
|
|||
SimpleSchema.extendOptions([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment above this since it might not be obvious why.
// These options are added by the `aldeed:schema-index` Meteor package, but because that
// is a Meteor package and we also load the schemas in a non-Meteor Node app, we need to do it here.
/** | ||
* | ||
* @method hasChildVariant | ||
* @summary Return true if a Product or Variant has at least 1 child Product. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add to the end of summary: "that is visible and not deleted"
mockCollections.Products.findOne.mockReturnValueOnce(Promise.resolve(mockVariants[1])); | ||
const spec = await hasChildVariant(internalVariantIds[0], mockCollections); | ||
expect(spec).toBe(true); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you're mocking the findOne
, this test isn't really any different from the one above it. I'd just go with the two tests, true and false.
If you wanted to actually test the findOne selector, you'd have to make some integration tests for it. I don't think that's necessary since it's a simple function.
@aldeed I've made the requested changes and it's ready for review. |
Resolves #4246
Impact: minor
Type: feature|refactor
Issue
Writing GQL integration test has become difficult because we've been creating mock data ad-hoc.
More info here
Solution
@reactioncommerce
npm package that can take the de-meteorizedSimpleSchema
and create a mocks factory for each schema. See data-factorytest-utils/helper
that will build a mocks factory using the data-factory package and export aFactory
object to be used in the integration test.Factory
.Breaking changes
ReactionProduct
API fromlib/api
Testing
docker-compose run devserver npm run test:integration