@reactioncommerce/api-plugin-shops
Advanced tools
Comparing version 1.2.5 to 1.3.0
{ | ||
"name": "@reactioncommerce/api-plugin-shops", | ||
"description": "Shops plugin for the Reaction API", | ||
"version": "1.2.5", | ||
"version": "1.3.0", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "type": "module", |
@@ -145,2 +145,6 @@ import SimpleSchema from "simpl-schema"; | ||
for (const func of context.getFunctionsOfType("mutateShopBeforeCreate")) { | ||
await func(context, shop); // eslint-disable-line no-await-in-loop | ||
} | ||
ShopSchema.validate(shop); | ||
@@ -147,0 +151,0 @@ |
@@ -8,5 +8,25 @@ import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js"; | ||
/** | ||
* @summary Creates a mock plugin that extends the shop schema mutates the shop before being created | ||
* @param {Object} context - mock context | ||
* @return {undefined} | ||
*/ | ||
function mockPluginExtendingShop(context) { | ||
context.simpleSchemas.Shop.extend({ | ||
externalShopProp: { | ||
type: String, | ||
optional: true | ||
} | ||
}); | ||
context.getFunctionsOfType.mockReturnValueOnce([ | ||
(_, shop) => { | ||
shop.externalShopProp = "externalValue"; | ||
} | ||
]); | ||
} | ||
test("creates shop with type primary if there is no existing shop", async () => { | ||
mockContext.collections.Shops.findOne.mockReturnValueOnce(Promise.resolve(null)); | ||
mockContext.collections.Shops.insertOne.mockReturnValueOnce(Promise.resolve({ result: { ok: 1 } })); | ||
mockPluginExtendingShop(mockContext); | ||
@@ -16,3 +36,4 @@ await expect(createShop(mockContext, { | ||
})).resolves.toEqual(expect.objectContaining({ | ||
shopType: "primary" | ||
shopType: "primary", | ||
externalShopProp: "externalValue" | ||
})); | ||
@@ -19,0 +40,0 @@ }); |
Sorry, the diff of this file is not supported yet
102815
1705