diff --git a/Makefile b/Makefile index 4c0d03f..e721bbe 100644 --- a/Makefile +++ b/Makefile @@ -28,9 +28,6 @@ install_dev: sudo mv temploc2 /usr/bin #extra plugins @if [ $(PLUGINS) = 1 ]; then \ - haxelib git cagette-pro git@bitbucket.org:bubar/cagette-pro.git; \ - haxelib git cagette-hosted git@bitbucket.org:bubar/cagette-hosted.git; \ - haxelib git cagette-wholesale-order git@github.com:bablukid/cagette-wholesale-order.git; \ fi #install npm dependencies npm install @@ -82,20 +79,5 @@ templates: chown www-data:www-data -R www ctemplates: -# (cd lang/$(LANG)/tpl; temploc2 -macros macros.mtt -output ../tmp/ *.mtt */*.mtt */*/*.mtt */*/*/*.mtt */*/*/*/*.mtt) (cd lang/$(LANG)/tpl; temploc2 -macros macros.mtt -output ../tmp/ *.mtt */*.mtt */*/*.mtt) -#Compile and run unit tests -tests: - @if [ $(PLUGINS) = 1 ]; then \ - haxe testsPlugins.hxml; \ - else \ - haxe tests.hxml; \ - fi - @docker-compose run --workdir="/var/www/www" neko neko tests.n mysql://root:root@mysql/tests - -cp_plugin: - cp -R .haxelib/cagette-hosted/git/tpl/* lang/master/tpl/plugin/hosted/ - cp -R .haxelib/cagette-pro/git/tpl/* lang/master/tpl/plugin/pro/ - cp -R .haxelib/cagette-wholesale-order/git/tpl/* lang/master/tpl/plugin/who/ - diff --git a/cagetteAllPlugins.hxml b/cagetteAllPlugins.hxml deleted file mode 100755 index 6762dc0..0000000 --- a/cagetteAllPlugins.hxml +++ /dev/null @@ -1,26 +0,0 @@ --lib templo --lib hxevents --lib thx.semver --lib thx.csv --lib datetime --lib hscript --lib smtpmailer --lib tink_json - --lib sugoi:git:https://github.com/bablukid/sugoi#master --lib record-macros:git:https://github.com/HaxeFoundation/record-macros#master --lib dbadmin:git:https://github.com/ncannasse/dbadmin.git#master - --lib cagette-pro:git:https://bubar@bitbucket.org/bubar/cagette-pro.git#master --lib cagette-hosted:git:https://bubar@bitbucket.org/bubar/cagette-hosted.git#master --lib cagette-wholesale-order:git:https://github.com/bablukid/cagette-wholesale-order.git#master - --cp common --cp src --cp lang/master/tpl - --D plugins - - --neko www/index.n --main App \ No newline at end of file diff --git a/cagetteAllPlugins.hxproj b/cagetteAllPlugins.hxproj deleted file mode 100755 index f6f1362..0000000 --- a/cagetteAllPlugins.hxproj +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/cagetteAllPluginsJs.hxml b/cagetteAllPluginsJs.hxml deleted file mode 100644 index 0e7469f..0000000 --- a/cagetteAllPluginsJs.hxml +++ /dev/null @@ -1,17 +0,0 @@ --dce no --cp common --cp js --lib sugoi:git:https://github.com/bablukid/sugoi#i18n --lib hxleaflet:git:https://github.com/bablukid/hxleaflet --lib cagette-hosted --lib react --lib react-router-4 --lib modular --lib tink_json - --D plugins --D no-deprecation-warnings - --main App --js www/js/app.js - diff --git a/package-lock.json b/package-lock.json index 859964b..ac95480 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,7 +1,8 @@ { - "name": "Cagette.net", - "requires": true, + "name": "CagettePei", + "version": "1.6.0", "lockfileVersion": 1, + "requires": true, "dependencies": { "@types/react": { "version": "16.0.0", diff --git a/src/test/TestDistributions.hx b/src/test/TestDistributions.hx deleted file mode 100644 index fb6e5c0..0000000 --- a/src/test/TestDistributions.hx +++ /dev/null @@ -1,299 +0,0 @@ -package test; - -/** - * Test distribution creation - * - * @author web-wizard - */ -class TestDistributions extends haxe.unit.TestCase -{ - - public function new(){ - super(); - } - - /** - * - */ - override function setup(){ - TestSuite.initDB(); - TestSuite.initDatas(); - } - - /** - * Check that we can add a distribution outside existing time range for a specific contract and place - * Check that we can't add a distribution overlapping with existing distribution for a specific contract and place - */ - function testOverlapping() { - var existingDistrib = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE; - var e1 = null; - try { - var distrib1 = service.DistributionService.create(existingDistrib.contract,new Date(2018, 5, 1, 18, 0, 0),new Date(2018, 5, 1, 18, 30, 0), - existingDistrib.place.id,null,null,null,null,new Date(2018, 4, 1, 18, 0, 0),new Date(2018, 4, 30, 18, 30, 0)); - } - catch(x:tink.core.Error) { - e1 = x; - } - assertEquals(e1, null); - - //existingDistrib.date <= distrib2.date && existingDistrib.end >= distrib2.date - var e2 = null; - try { - var distrib2 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 5, 1, 19, 30, 0),new Date(2017, 5, 1, 20, 30, 0), - existingDistrib.place.id,null,null,null,null,new Date(2017, 4, 1, 18, 0, 0),new Date(2017, 4, 30, 18, 30, 0)); - } - catch(x:tink.core.Error) { - e2 = x; - } - assertEquals(e2.message, "There is already a distribution at this place overlapping with the time range you've selected."); - - //existingDistrib.date <= distrib3.end && existingDistrib.end >= distrib3.end - var e3 = null; - try{ - var distrib3 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 5, 1, 17, 30, 0),new Date(2017, 5, 1, 19, 30, 0), - existingDistrib.place.id,null,null,null,null,new Date(2017, 4, 1, 18, 0, 0),new Date(2017, 4, 30, 18, 30, 0)); - } - catch(x:tink.core.Error){ - e3 = x; - } - assertEquals(e3.message, "There is already a distribution at this place overlapping with the time range you've selected."); - - //existingDistrib.date >= distrib4.date && existingDistrib.end <= distrib4.end - var e4 = null; - try{ - var distrib4 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 5, 1, 17, 30, 0),new Date(2017, 5, 1, 21, 30, 0), - existingDistrib.place.id,null,null,null,null,new Date(2017, 4, 1, 18, 0, 0),new Date(2017, 4, 30, 18, 30, 0)); - } - catch(x:tink.core.Error){ - e4 = x; - } - assertEquals(e4.message, "There is already a distribution at this place overlapping with the time range you've selected."); - - //existingDistrib.date > distrib5.end - var e5 = null; - try{ - var distrib5 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 5, 1, 17, 30, 0),new Date(2017, 5, 1, 18, 59, 0), - existingDistrib.place.id,null,null,null,null,new Date(2017, 4, 1, 18, 0, 0),new Date(2017, 4, 30, 18, 30, 0)); - } - catch(x:tink.core.Error){ - e5 = x; - } - assertEquals(e5, null); - - //existingDistrib.date > distrib6.end - var e6 = null; - try{ - var distrib6 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 3, 1, 17, 30, 0),new Date(2017, 3, 1, 18, 59, 0), - existingDistrib.place.id,null,null,null,null,new Date(2017, 2, 1, 18, 0, 0),new Date(2017, 3, 30, 18, 30, 0)); - } - catch(x:tink.core.Error){ - e6 = x; - } - assertEquals(e6.message, "The distribution start date must be set after the orders end date."); - - } - - /** - * Check that we can add a distribution outside existing time range for a specific contract and place - * Check that we can't add a distribution overlapping with existing distribution for a specific contract and place - */ - function testEdit() { - - //TO DO - assertEquals(true, true); - } - - function testCreateCycle() { - TestSuite.CONTRAT_LEGUMES.startDate = new Date(2018, 0, 1, 0, 0, 0); - TestSuite.CONTRAT_LEGUMES.endDate = new Date(2019, 11, 31, 23, 59, 0); - TestSuite.CONTRAT_LEGUMES.update(); - - var weeklyDistribCycle = service.DistributionService.createCycle(TestSuite.CONTRAT_LEGUMES,Weekly,new Date(2018, 11, 24, 0, 0, 0), - new Date(2019, 0, 24, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2, - new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id); - - var weeklyDistribs = Lambda.array(db.Distribution.manager.search($distributionCycle == weeklyDistribCycle, false)); - assertEquals(weeklyDistribs.length, 5); - assertEquals(weeklyDistribs[0].date.toString(), new Date(2018, 11, 24, 13, 0, 0).toString()); - assertEquals(weeklyDistribs[0].end.toString(), new Date(2018, 11, 24, 14, 0, 0).toString()); - assertEquals(weeklyDistribs[1].date.toString(), new Date(2018, 11, 31, 13, 0, 0).toString()); - assertEquals(weeklyDistribs[1].end.toString(), new Date(2018, 11, 31, 14, 0, 0).toString()); - assertEquals(weeklyDistribs[2].date.toString(), new Date(2019, 0, 7, 13, 0, 0).toString()); - assertEquals(weeklyDistribs[2].end.toString(), new Date(2019, 0, 7, 14, 0, 0).toString()); - assertEquals(weeklyDistribs[3].date.toString(), new Date(2019, 0, 14, 13, 0, 0).toString()); - assertEquals(weeklyDistribs[3].end.toString(), new Date(2019, 0, 14, 14, 0, 0).toString()); - assertEquals(weeklyDistribs[4].date.toString(), new Date(2019, 0, 21, 13, 0, 0).toString()); - assertEquals(weeklyDistribs[4].end.toString(), new Date(2019, 0, 21, 14, 0, 0).toString()); - service.DistributionService.deleteCycleDistribs(weeklyDistribCycle); - - var monthlyDistribCycle = service.DistributionService.createCycle(TestSuite.CONTRAT_LEGUMES,Monthly,new Date(2018, 9, 30, 0, 0, 0), - new Date(2019, 2, 31, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2, - new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id); - - var monthlyDistribs = Lambda.array(db.Distribution.manager.search($distributionCycle == monthlyDistribCycle, false)); - assertEquals(monthlyDistribs.length, 6); - assertEquals(monthlyDistribs[0].date.toString(), new Date(2018, 9, 30, 13, 0, 0).toString()); - assertEquals(monthlyDistribs[0].end.toString(), new Date(2018, 9, 30, 14, 0, 0).toString()); - assertEquals(monthlyDistribs[1].date.toString(), new Date(2018, 10, 27, 13, 0, 0).toString()); - assertEquals(monthlyDistribs[1].end.toString(), new Date(2018, 10, 27, 14, 0, 0).toString()); - assertEquals(monthlyDistribs[2].date.toString(), new Date(2018, 11, 25, 13, 0, 0).toString()); - assertEquals(monthlyDistribs[2].end.toString(), new Date(2018, 11, 25, 14, 0, 0).toString()); - assertEquals(monthlyDistribs[3].date.toString(), new Date(2019, 0, 29, 13, 0, 0).toString()); - assertEquals(monthlyDistribs[3].end.toString(), new Date(2019, 0, 29, 14, 0, 0).toString()); - assertEquals(monthlyDistribs[4].date.toString(), new Date(2019, 1, 26, 13, 0, 0).toString()); - assertEquals(monthlyDistribs[4].end.toString(), new Date(2019, 1, 26, 14, 0, 0).toString()); - assertEquals(monthlyDistribs[5].date.toString(), new Date(2019, 2, 26, 13, 0, 0).toString()); - assertEquals(monthlyDistribs[5].end.toString(), new Date(2019, 2, 26, 14, 0, 0).toString()); - service.DistributionService.deleteCycleDistribs(monthlyDistribCycle); - - var biweeklyDistribCycle = service.DistributionService.createCycle(TestSuite.CONTRAT_LEGUMES,BiWeekly,new Date(2018, 9, 30, 0, 0, 0), - new Date(2019, 0, 31, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2, - new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id); - - var biweeklyDistribs = Lambda.array(db.Distribution.manager.search($distributionCycle == biweeklyDistribCycle, false)); - assertEquals(biweeklyDistribs.length, 7); - assertEquals(biweeklyDistribs[0].date.toString(), new Date(2018, 9, 30, 13, 0, 0).toString()); - assertEquals(biweeklyDistribs[0].end.toString(), new Date(2018, 9, 30, 14, 0, 0).toString()); - assertEquals(biweeklyDistribs[1].date.toString(), new Date(2018, 10, 13, 13, 0, 0).toString()); - assertEquals(biweeklyDistribs[1].end.toString(), new Date(2018, 10, 13, 14, 0, 0).toString()); - assertEquals(biweeklyDistribs[2].date.toString(), new Date(2018, 10, 27, 13, 0, 0).toString()); - assertEquals(biweeklyDistribs[2].end.toString(), new Date(2018, 10, 27, 14, 0, 0).toString()); - assertEquals(biweeklyDistribs[3].date.toString(), new Date(2018, 11, 11, 13, 0, 0).toString()); - assertEquals(biweeklyDistribs[3].end.toString(), new Date(2018, 11, 11, 14, 0, 0).toString()); - assertEquals(biweeklyDistribs[4].date.toString(), new Date(2018, 11, 25, 13, 0, 0).toString()); - assertEquals(biweeklyDistribs[4].end.toString(), new Date(2018, 11, 25, 14, 0, 0).toString()); - assertEquals(biweeklyDistribs[5].date.toString(), new Date(2019, 0, 8, 13, 0, 0).toString()); - assertEquals(biweeklyDistribs[5].end.toString(), new Date(2019, 0, 8, 14, 0, 0).toString()); - assertEquals(biweeklyDistribs[6].date.toString(), new Date(2019, 0, 22, 13, 0, 0).toString()); - assertEquals(biweeklyDistribs[6].end.toString(), new Date(2019, 0, 22, 14, 0, 0).toString()); - service.DistributionService.deleteCycleDistribs(biweeklyDistribCycle); - - var triweeklyDistribCycle = service.DistributionService.createCycle(TestSuite.CONTRAT_LEGUMES,TriWeekly,new Date(2018, 9, 30, 0, 0, 0), - new Date(2019, 0, 31, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2, - new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id); - - var triweeklyDistribs = Lambda.array(db.Distribution.manager.search($distributionCycle == triweeklyDistribCycle, false)); - assertEquals(triweeklyDistribs.length, 5); - assertEquals(triweeklyDistribs[0].date.toString(), new Date(2018, 9, 30, 13, 0, 0).toString()); - assertEquals(triweeklyDistribs[0].end.toString(), new Date(2018, 9, 30, 14, 0, 0).toString()); - assertEquals(triweeklyDistribs[1].date.toString(), new Date(2018, 10, 20, 13, 0, 0).toString()); - assertEquals(triweeklyDistribs[1].end.toString(), new Date(2018, 10, 20, 14, 0, 0).toString()); - assertEquals(triweeklyDistribs[2].date.toString(), new Date(2018, 11, 11, 13, 0, 0).toString()); - assertEquals(triweeklyDistribs[2].end.toString(), new Date(2018, 11, 11, 14, 0, 0).toString()); - assertEquals(triweeklyDistribs[3].date.toString(), new Date(2019, 0, 1, 13, 0, 0).toString()); - assertEquals(triweeklyDistribs[3].end.toString(), new Date(2019, 0, 1, 14, 0, 0).toString()); - assertEquals(triweeklyDistribs[4].date.toString(), new Date(2019, 0, 22, 13, 0, 0).toString()); - assertEquals(triweeklyDistribs[4].end.toString(), new Date(2019, 0, 22, 14, 0, 0).toString()); - service.DistributionService.deleteCycleDistribs(triweeklyDistribCycle); - } - - function testDelete() { - //A variable contract with a distribution that has orders - var ordersDistrib = TestSuite.DISTRIB_LEGUMES_RUE_SAUCISSE; - var ordersDistribId = ordersDistrib.id; - var chicken = TestSuite.CHICKEN; - var order = service.OrderService.make(TestSuite.FRANCOIS, 1, chicken, ordersDistrib.id); - - var e = null; - try{ - service.DistributionService.delete(ordersDistrib); - } - catch(x:tink.core.Error){ - e = x; - } - assertEquals(e.message, "Deletion non possible: some orders are saved for this delivery."); - assertTrue(db.Distribution.manager.get(ordersDistribId) != null); - - //A variable contract with a distribution that has no orders - var noOrdersDistrib = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE; - var noOrdersDistribId = noOrdersDistrib.id; - - var e = null; - try{ - service.DistributionService.delete(noOrdersDistrib); - } - catch(x:tink.core.Error){ - e = x; - } - assertEquals(e, null); - assertEquals(db.Distribution.manager.get(noOrdersDistribId), null); - - //An Amap contract with a distribution that has orders - var amapDistrib = TestSuite.DISTRIB_CONTRAT_AMAP; - var amapDistribId = amapDistrib.id; - var panier = TestSuite.PANIER_AMAP_LEGUMES; - var amapOrder = service.OrderService.make(TestSuite.FRANCOIS, 1, panier, amapDistrib.id); - - var e = null; - try{ - service.DistributionService.delete(amapDistrib); - } - catch(x:tink.core.Error){ - e = x; - } - assertEquals(e, null); - assertEquals(db.Distribution.manager.get(amapDistribId), null); - - } - - function testUpdateAmapContractOperations(){ - - var t = sugoi.i18n.Locale.texts; - - //Take an amap contract with payments enabled - //Take 2 users and make orders for each - var amapDistrib = TestSuite.DISTRIB_CONTRAT_AMAP; - var contract = amapDistrib.contract; - var panier = TestSuite.PANIER_AMAP_LEGUMES; - var francoisOrder = service.OrderService.make(TestSuite.FRANCOIS, 1, panier, amapDistrib.id); - db.Operation.onOrderConfirm([francoisOrder]); - var sebOrder = service.OrderService.make(TestSuite.SEB, 3, panier, amapDistrib.id); - db.Operation.onOrderConfirm([sebOrder]); - - //Check initial operation names and amounts - var francoisOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.FRANCOIS); - assertEquals(francoisOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 1 deliveries"); - assertEquals(francoisOperation.amount, -13); - var sebOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.SEB); - assertEquals(sebOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 1 deliveries"); - assertEquals(sebOperation.amount, -39); - - //Add a distrib - var distrib = null; - var e = null; - try{ - distrib = service.DistributionService.create(contract,new Date(2018, 5, 1, 18, 0, 0),new Date(2018, 5, 1, 18, 30, 0), - amapDistrib.place.id,null,null,null,null,new Date(2018, 4, 1, 18, 0, 0),new Date(2018, 4, 30, 18, 30, 0)); - } - catch(x:tink.core.Error){ - e = x; - } - //Check names and amounts are modified accordingly - assertEquals(francoisOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 2 deliveries"); - assertEquals(francoisOperation.amount, -26); - var sebOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.SEB); - assertEquals(sebOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 2 deliveries"); - assertEquals(sebOperation.amount, -78); - - //Add a distrib cycle - var weeklyDistribCycle = service.DistributionService.createCycle(contract,Weekly,new Date(2018, 11, 24, 0, 0, 0), - new Date(2019, 0, 24, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2, - new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id); - //Check names and amounts are modified accordingly - assertEquals(francoisOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 7 deliveries"); - assertEquals(francoisOperation.amount, -91); - var sebOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.SEB); - assertEquals(sebOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 7 deliveries"); - assertEquals(sebOperation.amount, -273); - - //Delete the distrib cycle - service.DistributionService.deleteCycleDistribs(weeklyDistribCycle); - //Check names and amounts are modified accordingly - assertEquals(francoisOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 2 deliveries"); - assertEquals(francoisOperation.amount, -26); - var sebOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.SEB); - assertEquals(sebOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 2 deliveries"); - assertEquals(sebOperation.amount, -78); - } - -} \ No newline at end of file diff --git a/src/test/TestOrders.hx b/src/test/TestOrders.hx deleted file mode 100644 index 5d80007..0000000 --- a/src/test/TestOrders.hx +++ /dev/null @@ -1,473 +0,0 @@ -package test; -import Common; -import service.OrderService; -/** - * Test order making, updating and deleting - * - * @author fbarbut - */ -class TestOrders extends haxe.unit.TestCase -{ - - public function new(){ - super(); - } - - var c : db.Contract; - var p : db.Product; - var bob : db.User; - - /** - * get a contract + a user + a product + empty orders - */ - override function setup(){ - - TestSuite.initDB(); - TestSuite.initDatas(); - - db.Basket.emptyCache(); - - c = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.contract; - - p = TestSuite.STRAWBERRIES; - p.lock(); - p.stock = 8; - p.update(); - - bob = db.User.manager.get(1); - - } - - /** - Test Basket creation and numbering - **/ - public function testBasket(){ - - var d = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE; - - var o = OrderService.make(TestSuite.FRANCOIS, 3, TestSuite.STRAWBERRIES, d.id); - assertEquals(1, o.basket.num); - - var o = OrderService.make(TestSuite.SEB, 1, TestSuite.STRAWBERRIES, d.id); - assertEquals(2, o.basket.num); - - //order again, should keep existing basket number - var o = OrderService.make(TestSuite.FRANCOIS, 1, TestSuite.APPLES, d.id); - assertEquals(1, o.basket.num); - - //check bug of 2018-07 : changing the date and place of the distribution leads to lost basket (because basket were indexed on user-date-place) - d.lock(); - d.date = new Date(2028,1,1,0,0,0); - - var place = new db.Place(); - place.name = "Chez Momo"; - place.zipCode = "54"; - place.amap = d.contract.amap; - place.insert(); - - d.place = place; - d.update(); - - //Seb's basket is still 2 - var basket = db.Basket.get(TestSuite.SEB,place,d.date); - assertEquals(2, basket.num); - - var o = OrderService.make(TestSuite.SEB, 1, TestSuite.APPLES, d.id); - assertEquals(2, o.basket.num); - - var o2 = OrderService.edit(o,5,true,null,false); - assertEquals(2, o2.basket.num); - - //order to a different distrib in same contract should start a new numbering - var d2 = service.DistributionService.create(d.contract,new Date(2026,6,6,0,0,0),new Date(2026,6,6,1,0,0),place.id,null,null,null,null,new Date(2026,6,4,0,0,0),new Date(2026,6,5,0,0,0)); - var o = OrderService.make(TestSuite.SEB, 12, TestSuite.APPLES, d2.id); - assertEquals(1, o.basket.num); - - - } - - /** - * make orders & stock management - */ - public function testStocks(){ - - var stock = p.stock; - - assertTrue(c.type == db.Contract.TYPE_VARORDER); - assertTrue(c.flags.has(db.Contract.ContractFlags.StockManagement)); - assertTrue(stock == 8); - - //bob orders 3 strawberries, stock fall to 2 - //order is update to 6 berries - App.current.eventDispatcher.addOnce(function(e:Event){ - switch(e){ - case StockMove(e): - assertTrue(e.move==-3); - assertTrue(e.product==p); - default: - } - }); - var o = OrderService.make(bob, 3, p, TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.id); - assertTrue(p.stock == 5); - assertTrue(o.quantity == 3); - - //bob orders 6 more. stock fall to 0, order is reduced to 5 - //quantity is not 9 but 8 - App.current.eventDispatcher.addOnce(function(e:Event){ - switch(e){ - case StockMove(e): - assertTrue(e.move==-5); - assertTrue(e.product==p); - default: - } - }); - var o = OrderService.make(bob, 6, p, TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.id); - assertTrue(p.stock == 0); - assertTrue(o.quantity == 8); - - //bob orders again but cant order anything - var o = OrderService.make(bob, 3, p, TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.id); - assertTrue(p.stock == 0); - assertTrue(o.quantity == 8); - - } - - /** - * test edit orders and stock management - */ - function testOrderEdit(){ - - var o = db.UserContract.manager.select( $user == bob && $product == p, true); - - //no order, stock at 8 - assertEquals(p.stock , 8); - assertEquals(o , null); - - //bob orders 3 strawberries - var o = OrderService.make(bob, 3, p , TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.id); - assertEquals(o.product.name, p.name); - assertEquals(o.quantity, 3); - assertEquals(p.stock , 5); - - //order edit, order 6 berries - App.current.eventDispatcher.addOnce(function(e:Event){ - switch(e){ - case StockMove(e): - assertTrue(e.move==-3); - assertTrue(e.product==p); - default: - } - }); - var o = OrderService.edit(o, 6); - assertTrue(p.stock == 2); - assertTrue(o.quantity == 6); - - //order edit, order 9 berries. ( 3 more, but stock fall to 0, reduced to 2 ) - App.current.eventDispatcher.addOnce(function(e:Event){ - switch(e){ - case StockMove(e): - assertEquals( -2.0 , e.move ); - assertEquals( p , e.product); - default: - } - }); - var o = OrderService.edit(o, 9); - assertEquals(0.0 , p.stock); - assertEquals(8.0 , o.quantity); - - //order more, but stock at 0 - var o = OrderService.edit(o, 12); - assertEquals(0.0 , p.stock); - assertEquals(8.0 , o.quantity); - - //order less - var o = OrderService.edit(o, 6); - assertEquals(2.0 , p.stock); - assertEquals(6.0 , o.quantity); - - - //floatQt : ordering float quantities should throw an exception - var err = null; - try{ - var o = OrderService.edit(o, 6.4); - }catch(e:tink.core.Error){ - err = e.message; - } - assertTrue( err!=null ); - } - - /** - * test orders with multiweight product - */ - function testOrderWithMultiWeightProduct(){ - - var chicken = TestSuite.CHICKEN; - var distrib = db.Distribution.manager.select($contract == chicken.contract, false); - - var order = OrderService.make(bob, 1, chicken, distrib.id); - assertEquals(1.0, order.quantity); - assertEquals(chicken.id, order.product.id); - assertEquals(chicken.price, order.productPrice); - - //order 2 more, should not aggregate because multiWeight is true - var order2 = OrderService.make(bob, 2, chicken, distrib.id); - - assertTrue(order2.id != order.id); - - //we should get 3 different orders - var orders = distrib.getOrders(); - - //trace(OrderService.prepare(orders)); - - assertEquals(3, orders.length); - for ( o in orders){ - assertEquals(o.user.id, bob.id); - assertEquals(o.product.id, chicken.id); - assertEquals(1.0, o.quantity); - } - - } - - /** - * @author fbarbut - * @date 2018-01-26 - * order a product, edit and set qt to zero, order again. - * the same record should be re-used ( if not multiweight ) - */ - function testMakeOrderAndZeroQuantity(){ - var fraises = TestSuite.STRAWBERRIES; - var distrib = db.Distribution.manager.select($contract == fraises.contract, false); - - var order = OrderService.make(bob, 1, fraises, distrib.id); - - order = OrderService.edit(order, 0); - - assertEquals(0.0, order.quantity); - - var order2 = OrderService.make(bob, 1, fraises, distrib.id); - - var bobOrders = []; - for ( o in distrib.getOrders()) if (o.user.id == bob.id) bobOrders.push(o); - - assertFalse(fraises.multiWeight); - assertEquals(1, bobOrders.length); - assertEquals(1.0, bobOrders[0].quantity); - } - - /** - * Test order deletion and operation deletion in various contexts - @author jbarbic - */ - function testDelete(){ - - var t = sugoi.i18n.Locale.texts; - - //[Test case] Should throw an error when trying to delete order and that the quantity is not zero - var amapDistrib = TestSuite.DISTRIB_CONTRAT_AMAP; - var amapContract = amapDistrib.contract; - var order = OrderService.make(TestSuite.FRANCOIS, 1, TestSuite.PANIER_AMAP_LEGUMES, amapDistrib.id); - var orderId = order.id; - db.Operation.onOrderConfirm([order]); - var e1 = null; - try { - service.OrderService.delete(order); - } - catch(x:tink.core.Error){ - e1 = x; - } - assertEquals(e1.message, "Deletion not possible: quantity is not zero."); - assertTrue(db.UserContract.manager.get(orderId) != null); - - //[Test case] Amap contract and quantity zero with payments disabled - //Check that order is deleted - order = OrderService.edit(order, 0); - var e2 = null; - try { - OrderService.delete(order); - } - catch(x:tink.core.Error){ - e2 = x; - } - assertEquals(e2, null); - assertEquals(db.UserContract.manager.get(orderId), null); - - //[Test case] Amap contract and quantity zero with payments enabled and 2 orders - //Check that first order is deleted but operation amount is at 0 - //Check that operation is deleted only at the second order deletion - var order1 = OrderService.make(TestSuite.FRANCOIS, 1, TestSuite.PANIER_AMAP_LEGUMES, amapDistrib.id); - db.Operation.onOrderConfirm([order1]); - var order1Id = order1.id; - order1 = OrderService.edit(order1, 0); - db.Operation.onOrderConfirm([order1]); - var order2 = OrderService.make(TestSuite.FRANCOIS, 1, TestSuite.PANIER_AMAP_LEGUMES, amapDistrib.id); - db.Operation.onOrderConfirm([order2]); - var order2Id = order2.id; - order2 = OrderService.edit(order2, 0); - db.Operation.onOrderConfirm([order2]); - var operation = db.Operation.findCOrderTransactionFor(amapContract, TestSuite.FRANCOIS); - var operationId = operation.id; - var e3 = null; - try { - service.OrderService.delete(order1); - } - catch(x:tink.core.Error){ - e3 = x; - } - assertEquals(e3, null); - assertEquals(db.UserContract.manager.get(order1Id), null); - assertTrue(db.Operation.manager.get(operationId) != null); - assertEquals(operation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 1 deliveries"); - assertEquals(operation.amount, 0); - var e4 = null; - try { - service.OrderService.delete(order2); - } - catch(x:tink.core.Error){ - e4 = x; - } - assertEquals(null, e4); - assertEquals(null, db.UserContract.manager.get(order2Id)); - assertEquals(null, db.Operation.manager.get(operationId)); - - //[Test case] Var Order contract and quantity zero with payments disabled - //Check that order is deleted - var variableDistrib = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE; - - var g = variableDistrib.contract.amap; - g.lock(); - g.flags.unset(HasPayments); - g.update(); - - var order = OrderService.make(TestSuite.FRANCOIS, 2, TestSuite.STRAWBERRIES, variableDistrib.id); - var orderId = order.id; - db.Operation.onOrderConfirm([order]); - order = OrderService.edit(order, 0); - db.Operation.onOrderConfirm([order]); - var e1 = null; - try { - service.OrderService.delete(order); - } - catch(x:tink.core.Error){ - e1 = x; - } - assertEquals(false,variableDistrib.contract.amap.hasPayments() ); - assertEquals(null, e1); - assertEquals(null, db.UserContract.manager.get(orderId)); - - //[Test case] Var Order contract and quantity zero with payments enabled and 2 orders - //Check that first order is deleted - //Check that operation is deleted only at the second order deletion - variableDistrib = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE; - var variableContract = variableDistrib.contract; - var g = variableDistrib.contract.amap; - g.lock(); - g.flags.set(HasPayments); - g.update(); - assertTrue(variableContract.amap.hasPayments()); - - var order1 = OrderService.make(TestSuite.FRANCOIS, 2, TestSuite.STRAWBERRIES, variableDistrib.id); - db.Operation.onOrderConfirm([order1]); - var order1Id = order1.id; - - var order2 = OrderService.make(TestSuite.FRANCOIS, 3, TestSuite.APPLES, variableDistrib.id); - db.Operation.onOrderConfirm([order2]); - var order2Id = order2.id; - - order1 = OrderService.edit(order1, 0); - db.Operation.onOrderConfirm([order1]); - - order2 = OrderService.edit(order2, 0); - db.Operation.onOrderConfirm([order2]); - - assertEquals(2, variableContract.getUserOrders(TestSuite.FRANCOIS,variableDistrib).length); //François has 2 orders - var basket = db.Basket.get(TestSuite.FRANCOIS,variableDistrib.place,variableDistrib.date); - assertEquals(2, basket.getOrders().length); - - var operation1 = db.Operation.findVOrderTransactionFor(order1.distribution.getKey(), TestSuite.FRANCOIS, variableContract.amap); - var operation1Id = operation1.id; - var operation2 = db.Operation.findVOrderTransactionFor(order2.distribution.getKey(), TestSuite.FRANCOIS, variableContract.amap); - var operation2Id = operation2.id; - assertEquals(operation1Id,operation2Id); - var e2 = null; - try { - //delete strawberries order - service.OrderService.delete(order1); - } - catch(x:tink.core.Error){ - e2 = x; - } - assertEquals(null, e2); - assertEquals(null, db.UserContract.manager.get(order1Id) ); //order 1 is deleted - assertTrue( db.Operation.manager.get(operation1Id) != null); //operation should be here - assertEquals(0.0,operation1.amount); - assertEquals(1 , basket.getOrders().length); - var e3 = null; - try { - //delete apple order - service.OrderService.delete(order2); - } - catch(x:tink.core.Error){ - e3 = x; - } - assertEquals(null, e3); - assertEquals(null, db.UserContract.manager.get(order2Id)); //order 2 is deleted - assertEquals(null, db.Operation.manager.get(operation1Id)); //operation should be deleted - assertEquals(0 , basket.getOrders().length); - - //[Test case] 2 VarOrderContracts and quantity zero with payments enabled and 1 order each - //Check that first order is deleted but operation amount is at 0 - //Check that operation is deleted only at the second order deletion - var variableDistrib1 = TestSuite.DISTRIB_LEGUMES_RUE_SAUCISSE; - var order1 = OrderService.make(TestSuite.FRANCOIS, 2, TestSuite.COURGETTES, variableDistrib1.id); - assertTrue(order1.basket!=null); - // trace("WE GOT A BASKET "+order1.basket.id); - // trace("... THEN RE-GET BASKET user "+TestSuite.FRANCOIS.id+" place "+variableDistrib1.place.id+" date "+variableDistrib1.date); - var basket = db.Basket.get(TestSuite.FRANCOIS,variableDistrib1.place,variableDistrib1.date); - assertTrue(basket!=null); - assertEquals(1, basket.getOrders().length); - db.Operation.onOrderConfirm([order1]); - var order1Id = order1.id; - - var variableDistrib2 = TestSuite.DISTRIB_PATISSERIES; - var order2 = OrderService.make(TestSuite.FRANCOIS, 3, TestSuite.FLAN, variableDistrib2.id); - db.Operation.onOrderConfirm([order2]); - var order2Id = order2.id; - - order1 = OrderService.edit(order1, 0); - db.Operation.onOrderConfirm([order1]); - - order2 = OrderService.edit(order2, 0); - db.Operation.onOrderConfirm([order2]); - - //check basket - var basket = db.Basket.get(TestSuite.FRANCOIS,variableDistrib1.place,variableDistrib1.date); - assertEquals(2, basket.getOrders().length); - - var operation = db.Operation.findVOrderTransactionFor(order1.distribution.getKey(), TestSuite.FRANCOIS, variableDistrib1.contract.amap); - var operationId = operation.id; - - - var e4 = null; - try { - service.OrderService.delete(order1); - } - catch(x:tink.core.Error){ - e4 = x; - } - assertEquals(e4, null); - assertEquals(db.UserContract.manager.get(order1Id), null); - assertTrue(db.Operation.manager.get(operationId) != null); //op should still be here - assertEquals(0.0,operation.amount);//...with amount 0 - - var e5 = null; - try { - service.OrderService.delete(order2); - } - catch(x:tink.core.Error){ - e5 = x; - } - assertEquals(e5, null); - assertEquals(db.UserContract.manager.get(order2Id), null); - assertEquals(null, db.Operation.manager.get(operationId), null); //op should have been deleted - } -} \ No newline at end of file diff --git a/src/test/TestPayments.hx b/src/test/TestPayments.hx deleted file mode 100644 index d5ee953..0000000 --- a/src/test/TestPayments.hx +++ /dev/null @@ -1,64 +0,0 @@ -package test; - -/** - * Test payments - * - * @author web-wizard - */ -class TestPayments extends haxe.unit.TestCase -{ - - public function new(){ - super(); - } - - override function setup(){ - TestSuite.initDB(); - TestSuite.initDatas(); - db.Basket.emptyCache(); - } - - function testValidateDistribution() { - - //Take a contract with payments enabled - //Take 2 users and make orders for each - var distrib = TestSuite.DISTRIB_LEGUMES_RUE_SAUCISSE; - var contract = distrib.contract; - var product = TestSuite.COURGETTES; - var francoisOrder = service.OrderService.make(TestSuite.FRANCOIS, 1, product, distrib.id); - var francoisOrderOperation = db.Operation.onOrderConfirm([francoisOrder]); - var sebOrder = service.OrderService.make(TestSuite.SEB, 3, product, distrib.id); - var sebOrderOperation = db.Operation.onOrderConfirm([sebOrder]); - //They both pay by check - var francoisPayment = db.Operation.makePaymentOperation(TestSuite.FRANCOIS,contract.amap, payment.Check.TYPE, product.price, "Payment by check", francoisOrderOperation[0]); - var sebPayment = db.Operation.makePaymentOperation(TestSuite.SEB,contract.amap, payment.Check.TYPE, 3 * product.price, "Payment by check", sebOrderOperation[0] ); - - //Autovalidate this old distrib and check that all the payments are validated - service.PaymentService.validateDistribution(distrib); - - //distrib should be validated - assertTrue(contract.amap.hasPayments()); - assertEquals(true, distrib.validated); - - //orders should be marked as paid - assertEquals(true, francoisOrder.paid); - assertEquals(true, sebOrder.paid); - - //order operation is not pending - var francoisOperation = db.Operation.findVOrderTransactionFor(francoisOrder.distribution.getKey(), TestSuite.FRANCOIS, contract.amap, false); - var sebOperation = db.Operation.findVOrderTransactionFor(sebOrder.distribution.getKey(), TestSuite.SEB, contract.amap, false); - assertEquals(francoisOperation.pending, false); - assertEquals(sebOperation.pending, false); - - //payment operation is not pending - assertEquals(francoisPayment.pending, false); - assertEquals(sebPayment.pending, false); - - //basket are validated - var b = db.Basket.get(TestSuite.SEB,distrib.place,distrib.date); - assertEquals(true, b.isValidated()); - var b = db.Basket.get(TestSuite.FRANCOIS,distrib.place,distrib.date); - assertEquals(true, b.isValidated()); - } - -} \ No newline at end of file diff --git a/src/test/TestReports.hx b/src/test/TestReports.hx deleted file mode 100644 index c1b6fdb..0000000 --- a/src/test/TestReports.hx +++ /dev/null @@ -1,171 +0,0 @@ -package test; -import Common; -import test.TestSuite; -import service.ReportService; -import service.OrderService; - -/** - * Test order reports - * - * @author fbarbut - */ -class TestReports extends haxe.unit.TestCase -{ - - public function new(){ - - super(); - } - - override function setup(){ - - TestSuite.initDB(); - TestSuite.initDatas(); - - } - - - function testOrdersByProduct(){ - - //record orders - var seb = TestSuite.SEB; - var francois = TestSuite.FRANCOIS; - var julie = TestSuite.JULIE; - - //distrib de légumes - var d = TestSuite.DISTRIB_LEGUMES_RUE_SAUCISSE; - var carrots = TestSuite.CARROTS; - var courgettes = TestSuite.COURGETTES; - var poulet = TestSuite.CHICKEN; - - OrderService.make(seb,4,courgettes,d.id); - OrderService.make(seb,1,poulet,d.id); - - OrderService.make(francois,6,courgettes,d.id); - OrderService.make(francois,2,poulet,d.id); - OrderService.make(francois,3,carrots,d.id); - - OrderService.make(julie,8,carrots,d.id); - OrderService.make(julie,3,poulet,d.id); - - //record orders on ANOTHER distrib - var d2 = service.DistributionService.create( - d.contract, - new Date(2018,2,12,0,0,0), - new Date(2018,2,12,0,3,0), - d.contract.amap.getPlaces().first().id, - null,null,null,null, - new Date(2018,2,8,0,0,0), - new Date(2018,2,11,0,0,0) - ); - OrderService.make(julie,6,carrots,d2.id); - OrderService.make(julie,1,poulet,d2.id); - - var orders = ReportService.getOrdersByProduct(d); - - //courgettes x 10 - var courgettesOrder = Lambda.find(orders, function(o) return o.pid==courgettes.id); - assertEquals( 10.0 , courgettesOrder.quantity ); - assertEquals( 35.0 , courgettesOrder.totalTTC ); - assertEquals( 33.18 , tools.FloatTool.clean(courgettesOrder.totalHT) ); - - //the report stays the same, even if the product has a new price. - courgettes.lock(); - courgettes.price+=4; - courgettes.update(); - var orders = ReportService.getOrdersByProduct(d); - var courgettesOrder = Lambda.find(orders, function(o) return o.pid==courgettes.id); - assertEquals( 10.0 , courgettesOrder.quantity ); - assertEquals( 35.0 , courgettesOrder.totalTTC ); - assertEquals( 33.18 , tools.FloatTool.clean(courgettesOrder.totalHT) ); - - - } - - /** - * run once at the beginning - */ - /*override function setup(){ - - sys.db.Manager.cnx.request("TRUNCATE TABLE UserContract;"); - - var bubar = db.User.manager.get(1); - var seb = db.User.manager.get(2); - - //fruits from group 1 - var fraises = db.Product.manager.get(2); - fraises.stock = 30; - var pommes = db.Product.manager.get(3); - var distrib = fraises.contract.getDistribs().first(); - - db.UserContract.make(bubar, 4, fraises, distrib.id); - db.UserContract.make(seb, 2, pommes, distrib.id); - - //vegetables from group 2 - var courgettes = db.Product.manager.get(4); - var carottes = db.Product.manager.get(5); - var distrib = courgettes.contract.getDistribs().first(); - - db.UserContract.make(bubar, 1, carottes ,distrib.id); - db.UserContract.make(seb, 5, courgettes ,distrib.id); - }*/ - - - /** - * test a simple report with just a time frame - */ - /*public function testTimeFrameReport(){ - - var fraises = db.Product.manager.get(2); - var pommes = db.Product.manager.get(3); - var courgettes = db.Product.manager.get(4); - var carottes = db.Product.manager.get(5); - - //check we got the right products - assertEquals("Fraises",fraises.name); - assertEquals("Pommes",pommes.name); - assertEquals("Courgettes",courgettes.name); - assertEquals("Carottes", carottes.name); - - var options = { startDate:new Date(2017, 5, 1, 0, 0, 0), endDate:new Date(2017, 5, 31, 0, 0, 0), groups:[], contracts:[] }; - - var rep = new pro.OrderReport(options); - - var data = rep.byProduct(); - - assertEquals(4,data.length); //should be the 4 products - - for ( d in data){ - switch(d.pname){ - case "Fraises": assertEquals(d.qt, 4); - case "Pommes": assertEquals(d.qt, 2); - case "Carottes": assertEquals(d.qt, 1); - case "Courgettes": assertEquals(d.qt, 5); - } - } - - }*/ - - - /** - * test a report with time frame + group - */ - /*public function testGroupReport(){ - - var options = { startDate:new Date(2017, 5, 1, 0, 0, 0), endDate:new Date(2017, 5, 31, 0, 0, 0), groups:[1], contracts:[] }; - - var rep = new pro.OrderReport(options); - var data = rep.byProduct(); - assertEquals(2,data.length); //should be the 2 products - - for ( d in data){ - switch(d.pname){ - case "Fraises": assertEquals(d.qt, 4); - case "Pommes": assertEquals(d.qt, 2); - } - } - }*/ - - - -} \ No newline at end of file diff --git a/src/test/TestSuite.hx b/src/test/TestSuite.hx deleted file mode 100644 index 6acf049..0000000 --- a/src/test/TestSuite.hx +++ /dev/null @@ -1,413 +0,0 @@ -package test; -import Common; -/** - * CAGETTE.NET TEST SUITE - * @author fbarbut - */ -class TestSuite -{ - - static function main() { - - connectDb(); - var r = new haxe.unit.TestRunner(); - - //Cagette core tests - r.add(new test.TestUser()); - r.add(new test.TestOrders()); - r.add(new test.TestTools()); - r.add(new test.TestDistributions()); - r.add(new test.TestPayments()); - r.add(new test.TestReports()); - - #if plugins - //Cagette-pro tests, keep in this order - r.add(new pro.test.TestProductService()); - r.add(new pro.test.TestRemoteCatalog()); - r.add(new pro.test.TestDistribService()); - r.add(new pro.test.TestReports()); - //wholesale-order tests - r.add(new who.test.TestWho()); - #end - - r.run(); - } - - static function connectDb() { - var dbstr = Sys.args()[0]; - var dbreg = ~/([^:]+):\/\/([^:]+):([^@]*?)@([^:]+)(:[0-9]+)?\/(.*?)$/; - if( !dbreg.match(dbstr) ) - throw "Configuration requires a valid database attribute, format is : mysql://user:password@host:port/dbname"; - var port = dbreg.matched(5); - var dbparams = { - user:dbreg.matched(2), - pass:dbreg.matched(3), - host:dbreg.matched(4), - port:port == null ? 3306 : Std.parseInt(port.substr(1)), - database:dbreg.matched(6), - socket:null - }; - - sys.db.Manager.cnx = sys.db.Mysql.connect(dbparams); - sys.db.Manager.initialize(); - } - - - public static function initDB(){ - //NUKE EVERYTHING BWAAAAH !! - sys.db.Manager.cleanup(); //cleanup cache objects - sql("DROP DATABASE tests;"); - sql("CREATE DATABASE tests;"); - sql("USE tests;"); - - var tables : Array = [ - - //cagette - db.TxpProduct.manager, - db.TxpCategory.manager, - db.TxpSubCategory.manager, - db.Category.manager, - db.CategoryGroup.manager, - db.ProductCategory.manager, - - db.Basket.manager, - db.UserContract.manager, - db.UserAmap.manager, - db.Operation.manager, - - db.User.manager, - db.Amap.manager, - db.Contract.manager, - db.Product.manager, - db.Vendor.manager, - db.Place.manager, - db.Distribution.manager, - db.DistributionCycle.manager, - - //sugoi tables - sugoi.db.Cache.manager, - sugoi.db.Error.manager, - sugoi.db.File.manager, - sugoi.db.Session.manager, - sugoi.db.Variable.manager, - ]; - - for(t in tables) createTable(t); - - #if plugins - //add Cpro datas : we need those tables even in cagette core tests - pro.test.ProTestSuite.initDB(); - pro.test.ProTestSuite.initDatas(); - #end - } - - public static function createTable( m ){ - if ( sys.db.TableCreate.exists(m) ){ - drop(m); - } - // Sys.println("Creating table "+ m.dbInfos().name); - sys.db.TableCreate.create(m); - } - - public static function truncate(m){ - sql("TRUNCATE TABLE "+m.dbInfos().name+";"); - } - - public static function drop(m){ - sql("DROP TABLE "+m.dbInfos().name+";"); - } - - public static function sql(sql){ - return sys.db.Manager.cnx.request(sql); - } - - //shortcut to datas - public static var FRANCOIS:db.User = null; - public static var SEB:db.User = null; - public static var JULIE:db.User = null; - - public static var CHICKEN:db.Product = null; - public static var STRAWBERRIES:db.Product = null; - public static var APPLES:db.Product = null; - public static var AMAP_DU_JARDIN:db.Amap = null; - public static var LOCAVORES:db.Amap = null; - public static var PANIER_AMAP_LEGUMES:db.Product = null; - public static var DISTRIB_CONTRAT_AMAP:db.Distribution = null; - public static var DISTRIB_FRUITS_PLACE_DU_VILLAGE:db.Distribution = null; - public static var DISTRIB_LEGUMES_RUE_SAUCISSE:db.Distribution = null; - public static var CONTRAT_LEGUMES:db.Contract = null; - public static var PLACE_DU_VILLAGE:db.Place = null; - public static var COURGETTES:db.Product = null; - public static var CARROTS:db.Product = null; - public static var FLAN:db.Product = null; - public static var CROISSANT:db.Product = null; - public static var DISTRIB_PATISSERIES:db.Distribution = null; - - public static function initDatas(){ - - //USERS - - var f = new db.User(); - f.firstName = "François"; - f.lastName = "B"; - f.email = "francois@alilo.fr"; - f.insert(); - - FRANCOIS = f; - - var u = new db.User(); - u.firstName = "Seb"; - u.lastName = "Z"; - u.email = "sebastien@alilo.fr"; - u.insert(); - - SEB = u; - - var u = new db.User(); - u.firstName = "Julie"; - u.lastName = "B"; - u.email = "julie@alilo.fr"; - u.insert(); - - JULIE = u; - - initApp(u); - - //GROUP "AMAP du Jardin public" - var a = new db.Amap(); - a.name = "AMAP du Jardin public"; - a.contact = f; - a.flags.set(db.Amap.AmapFlags.HasPayments); - a.insert(); - AMAP_DU_JARDIN = a; - - var place = new db.Place(); - place.name = "Place du village"; - place.zipCode = "00000"; - place.city = "St Martin"; - place.amap = a; - place.insert(); - - PLACE_DU_VILLAGE = place; - - //VENDOR "Ferme de la galinette" - var v = new db.Vendor(); - v.name = "La ferme de la Galinette"; - v.email = "galinette@gmail.com"; - v.zipCode = "00000"; - v.city = "Bourligheim"; - v.insert(); - - var c = new db.Contract(); - c.name = "Contrat AMAP Légumes"; - c.startDate = new Date(2017, 1, 1, 0, 0, 0); - c.endDate = new Date(2030, 12, 31, 23, 59, 0); - c.vendor = v; - c.amap = a; - c.type = db.Contract.TYPE_CONSTORDERS; - c.insert(); - - var p = new db.Product(); - p.name = "Panier Légumes"; - p.price = 13; - p.contract = c; - p.insert(); - - PANIER_AMAP_LEGUMES = p; - - var d = new db.Distribution(); - d.date = new Date(2017, 5, 1, 19, 0, 0); - d.end = new Date(2017, 5, 1, 20, 0, 0); - d.orderStartDate = new Date(2017, 4, 1, 20, 0, 0); - d.orderEndDate = new Date(2017, 4, 30, 20, 0, 0); - d.contract = c; - d.place = place; - d.insert(); - - DISTRIB_CONTRAT_AMAP = d; - - //varying contract for strawberries with stock mgmt - var c = new db.Contract(); - c.name = "Commande fruits"; - c.vendor = v; - c.startDate = new Date(2017, 1, 1, 0, 0, 0); - c.endDate = new Date(2030, 12, 31, 23, 59, 0); - c.flags.set(db.Contract.ContractFlags.StockManagement); - c.type = db.Contract.TYPE_VARORDER; - c.amap = a; - c.insert(); - - var p = new db.Product(); - p.name = "Fraises"; - p.qt = 1; - p.unitType = Common.Unit.Kilogram; - p.price = 10; - p.organic = true; - p.contract = c; - p.stock = 8; - p.insert(); - - STRAWBERRIES = p; - - var p = new db.Product(); - p.name = "Pommes"; - p.qt = 1; - p.unitType = Common.Unit.Kilogram; - p.price = 6; - p.organic = true; - p.contract = c; - p.stock = 12; - p.insert(); - - APPLES = p; - - var d = new db.Distribution(); - d.date = new Date(2017, 5, 1, 19, 0, 0); - d.end = new Date(2017, 5, 1, 20, 0, 0); - d.orderStartDate = new Date(2017, 4, 1, 20, 0, 0); - d.orderEndDate = new Date(2017, 4, 30, 20, 0, 0); - d.contract = c; - d.place = place; - d.insert(); - - DISTRIB_FRUITS_PLACE_DU_VILLAGE = d; - - //second group - var a = new db.Amap(); - a.name = "Les Locavores de la Rue Saucisse"; - a.contact = f; - a.flags.set(db.Amap.AmapFlags.HasPayments); - a.insert(); - LOCAVORES = a; - - var place = new db.Place(); - place.name = "Rue Saucisse"; - place.zipCode = "00000"; - place.city = "St Martin"; - place.amap = a; - place.insert(); - - var v = new db.Vendor(); - v.name = "La ferme de la courgette enragée"; - v.email = "courgette@gmail.com"; - v.zipCode = "00000"; - v.city = "Bourligeac"; - v.insert(); - - var c = new db.Contract(); - c.name = "Commande Legumes"; - c.startDate = new Date(2017, 1, 1, 0, 0, 0); - c.endDate = new Date(2030, 12, 31, 23, 59, 0); - c.vendor = v; - c.amap = a; - c.type = db.Contract.TYPE_VARORDER; - c.insert(); - - CONTRAT_LEGUMES = c; - - var p = new db.Product(); - p.name = "Courgettes"; - p.qt = 1; - p.unitType = Common.Unit.Kilogram; - p.price = 3.5; - p.vat = 5.5; - p.organic = true; - p.contract = c; - p.insert(); - - COURGETTES = p; - - var p = new db.Product(); - p.name = "Carottes"; - p.qt = 1; - p.unitType = Common.Unit.Kilogram; - p.price = 2.8; - p.vat = 5.5; - p.contract = c; - p.insert(); - - CARROTS = p; - - var p = new db.Product(); - p.name = "Poulet"; - p.qt = 1.5; - p.unitType = Common.Unit.Kilogram; - p.price = 15; - p.vat = 5.5; - p.multiWeight = true; - p.hasFloatQt = true; - p.contract = c; - p.insert(); - - CHICKEN = p; - - var d = service.DistributionService.create(c,new Date(2017, 5, 1, 19, 0, 0),new Date(2017, 5, 1, 19, 2, 0),place.id,null,null,null,null,new Date(2017, 4, 10, 19, 0, 0),new Date(2017, 4, 20, 19, 0, 0)); - DISTRIB_LEGUMES_RUE_SAUCISSE = d; - - //PASTRY - - var c = new db.Contract(); - c.name = "Commande Pâtisseries"; - c.startDate = new Date(2017, 1, 1, 0, 0, 0); - c.endDate = new Date(2017, 12, 31, 23, 59, 0); - c.vendor = v; - c.amap = a; - c.type = db.Contract.TYPE_VARORDER; - c.insert(); - - var p = new db.Product(); - p.name = "Flan"; - p.qt = 1; - p.unitType = Common.Unit.Kilogram; - p.price = 3.5; - p.organic = true; - p.contract = c; - p.insert(); - - FLAN = p; - - var p = new db.Product(); - p.name = "Croissant"; - p.qt = 1; - p.unitType = Common.Unit.Kilogram; - p.price = 2.8; - p.contract = c; - p.insert(); - - CROISSANT = p; - - var d = new db.Distribution(); - d.date = new Date(2017, 5, 1, 19, 0, 0); - d.contract = c; - d.place = place; - d.insert(); - - DISTRIB_PATISSERIES = d; - } - - static function initApp(u:db.User){ - - //setup App - var app = App.current = new App(); - App.config.DEBUG = true; - app.initLang("en"); - - app.eventDispatcher = new hxevents.Dispatcher(); - app.plugins = []; - //internal plugins - app.plugins.push(new plugin.Tutorial()); - - //optionnal plugins - #if plugins - //app.plugins.push( new hosted.HostedPlugIn() ); - app.plugins.push( new pro.ProPlugIn() ); - app.plugins.push( new connector.ConnectorPlugIn() ); - //app.plugins.push( new pro.LemonwayEC() ); - app.plugins.push( new who.WhoPlugIn() ); - #end - - App.current.user = u; - App.current.view = new View(); - } -} - diff --git a/src/test/TestTools.hx b/src/test/TestTools.hx deleted file mode 100644 index 4e27d33..0000000 --- a/src/test/TestTools.hx +++ /dev/null @@ -1,92 +0,0 @@ -package test; -import Common; - -/** - * Test various tools - * - * @author fbarbut - */ -class TestTools extends haxe.unit.TestCase -{ - - public function new(){ - super(); - } - - - function testDateRanges(){ - // test last hour range - var now = Date.fromString("2018-01-01 00:30:12"); - var r = tools.DateTool.getLastHourRange(now); - assertEquals("2017-12-31 23:00:00",r.from.toString()); - assertEquals("2018-01-01 00:00:00",r.to.toString()); - - // test last minute - var now = Date.fromString("2018-01-01 00:30:12"); - var r = tools.DateTool.getLastMinuteRange(now); - assertEquals("2018-01-01 00:29:00",r.from.toString()); - assertEquals("2018-01-01 00:30:00",r.to.toString()); - } - - - function testFloatTool(){ - - assertEquals( true , tools.FloatTool.isEqual(10.0,10.000) ); - assertEquals( true , tools.FloatTool.isEqual(10.0,10) ); - assertEquals( true , tools.FloatTool.isEqual(10,10) ); - assertEquals( true , tools.FloatTool.isEqual(10.00000001,10) ); - assertEquals( false , tools.FloatTool.isEqual(10.02,10) ); - - assertEquals( false , tools.FloatTool.isInt(10.08) ); - assertEquals( true , tools.FloatTool.isInt(10.00) ); - - - } - -/* - @admin - public function doTests() { - - var assertTrue = function(val, ?desc="") { - if (val) { - Sys.println("OK :
"); - }else { - Sys.println("ERROR : "+desc+"
"); - } - } - - - //test les fonctions de cotisation - - var amap = db.Amap.manager.get(1); - - amap.membershipRenewalDate = new Date(2015, 0, 1,0,0,0); - amap.update(); - - assertTrue(amap.getMembershipYear(new Date(2015, 3, 3, 0, 0, 0) ) == 2015); - assertTrue(amap.getPeriodName(new Date(2015, 3, 3, 0, 0, 0)) == "2015"); - - assertTrue(amap.getMembershipYear(new Date(2014, 8, 8, 0, 0, 0) ) == 2014); - assertTrue(amap.getPeriodName(new Date(2014, 8, 8, 0, 0, 0) ) == "2014"); - - assertTrue(amap.getMembershipYear(new Date(2013, 11, 12, 0, 0, 0) ) == 2013); - assertTrue(amap.getPeriodName(new Date(2013, 11, 12, 0, 0, 0) ) == "2013"); - - amap.membershipRenewalDate = new Date(2015, 8, 1,0,0,0); - amap.update(); - - assertTrue(amap.getMembershipYear(new Date(2015, 3, 3, 0, 0, 0) ) == 2014); - assertTrue(amap.getPeriodName(new Date(2015, 3, 3, 0, 0, 0)) == "2014-2015"); - - var d = amap.getMembershipYear(new Date(2015, 8, 8, 0, 0, 0) ); - assertTrue( d == 2015, "le 8 sept 2015, on doit etre en cotis 2015, la c " + d); - assertTrue(amap.getPeriodName(new Date(2015, 8, 8, 0, 0, 0)) == "2015-2016"); - - var d = new Date(2013, 11, 12, 0, 0, 0) ; - assertTrue( amap.getMembershipYear(d) == 2013, "le 12 oct 2013, on doit etre en cotis 2013 , là c " + amap.getMembershipYear(d) ); - assertTrue(amap.getPeriodName(d) == "2013-2014", "le 12 oct 2013, on doit etre en 2013-2014 , là c " + amap.getPeriodName(d) ); - - - }*/ - -} \ No newline at end of file diff --git a/src/test/TestUser.hx b/src/test/TestUser.hx deleted file mode 100644 index b4ffb3c..0000000 --- a/src/test/TestUser.hx +++ /dev/null @@ -1,48 +0,0 @@ - - -package test; -import db.UserAmap; -import Common; - -/** - * Test user rights to view contracts - * - * @author web-wizard - */ -class TestUser extends haxe.unit.TestCase -{ - - public function new(){ - super(); - } - - var contract : db.Contract; - var user : db.User; - var group1 : db.Amap; - var group2 : db.Amap; - var userAmap : db.UserAmap; - - /** - * get a contract + a user - */ - override function setup(){ - TestSuite.initDB(); - TestSuite.initDatas(); - - contract = db.Contract.manager.get(3); - user = db.User.manager.get(1); - group1 = db.Amap.manager.get(1); - group2 = db.Amap.manager.get(2); - } - - /** - * Check that a user who has admin rights for his/her group can't view a contract from a group - he/she doesn't belong to - */ - function testViewContract(){ - userAmap = db.UserAmap.getOrCreate(user, group1); - userAmap.giveRight(Right.GroupAdmin); - assertFalse(user.canManageContract(contract)); - } - -} \ No newline at end of file diff --git a/tests.hxml b/tests.hxml deleted file mode 100644 index 1194f2e..0000000 --- a/tests.hxml +++ /dev/null @@ -1,17 +0,0 @@ --lib dbadmin --lib templo --lib sugoi --lib hxevents --lib thx.semver --lib thx.csv --lib datetime --lib hscript --lib smtpmailer --lib record-macros --lib tink_json --cp common --cp src --cp lang/master/tpl --neko www/tests.n - -main test.TestSuite - diff --git a/testsJS.hxml b/testsJS.hxml deleted file mode 100644 index 012f003..0000000 --- a/testsJS.hxml +++ /dev/null @@ -1,9 +0,0 @@ -# JS --js js/test/tests.js --main test.TestAll --cp js --cp common --lib utest --lib hxnodejs --lib sugoi:git:https://github.com/bablukid/sugoi#i18n --D test diff --git a/testsPlugins.hxml b/testsPlugins.hxml deleted file mode 100644 index 7a203a9..0000000 --- a/testsPlugins.hxml +++ /dev/null @@ -1,21 +0,0 @@ --lib dbadmin --lib templo --lib sugoi --lib hxevents --lib thx.semver --lib thx.csv --lib datetime --lib hscript --lib smtpmailer --lib record-macros --lib cagette-pro --lib cagette-hosted --lib cagette-wholesale-order --lib tink_json --cp common --cp src --cp lang/master/tpl --neko www/tests.n --D plugins --main test.TestSuite -