test('[Success] Add a variant to a product', async t => { const variant = { title: 'test-jacket-variant', price: '200.00', stock: 10, product: g.products[0]._id }; const res = await g.request .post('/admin/product/addvariant') .send(variant) .set('apiKey', g.users[0].apiKey) .expect(200); // Check the returned message t.deepEqual(res.body.message, 'Successfully added variant'); t.deepEqual(res.body.product.variants[0].title, variant.title); t.deepEqual(res.body.product.variants[0].price, variant.price); t.deepEqual(res.body.product.variants[0].stock, variant.stock); t.deepEqual(res.body.product.variants[0].product, g.products[0]._id.toString()); });
test('[Success] Update existing variant', async t => { const editVariant = { product: g.variants[0].product, variant: g.variants[0]._id, title: 'edited-title', price: '55.55', stock: 55 }; const res = await g.request .post('/admin/product/editvariant') .send(editVariant) .set('apiKey', g.users[0].apiKey) .expect(200); // Check the returned message t.deepEqual(res.body.message, 'Successfully saved variant'); t.deepEqual(res.body.variant._id, editVariant.variant.toString()); t.deepEqual(res.body.variant.product, editVariant.product.toString()); t.deepEqual(res.body.variant.title, editVariant.title); t.deepEqual(res.body.variant.price, editVariant.price); t.deepEqual(res.body.variant.stock, editVariant.stock); });
title: req.body.title, price: req.body.price, stock: safeParseInt(req.body.stock) || null };
title: req.body.title, price: req.body.price, stock: safeParseInt(req.body.stock) || null };
productStock = variant.stock;
}); if(variant){ productCurrentStock = variant.stock; }else{ productCurrentStock = 0;
function productOverview( product ) { return { id: product.id, name: product.name, permalink: product.permalink, price: product.price, imageUrl: product.imageUrl, stock: product.stock, }; }
// stock.symbols.getStockList().then((data)=>{ // console.log(data); // }); // stock.trading.getMonthHis("sh600005").then((data) => { // console.log(data); // }); dip.stock.symbols.getBoards("600005").then((data) => { console.log(data); });
productService.on('store', async (req, cb) => { let product = ProductModel.create({ title: req.body.title, price: req.body.price, stock: req.body.stock }) cb(product) })
const mapStateToProps = (state) => { return { itemsInStock: state.stock } }
const incrementAction = (id) => (dispatch, getState) => { const { stock } = getState() if (selectIdItem(stock, id).stock > 0) { console.log('action-in') dispatch(decrementStock(id)) dispatch(incrementAmount(id)) } }
describe('stock', () => { test('stock length', () => { expect(stock).toHaveLength(27) }) test('stock has the right props', () => { stock.forEach(e => expect(e).toMatchObject({ productId: expect.any(Number), stock: expect.any(Number) })) }) test('stock prop is not a real number', () => { stock.forEach(e => expect(Number.isInteger(e.stock)).toBe(true)) }) })
dispatch () { return transactionHelper.openReadCommitted((transaction) => this.stock.remove(this.invoice.quantity, transaction).then(() => Payment.createWithinTransaction(this.invoice.pokemon.id, this.invoice.quantity, transaction) ) ) }
test('[Success] Add a variant with null stock', async t => { const variant = { title: 'test-jacket-variant', price: '200.00', stock: null, product: g.products[0]._id }; const res = await g.request .post('/admin/product/addvariant') .send(variant) .set('apiKey', g.users[0].apiKey) .expect(200); // Check the returned message t.deepEqual(res.body.message, 'Successfully added variant'); t.deepEqual(res.body.product.variants[0].title, variant.title); t.deepEqual(res.body.product.variants[0].price, variant.price); t.deepEqual(res.body.product.variants[0].stock, variant.stock); t.deepEqual(res.body.product.variants[0].product, g.products[0]._id.toString()); });