code from amapei

This commit is contained in:
cagette@ct8
2020-09-26 18:25:18 +00:00
parent 42fe367911
commit 72b4699871
1966 changed files with 220437 additions and 2 deletions
+20
View File
@@ -0,0 +1,20 @@
package test;
import js.Browser;
import utest.Runner;
import utest.ui.Report;
import test.utils.TestCartUtils;
class TestAll
{
public static function main()
{
var runner = new Runner();
// Utils
runner.addCase(new TestCartUtils());
Report.create(runner);
runner.run();
}
}
+44
View File
@@ -0,0 +1,44 @@
[
{
"contractTaxName": null,
"desc": "Des grattons fait avec du cochon gascon, élevé en plein air et selon les préceptes de l'agriculture biologique. Meilleur que des rillettes!",
"vatValue": 0.234597156398104,
"price": 4.5,
"name": "Gratton de porc noir",
"type": 0,
"contractTax": null,
"contractId": 4672,
"orderable": true,
"hasFloatQt": false,
"id": 56610,
"qt": 190,
"unitType": 2,
"ref": "GRA-1",
"vat": 5.5,
"categories": null,
"stock": null,
"organic": false,
"image": "/img/taxo/cat10.png"
},
{
"contractTaxName": null,
"desc": "Un pâté savoureux qui se mange sans modération! Date de péremption : 1 Avril 2019 Lot : L16AV01P Poids : 200gr Ingrédients : Viande de porc issue de lagriculture biologique, Sel, Poivre",
"vatValue": 0.297156398104265,
"price": 5.7,
"name": "Pâté de porc noir",
"type": 0,
"contractTax": null,
"contractId": 4672,
"orderable": true,
"hasFloatQt": false,
"id": 56611,
"qt": 1,
"unitType": 0,
"ref": "PAPN-1",
"vat": 5.5,
"categories": null,
"stock": null,
"organic": false,
"image": "/file/2521_6a77c954191e5a2d8cd5a5d8cade4f6b.PNG"
}
]
+58
View File
@@ -0,0 +1,58 @@
package test.utils;
import sys.io.File.getContent;
import haxe.Json.parse;
import utest.Assert;
import utils.CartUtils;
import Common;
class TestCartUtils
{
static var products:Array<ProductInfo>;
public function new() {
var http = new haxe.Http("localhost/js/test/mocks.json?format=json");
products = parse(getContent("js/test/mocks.json"));
}
public function testAddToCart()
{
var order = {
products: [{
product: products[0],
quantity: 1
}],
total: products[0].price
};
var newProduct = products[1];
order = CartUtils.addToCart(order, newProduct, 1);
Assert.equals(order.products.length, 2);
Assert.equals(order.total, products[0].price + products[1].price);
order = CartUtils.addToCart(order, newProduct, 3);
Assert.equals(order.products[1].quantity, 4);
Assert.equals(order.total, products[0].price + 4 * products[1].price);
}
public function testRemoveFromCart()
{
var order = {
products: [{
product: products[0],
quantity: 5
}, {
product: products[1],
quantity: 3
}],
total: 5 * products[0].price + 3 * products[1].price
};
order = CartUtils.removeFromCart(order, products[0], 2);
Assert.equals(order.products[0].quantity, 3);
Assert.equals(order.total, 3 * products[0].price + 3 * products[1].price);
order = CartUtils.removeFromCart(order, products[1]);
Assert.equals(order.products.length, 1);
Assert.equals(order.total, 3 * products[0].price);
}
}