From 2751883b3265d5e16345329f110154427ca7af79 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Wed, 20 Jul 2022 11:37:50 -0400 Subject: [PATCH] fix tests --- examples/ecommerce-netlify-functions/package.json | 4 ++-- examples/ecommerce-netlify-functions/seed.js | 1 + .../ecommerce-netlify-functions/test/addToCart.test.js | 8 ++++++-- .../ecommerce-netlify-functions/test/checkout.test.js | 8 ++++++-- .../ecommerce-netlify-functions/test/getProducts.test.js | 8 ++++++-- .../test/removeFromCart.test.js | 8 ++++++-- 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/examples/ecommerce-netlify-functions/package.json b/examples/ecommerce-netlify-functions/package.json index 94e19c2dbb..3252c62446 100644 --- a/examples/ecommerce-netlify-functions/package.json +++ b/examples/ecommerce-netlify-functions/package.json @@ -9,8 +9,8 @@ "netlify-cli": "10.7.1" }, "scripts": { - "seed": "env NODE_ENV=development node ./seed", - "start": "env NODE_ENV=development netlify dev", + "seed": "env NODE_ENV=local node ./seed", + "start": "env NODE_ENV=local netlify dev", "test": "env NODE_ENV=test mocha ./test/*.test.js" } } diff --git a/examples/ecommerce-netlify-functions/seed.js b/examples/ecommerce-netlify-functions/seed.js index 9f14ddb88c..bb7a6ceae5 100644 --- a/examples/ecommerce-netlify-functions/seed.js +++ b/examples/ecommerce-netlify-functions/seed.js @@ -6,6 +6,7 @@ const mongoose = require('mongoose'); async function createProducts() { await mongoose.connect(config.mongodbUri); + await mongoose.connection.dropDatabase(); await Product.create({ name: 'iPhone 12', diff --git a/examples/ecommerce-netlify-functions/test/addToCart.test.js b/examples/ecommerce-netlify-functions/test/addToCart.test.js index fb0ecb541c..f771516490 100644 --- a/examples/ecommerce-netlify-functions/test/addToCart.test.js +++ b/examples/ecommerce-netlify-functions/test/addToCart.test.js @@ -8,8 +8,12 @@ const fixtures = require('../test/fixtures'); describe('Add to Cart', function() { it('Should create a cart and add a product to the cart', async function() { - const products = await fixtures.createProducts({product: [{ productName: 'A Test Products', productPrice: 500 }, {productName: 'Another Test Product', productPrice: 600 }]}) - .then((res) => res.products); + const products = await fixtures.createProducts({ + product: [ + { name: 'A Test Products', price: 500 }, + { name: 'Another Test Product', price: 600 } + ] + }).then((res) => res.products); const params = { body: { cartId: null, diff --git a/examples/ecommerce-netlify-functions/test/checkout.test.js b/examples/ecommerce-netlify-functions/test/checkout.test.js index 71e9483f26..82844554bc 100644 --- a/examples/ecommerce-netlify-functions/test/checkout.test.js +++ b/examples/ecommerce-netlify-functions/test/checkout.test.js @@ -11,8 +11,12 @@ const stripe = require('../integrations/stripe') describe('Checkout', function() { it('Should do a successful checkout run', async function() { - const products = await fixtures.createProducts({product: [{ productName: 'A Test Products', productPrice: 500 }, {productName: 'Another Test Product', productPrice: 600 }]}) - .then((res) => res.products); + const products = await fixtures.createProducts({ + product: [ + { name: 'A Test Products', price: 500 }, + { name: 'Another Test Product', price: 600 } + ] + }).then((res) => res.products); const params = { body: { cartId: null, diff --git a/examples/ecommerce-netlify-functions/test/getProducts.test.js b/examples/ecommerce-netlify-functions/test/getProducts.test.js index 0328f2c9e5..8ed414645c 100644 --- a/examples/ecommerce-netlify-functions/test/getProducts.test.js +++ b/examples/ecommerce-netlify-functions/test/getProducts.test.js @@ -8,8 +8,12 @@ const mongoose = require('mongoose'); describe('Products', function() { it('Should get all products.', async function() { - await fixtures.createProducts({product: [{ productName: 'A Test Products', productPrice: 500 }, {productName: 'Another Test Product', productPrice: 600 }]}) - .then((res) => res.products); + await fixtures.createProducts({ + product: [ + { name: 'A Test Products', price: 500 }, + { name: 'Another Test Product', price: 600 } + ] + }).then((res) => res.products); const result = await getProducts(); assert(result); }); diff --git a/examples/ecommerce-netlify-functions/test/removeFromCart.test.js b/examples/ecommerce-netlify-functions/test/removeFromCart.test.js index 24de63946d..1c646ef471 100644 --- a/examples/ecommerce-netlify-functions/test/removeFromCart.test.js +++ b/examples/ecommerce-netlify-functions/test/removeFromCart.test.js @@ -9,8 +9,12 @@ const fixtures = require('./fixtures'); describe('Remove From Cart', function() { it('Should create a cart and then it should remove the entire item from it.', async function() { - const products = await fixtures.createProducts({product: [{ productName: 'A Test Products', productPrice: 500 }, {productName: 'Another Test Product', productPrice: 600 }]}) - .then((res) => res.products); + const products = await fixtures.createProducts({ + product: [ + { name: 'A Test Products', price: 500 }, + { name: 'Another Test Product', price: 600 } + ] + }).then((res) => res.products); const params = { body: { cartId: null,