From 6d35a4a16018e9eb093a87bc281b5c0db0e43bf1 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 19 Jan 2021 13:57:04 +0100 Subject: [PATCH] 1823 - Added independent order object from card --- modules/order/front/catalog/index.js | 16 ++++++++++------ modules/order/front/catalog/index.spec.js | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/modules/order/front/catalog/index.js b/modules/order/front/catalog/index.js index 318f5dbca..5fdd2e238 100644 --- a/modules/order/front/catalog/index.js +++ b/modules/order/front/catalog/index.js @@ -25,8 +25,15 @@ class Controller extends Section { } $onChanges() { - if (this.order && this.order.isConfirmed) - this.$state.go('order.card.line'); + this.getData().then(() => { + if (this.order && this.order.isConfirmed) + this.$state.go('order.card.line'); + }); + } + + getData() { + return this.$http.get(`Orders/${this.$params.id}`) + .then(res => this.order = res.data); } /** @@ -366,8 +373,5 @@ class Controller extends Section { ngModule.vnComponent('vnOrderCatalog', { template: require('./index.html'), - controller: Controller, - bindings: { - order: '<' - } + controller: Controller }); diff --git a/modules/order/front/catalog/index.spec.js b/modules/order/front/catalog/index.spec.js index 109893ae1..03d7c41ba 100644 --- a/modules/order/front/catalog/index.spec.js +++ b/modules/order/front/catalog/index.spec.js @@ -28,6 +28,22 @@ describe('Order', () => { }; })); + describe('getData()', () => { + it(`should make a query an fetch the order data`, () => { + controller._order = null; + + $httpBackend.expect('GET', `Orders/4`).respond(200, {id: 4, isConfirmed: true}); + $httpBackend.expect('GET', `Orders/4/getItemTypeAvailable?itemCategoryId=1`).respond(); + controller.getData(); + $httpBackend.flush(); + + const order = controller.order; + + expect(order.id).toEqual(4); + expect(order.isConfirmed).toBeTruthy(); + }); + }); + describe('order() setter', () => { it(`should call scope $applyAsync() method and apply filters from state params`, () => { $httpBackend.expect('GET', `Orders/4/getItemTypeAvailable?itemCategoryId=1`).respond();