Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

producteca-sdk

Package Overview
Dependencies
Maintainers
2
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

producteca-sdk - npm Package Compare versions

Comparing version 0.0.21 to 0.0.22

producteca-sdk.sublime-project

0

build/productecaApi.js

@@ -0,0 +0,0 @@ (function() {

(function() {
var Adjustment, smartParseFloat, _;
var Adjustment, smartParseFloat, smartParseInt, trimIfStr, _,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

@@ -11,3 +12,3 @@ _ = require("lodash");

}
if (typeof str === 'number') {
if (_.isNumber(str)) {
return str;

@@ -24,16 +25,99 @@ }

smartParseInt = (function(_this) {
return function(n) {
if (_.isNumber(n)) {
return n;
} else {
return parseInt(n);
}
};
})(this);
trimIfStr = (function(_this) {
return function(str) {
if (_.isString(str)) {
return str.trim();
} else {
return str;
}
};
})(this);
module.exports = Adjustment = (function() {
function Adjustment(dto) {
this._adaptStock = __bind(this._adaptStock, this);
this._adaptPrice = __bind(this._adaptPrice, this);
this.forEachStock = __bind(this.forEachStock, this);
this.forEachPrice = __bind(this.forEachPrice, this);
var _ref;
dto = _.mapValues(dto, function(it) {
if (it != null) {
return it.trim();
if (_.isArray(it)) {
return it.map((function(_this) {
return function(val) {
return _.mapValues(val, function(inner) {
return trimIfStr(inner);
});
};
})(this));
} else {
return it;
return trimIfStr(it);
}
});
_.extend(this, dto);
this.price = smartParseFloat(dto.price);
this.stock = _.max([0, parseInt(dto.stock)]);
if (this.prices != null) {
this.prices.forEach((function(_this) {
return function(it) {
return it.value = _this._adaptPrice(it.value);
};
})(this));
} else {
this.price = this._adaptPrice(this.price);
}
if (this.stocks != null) {
if ((_ref = this.stocks) != null) {
_ref.forEach((function(_this) {
return function(it) {
return it.quantity = _this._adaptStock(it.quantity);
};
})(this));
}
} else {
this.stock = this._adaptStock(this.stock);
}
}
Adjustment.prototype.forEachPrice = function(fn) {
if (this.prices == null) {
return fn(this.price);
}
return this.prices.forEach((function(_this) {
return function(_arg) {
var priceList, value;
value = _arg.value, priceList = _arg.priceList;
return fn(value, priceList);
};
})(this));
};
Adjustment.prototype.forEachStock = function(fn) {
if (this.stocks == null) {
return fn(this.stock);
}
return this.stocks.forEach((function(_this) {
return function(_arg) {
var quantity, warehouse;
quantity = _arg.quantity, warehouse = _arg.warehouse;
return fn(quantity, warehouse);
};
})(this));
};
Adjustment.prototype._adaptPrice = function(price) {
return smartParseFloat(price);
};
Adjustment.prototype._adaptStock = function(stock) {
return _.max([0, smartParseInt(stock)]);
};
return Adjustment;

@@ -40,0 +124,0 @@

109

build/syncer/adjustment.spec.js
(function() {
var AjusteStock;
var Adjustment;
AjusteStock = require("./adjustment");
Adjustment = require("./adjustment");
describe("Ajustment", function() {
it("does trim to the basic properties", function() {
var ajusteStock;
ajusteStock = new AjusteStock({
var adjustment;
adjustment = new Adjustment({
identifier: "915004085101 ",
name: "COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA "
});
ajusteStock.identifier.should.equal("915004085101");
return ajusteStock.name.should.equal("COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA");
adjustment.identifier.should.equal("915004085101");
return adjustment.name.should.equal("COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA");
});
it("does trim to the inner properties in arrays", function() {
return new Adjustment({
stocks: [
{
warehouse: " hola"
}
]
}).stocks[0].warehouse.should.equal("hola");
});
describe("parsing price to float...", function() {
it("thousands separator: ','; decimals separator: '.'", function() {
return new AjusteStock({
price: "4,160.99"
}).price.should.equal(4160.99);
return new Adjustment({
prices: [
{
value: "4,160.99"
}
]
}).prices[0].value.should.equal(4160.99);
});
it("thousands separator: '.'; decimals separator: ','", function() {
return new AjusteStock({
price: "4.160,99"
}).price.should.equal(4160.99);
return new Adjustment({
prices: [
{
value: "4.160,99"
}
]
}).prices[0].value.should.equal(4160.99);
});
it("without thousands separator", function() {
return new AjusteStock({
price: "4160.99"
}).price.should.equal(4160.99);
return new Adjustment({
prices: [
{
value: "4160.99"
}
]
}).prices[0].value.should.equal(4160.99);
});
return it("without thousands and decimals separator", function() {
return new AjusteStock({
price: "4160"
}).price.should.equal(4160);
it("without thousands and decimals separator", function() {
return new Adjustment({
prices: [
{
value: "4160"
}
]
}).prices[0].value.should.equal(4160);
});
return it("don't try to parse the price if it's a Number", function() {
return new Adjustment({
prices: [
{
value: 4160
}
]
}).prices[0].value.should.equal(4160);
});
});
it("parses the stock to int", function() {
return new AjusteStock({
stock: "2.00"
}).stock.should.equal(2);
return describe("parsing stocks to int...", function() {
it("parses the stock to int if it's a string", function() {
return new Adjustment({
stocks: [
{
quantity: "2.00"
}
]
}).stocks[0].quantity.should.equal(2);
});
it("don't try to parse the stock if it's a Number", function() {
return new Adjustment({
stocks: [
{
quantity: 2
}
]
}).stocks[0].quantity.should.equal(2);
});
return it("intializes the stock in 0 when the provided is lower", function() {
return new Adjustment({
stocks: [
{
quantity: "-4.00"
}
]
}).stocks[0].quantity.should.equal(0);
});
});
return it("intializes the stock in 0 when the provided is lower", function() {
return new AjusteStock({
stock: "-4.00"
}).stock.should.equal(0);
});
});
}).call(this);

@@ -93,4 +93,11 @@ (function() {

Syncer.prototype._updatePrice = function(adjustment, product) {
console.log("Updating price of ~" + adjustment.identifier + "(" + product.id + ") with value $" + adjustment.price + "...");
return this.productecaApi.updatePrice(product, this.settings.priceList, adjustment.price);
return adjustment.forEachPrice((function(_this) {
return function(price, priceList) {
if (priceList == null) {
priceList = _this.settings.priceList;
}
console.log("Updating price of ~" + adjustment.identifier + "(" + product.id + ") in priceList " + priceList + " with value $" + price + "...");
return _this.productecaApi.updatePrice(product, priceList, price);
};
})(this));
};

@@ -101,13 +108,20 @@

variationId = this._getVariation(product, adjustment).id;
console.log("Updating stock of ~" + adjustment.identifier + "(" + product.id + ", " + variationId + ") with quantity " + adjustment.stock + "...");
return this.productecaApi.updateStocks({
id: product.id,
warehouse: this.settings.warehouse,
stocks: [
{
variation: variationId,
quantity: adjustment.stock
return adjustment.forEachStock((function(_this) {
return function(stock, warehouse) {
if (warehouse == null) {
warehouse = _this.settings.warehouse;
}
]
});
console.log("Updating stock of ~" + adjustment.identifier + "(" + product.id + ", " + variationId + ") in warehouse " + warehouse + " with quantity " + stock + "...");
return _this.productecaApi.updateStocks({
id: product.id,
warehouse: warehouse,
stocks: [
{
variation: variationId,
quantity: stock
}
]
});
};
})(this));
};

@@ -114,0 +128,0 @@

(function() {
var Product, Q, Syncer, chai, sinon, _;
var Adjustment, Product, Q, Syncer, chai, sinon, _;

@@ -14,2 +14,4 @@ _ = require("lodash");

Adjustment = require("./adjustment");
chai = require("chai");

@@ -101,22 +103,95 @@

});
it("se ignoran los productos cuyo sku es vacio", function() {
syncer.execute([
{
identifier: "",
stock: 40
}
]);
return client.updateStocks.called.should.be["false"];
describe("en el caso más completo (variantes - multi listaDePrecios / depósito)...", function() {
beforeEach(function() {
syncer.settings.identifier = "barcode";
return syncer.execute([
new Adjustment({
identifier: "CamperaRompeNocheNegra",
prices: [
{
priceList: "Precios Cuidados",
value: "30"
}, {
priceList: "Con Tarjeta de Crédito",
value: "90"
}
],
stocks: [
{
warehouse: "Villa Lugano",
quantity: 20
}
]
}), new Adjustment({
identifier: "CamperaRompeNocheBlanca",
prices: [
{
priceList: "Default",
value: "99"
}
],
stocks: [
{
warehouse: "Palermo",
quantity: 38
}
]
})
]);
});
it("actualiza los precios", function() {
client.updatePrice.should.have.callCount(3);
client.updatePrice.should.have.been.calledWith(camperaVariable, "Precios Cuidados", 30);
client.updatePrice.should.have.been.calledWith(camperaVariable, "Con Tarjeta de Crédito", 90);
return client.updatePrice.should.have.been.calledWith(camperaVariable, "Default", 99);
});
return it("actualiza los stocks", function() {
client.updateStocks.should.have.callCount(2);
client.updateStocks.should.have.been.calledWith({
id: 1,
warehouse: "Villa Lugano",
stocks: [
{
variation: 2,
quantity: 20
}
]
});
return client.updateStocks.should.have.been.calledWith({
id: 1,
warehouse: "Palermo",
stocks: [
{
variation: 4,
quantity: 38
}
]
});
});
});
describe("cuando los productos no tienen variantes...", function() {
var ajuste;
ajuste = {
ajuste = new Adjustment({
identifier: "123456",
price: 25,
stock: 40
};
});
it("se ignoran los productos cuyo sku es vacio", function() {
syncer.execute([
{
identifier: "",
stock: 40
}
]);
return client.updateStocks.called.should.be["false"];
});
it("_joinAdjustmentsAndProducts linkea ajustes con productos de Producteca", function() {
var ajustes;
var ajustes, clean;
ajustes = syncer._joinAdjustmentsAndProducts([ajuste]);
return ajustes.linked[0].should.eql({
clean = (function(_this) {
return function(o) {
return JSON.parse(JSON.stringify(o));
};
})(this);
return clean(ajustes.linked[0]).should.eql(clean({
adjustment: {

@@ -128,5 +203,5 @@ identifier: "123456",

products: [campera, camperaVariable]
});
}));
});
describe("al ejecutar dispara una request a Parsimotion matcheando el id segun sku", function() {
describe("al ejecutar dispara una request a Producteca matcheando el id segun sku", function() {
beforeEach(function() {

@@ -170,52 +245,17 @@ return syncer.execute([ajuste]);

});
describe("ejecutar devuelve un objeto con el resultado de la sincronizacion:", function() {
var resultadoShouldHaveProperty;
resultadoShouldHaveProperty = null;
beforeEach(function() {
var resultado;
resultado = syncer.execute([
{
identifier: "123456",
stock: 28
}, {
identifier: "55555",
stock: 70
}
]);
return resultadoShouldHaveProperty = function(name, value) {
return resultado.then(function(actualizados) {
return actualizados[name].should.eql(value);
});
};
});
it("los unlinked", function() {
return resultadoShouldHaveProperty("unlinked", [
{
identifier: "55555"
}
]);
});
return it("los linked", function() {
return resultadoShouldHaveProperty("linked", [
{
identifier: "123456"
}
]);
});
});
return describe("cuando los productos sí tienen variantes...", function() {
describe("cuando los productos sí tienen variantes...", function() {
it("cuando sincronizo por sku: no sincroniza las variantes", function() {
var ajustes;
ajustes = [
{
new Adjustment({
identifier: "CamperaRompeNocheNegra",
price: 11,
stock: 23
}, {
}), new Adjustment({
identifier: "CamperaRompeNocheBlanca",
price: 12,
stock: 24
}, {
}), new Adjustment({
identifier: "123456"
}
})
];

@@ -245,13 +285,13 @@ return syncer.execute(ajustes).then((function(_this) {

ajustes = [
{
new Adjustment({
identifier: "CamperaRompeNocheNegra",
price: 11,
stock: 23
}, {
}), new Adjustment({
identifier: "CamperaRompeNocheBlanca",
price: 12,
stock: 24
}, {
}), new Adjustment({
identifier: "123456"
}
})
];

@@ -276,4 +316,39 @@ return syncer.execute(ajustes).then((function(_this) {

});
return describe("resultado de la sincronización...", function() {
var resultadoShouldHaveProperty;
resultadoShouldHaveProperty = null;
beforeEach(function() {
var resultado;
resultado = syncer.execute([
new Adjustment({
identifier: "123456",
stock: 28
}), new Adjustment({
identifier: "55555",
stock: 70
})
]);
return resultadoShouldHaveProperty = function(name, value) {
return resultado.then(function(actualizados) {
return actualizados[name].should.eql(value);
});
};
});
it("los unlinked", function() {
return resultadoShouldHaveProperty("unlinked", [
{
identifier: "55555"
}
]);
});
return it("los linked", function() {
return resultadoShouldHaveProperty("linked", [
{
identifier: "123456"
}
]);
});
});
});
}).call(this);

@@ -8,6 +8,7 @@ {

},
"version": "0.0.21",
"version": "0.0.22",
"main": "build/sdk.js",
"dependencies": {
"bluebird": "^2.3.11",
"grunt-bump": "^0.3.1",
"lodash": "~2.4.1",

@@ -14,0 +15,0 @@ "q": "~1.0.1",

# Producteca SDK

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc