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

style: fix lint from #11892 #12132

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/ecommerce-netlify-functions/connect.js
Expand Up @@ -11,5 +11,5 @@ module.exports = async function connect() {
}
conn = mongoose.connection;
await mongoose.connect(config.mongodbUri);
return conn;
}
return conn;
};
4 changes: 2 additions & 2 deletions examples/ecommerce-netlify-functions/integrations/stripe.js
@@ -1,5 +1,5 @@
'use strict';

const config = require('../.config')
const config = require('../.config');

module.exports = require('stripe')(config.stripeSecretKey);
module.exports = require('stripe')(config.stripeSecretKey);
Expand Up @@ -11,11 +11,11 @@ const handler = async(event) => {
if (event.body.cartId) {
// get the document containing the specified cartId
const cart = await Cart.findOne({ _id: event.body.cartId }).setOptions({ sanitizeFilter: true });

if (cart == null) {
return { statusCode: 404, body: JSON.stringify({ message: 'Cart not found' }) };
}
if(!Array.isArray(event.body.items)) {
if (!Array.isArray(event.body.items)) {
return { statusCode: 500, body: JSON.stringify({ error: 'items is not an array' }) };
}
for (const product of event.body.items) {
Expand Down Expand Up @@ -45,4 +45,4 @@ const handler = async(event) => {
}
};

module.exports = { handler };
module.exports = { handler };
@@ -1,6 +1,6 @@
'use strict';

const stripe = require('../../integrations/stripe')
const stripe = require('../../integrations/stripe');
const config = require('../../.config');
const { Cart, Order, Product } = require('../../models');
const connect = require('../../connect');
Expand Down Expand Up @@ -53,7 +53,7 @@ const handler = async(event) => {
shipping: event.body.shipping,
paymentMethod: paymentMethod ? { id: paymentMethod.id, brand: paymentMethod.brand, last4: paymentMethod.last4 } : null
});

cart.orderId = order._id;
await cart.save();
return {
Expand All @@ -66,4 +66,4 @@ const handler = async(event) => {
}
};

module.exports = { handler };
module.exports = { handler };
Expand Up @@ -16,4 +16,4 @@ const handler = async(event) => {
}
};

module.exports = { handler };
module.exports = { handler };
Expand Up @@ -13,4 +13,4 @@ const handler = async(event) => {
}
};

module.exports = { handler };
module.exports = { handler };
Expand Up @@ -31,4 +31,4 @@ const handler = async(event) => {
}
};

module.exports = { handler };
module.exports = { handler };
2 changes: 1 addition & 1 deletion examples/ecommerce-netlify-functions/seed.js
Expand Up @@ -36,4 +36,4 @@ async function createProducts() {
process.exit(0);
}

createProducts();
createProducts();
16 changes: 8 additions & 8 deletions examples/ecommerce-netlify-functions/test/addToCart.test.js
Expand Up @@ -30,9 +30,9 @@ describe('Add to Cart', function() {
assert(result.body.items.length);
});
it('Should find the cart and add 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 { cart } = await fixtures.createCart({products: []});
const products = await fixtures.createProducts({ product: [{ productName: 'A Test Products', productPrice: 500 }, { productName: 'Another Test Product', productPrice: 600 }] })
.then((res) => res.products);
const { cart } = await fixtures.createCart({ products: [] });
const params = {
body: {
cartId: cart._id,
Expand All @@ -46,12 +46,12 @@ describe('Add to Cart', function() {
const findCart = await addToCart(params);
findCart.body = JSON.parse(findCart.body);
assert(findCart.body);
assert.equal(findCart.body.items.length, 2)
assert.equal(findCart.body.items.length, 2);
});
it('Should find the cart and increase the quantity of the item(s) in 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 { cart } = await fixtures.createCart({products: []});
const products = await fixtures.createProducts({ product: [{ productName: 'A Test Products', productPrice: 500 }, { productName: 'Another Test Product', productPrice: 600 }] })
.then((res) => res.products);
const { cart } = await fixtures.createCart({ products: [] });
const params = {
body: {
cartId: cart._id,
Expand All @@ -68,7 +68,7 @@ describe('Add to Cart', function() {
assert.equal(findCart.body.items.length, 2);
assert.equal(findCart.body.items[0].quantity, 2);
assert.equal(findCart.body.items[1].quantity, 1);
params.body = JSON.stringify(params.body)
params.body = JSON.stringify(params.body);
const updateCart = await addToCart(params);
updateCart.body = JSON.parse(updateCart.body);
assert(updateCart.body);
Expand Down
8 changes: 4 additions & 4 deletions examples/ecommerce-netlify-functions/test/checkout.test.js
Expand Up @@ -7,7 +7,7 @@ const { handler: checkout } = require('../netlify/functions/checkout');
const mongoose = require('mongoose');
const fixtures = require('./fixtures');
const sinon = require('sinon');
const stripe = require('../integrations/stripe')
const stripe = require('../integrations/stripe');

describe('Checkout', function() {
it('Should do a successful checkout run', async function() {
Expand All @@ -32,9 +32,9 @@ describe('Checkout', function() {
assert(result.body);
assert(result.body.items.length);
params.body.cartId = result.body._id;
sinon.stub(stripe.paymentIntents, 'retrieve').returns({status: 'succeeded', id: '123', brand: 'visa', last4: '1234'});
sinon.stub(stripe.paymentMethods, 'retrieve').returns({status: 'succeeded', id: '123', brand: 'visa', last4: '1234'});
sinon.stub(stripe.checkout.sessions, 'create').returns({status: 'succeeded', id: '123', brand: 'visa', last4: '1234'});
sinon.stub(stripe.paymentIntents, 'retrieve').returns({ status: 'succeeded', id: '123', brand: 'visa', last4: '1234' });
sinon.stub(stripe.paymentMethods, 'retrieve').returns({ status: 'succeeded', id: '123', brand: 'visa', last4: '1234' });
sinon.stub(stripe.checkout.sessions, 'create').returns({ status: 'succeeded', id: '123', brand: 'visa', last4: '1234' });
params.body.product = params.body.items;
params.body.name = 'Test Testerson';
params.body.email = 'test@localhost.com';
Expand Down
@@ -1,7 +1,7 @@
const {Cart} = require('../../models');
const { Cart } = require('../../models');


module.exports = async function createCart(params) {
const cart = await Cart.create({items: params.products});
return { cart };
}
const cart = await Cart.create({ items: params.products });
return { cart };
};
Expand Up @@ -2,6 +2,6 @@ const { Order } = require('../../models');

module.exports = async function createOrder(params) {

const order = await Order.create(params.order);
return { order };
};
const order = await Order.create(params.order);
return { order };
};
@@ -1,7 +1,7 @@
const { Product } = require('../../models');

module.exports = async function createProducts(params) {
const products = await Product.create(params.product);
const products = await Product.create(params.product);

return { products };
};
return { products };
};
8 changes: 4 additions & 4 deletions examples/ecommerce-netlify-functions/test/fixtures/index.js
Expand Up @@ -5,7 +5,7 @@ const createProducts = require('./createProducts');
const createOrder = require('./createOrder');

module.exports = {
createCart: createCart,
createProducts: createProducts,
createOrder: createOrder
}
createCart: createCart,
createProducts: createProducts,
createOrder: createOrder
};
2 changes: 1 addition & 1 deletion examples/ecommerce-netlify-functions/test/getCart.test.js
Expand Up @@ -12,7 +12,7 @@ describe('Get the cart given an id', function() {
const params = {
queryStringParameters: {
cartId: cart._id
},
}
};
const findCart = await getCart(params);
assert.equal(findCart.statusCode, 200);
Expand Down
Expand Up @@ -17,4 +17,4 @@ describe('Products', function() {
const result = await getProducts();
assert(result);
});
});
});
Expand Up @@ -33,7 +33,7 @@ describe('Remove From Cart', function() {
body: {
cartId: result.body._id,
item: {
productId: products[0]._id,
productId: products[0]._id
}
}
};
Expand All @@ -44,8 +44,8 @@ describe('Remove From Cart', function() {
});

it('Should create a cart and then it should reduce the quantity of an 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: [{ productName: 'A Test Products', productPrice: 500 }, { productName: 'Another Test Product', productPrice: 600 }] })
.then((res) => res.products);
const params = {
body: {
cartId: null,
Expand Down Expand Up @@ -74,4 +74,4 @@ describe('Remove From Cart', function() {
remove.body = JSON.parse(remove.body);
assert.equal(remove.body.items[0].quantity, 1);
});
});
});
2 changes: 1 addition & 1 deletion examples/ecommerce-netlify-functions/test/setup.test.js
Expand Up @@ -11,4 +11,4 @@ before(async() => {

after(async function() {
await mongoose.disconnect();
});
});