From 00344a462e6790aac87d83330d5ac54c5c17fbff Mon Sep 17 00:00:00 2001 From: Gerald Baulig Date: Mon, 21 Oct 2024 15:43:25 +0200 Subject: [PATCH] fix(test): add root_tech_user to test --- src/service.ts | 58 ++++++++++++++++++++++++--------------- test/mocks.ts | 39 ++++++++++++++++++++++++++ test/ordering-srv.spec.ts | 1 + 3 files changed, 76 insertions(+), 22 deletions(-) diff --git a/src/service.ts b/src/service.ts index aaa95cf..23d876e 100644 --- a/src/service.ts +++ b/src/service.ts @@ -474,7 +474,7 @@ export class OrderingService this.contact_point_type_ids = { ...this.contact_point_type_ids, ...cfg.get('contactPointTypeIds') - } + }; this.product_service = createClient( { @@ -1635,7 +1635,7 @@ export class OrderingService this.topic.emit(this.emitters['INVALID'], item); } else if (item?.payload?.order_state! in this.emitters) { - this.topic.emit(this.emitters[item.payload?.order_state!], item); + this.topic.emit(this.emitters[item.payload?.order_state!], item.payload); } } ); @@ -1851,7 +1851,7 @@ export class OrderingService ).map( item => { item.payload!.order_state = OrderState.PENDING; - return item + return item; } ), operation_status: response.operation_status @@ -1895,7 +1895,7 @@ export class OrderingService response.operation_status = r.operation_status; return r.items; } - ) + ); } if (this.creates_invoices_on_submit) { @@ -1993,10 +1993,10 @@ export class OrderingService const submits = Object.values(response_map).filter( order => order.status?.code === 200 ).map( - order => ({ - ...order.payload, - order_state: OrderState.SUBMITTED, - }) + order => { + order.payload.order_state = OrderState.SUBMITTED; + return order.payload; + } ); await super.upsert( @@ -2028,7 +2028,7 @@ export class OrderingService this.topic.emit(this.emitters['INVALID'], item); } else if (item.payload?.order_state! in this.emitters) { - this.topic.emit(this.emitters[item.payload.order_state!], item); + this.topic.emit(this.emitters[item.payload.order_state!], item.payload); } } ); @@ -2189,7 +2189,7 @@ export class OrderingService shop_id: order.payload?.shop_id, customer_id: order.payload?.customer_id, }; - return query + return query; } ).filter( query => query.items?.length @@ -2246,6 +2246,12 @@ export class OrderingService orders?: OrderMap, context?: any, ): Promise { + orders ??= await this.getOrderMap( + request.items?.map(item => item.order_id!), + request.subject, + context + ) ?? {}; + const solutions = await this.getPackingSolution( request, context, @@ -2313,6 +2319,12 @@ export class OrderingService context?: any, ): Promise { try { + orders ??= await this.getOrderMap( + request.items?.map(item => item.order_id!), + request.subject, + context + ) ?? {}; + const prototypes = await this.toFulfillmentResponsePrototypes( request, orders, @@ -2323,22 +2335,23 @@ export class OrderingService proto => proto.status?.code !== 200 ); - const valids = await DefaultMetaDataInjector( - this, - { - items: prototypes.filter( - proto => proto.status?.code === 200 - ).map( - proto => proto.payload! - ), - subject: request.subject, + const valids = prototypes.filter( + proto => proto.status?.code === 200 + ).map( + item => { + item.payload.meta ??= {}; + if (!item.payload.meta.owners?.length) { + const order = orders[item.payload.references[0].instance_id]; + item.payload.meta.owners = order.payload?.meta?.owners; + } + return item.payload; } ); const response = await this.fulfillment_service!.create( { - items: valids.items, - total_count: valids.items.length ?? 0, + items: valids, + total_count: valids.length ?? 0, subject: this.fulfillment_tech_user ?? this.ApiKey ?? request.subject, }, context @@ -2378,7 +2391,7 @@ export class OrderingService request: FulfillmentRequestList, context?: any ): Promise { - return this._createFulfillment(request, undefined, context); + return this._createFulfillment(request, undefined, context); } @resolves_subject( @@ -2407,6 +2420,7 @@ export class OrderingService const items = await this.toFulfillmentResponsePrototypes( request, + undefined, context ).then( prototypes => { diff --git a/test/mocks.ts b/test/mocks.ts index fc78573..3d49106 100644 --- a/test/mocks.ts +++ b/test/mocks.ts @@ -98,6 +98,10 @@ const mainMeta = { }; const subjects: { [key: string]: Subject } = { + root_tech_user: { + id: "root_tech_user", + token: "1a4c6789-6435-487a-9308-64d06384acf9" + }, superadmin: { id: 'superadmin', scope: 'main', @@ -577,6 +581,30 @@ const invalidOrders: { [key: string]: OrderList } = { }; const users: { [key: string]: UserResponse } = { + root_tech_user: { + payload: { + id: 'root_tech_user', + role_associations: [ + { + id: 'root_tech_user-1-super-administrator-r-id', + role: 'superadministrator-r-id', + attributes: [], + }, + ], + active: true, + user_type: UserType.TECHNICAL_USER, + tokens: [ + { + token: '1a4c6789-6435-487a-9308-64d06384acf9', + } + ], + }, + status: { + id: 'root_tech_user', + code: 200, + message: 'OK', + } + }, superadmin: { payload: { id: 'superadmin', @@ -657,6 +685,17 @@ const users: { [key: string]: UserResponse } = { }; const hierarchicalScopes: { [key: string]: HierarchicalScope[] } = { + root_tech_user: [ + { + id: 'main', + role: 'superadministrator-r-id', + children: [ + { + id: 'sub', + } + ] + } + ], superadmin: [ { id: 'main', diff --git a/test/ordering-srv.spec.ts b/test/ordering-srv.spec.ts index 7ea080c..c5ca58b 100644 --- a/test/ordering-srv.spec.ts +++ b/test/ordering-srv.spec.ts @@ -264,6 +264,7 @@ describe('The Ordering Service:', () => { const query: FulfillmentRequestList = { items: sample.items?.map(order => ({ orderId: order.id, + selectedItems: [], senderAddress: samples.businessAddresses[0], })), totalCount: sample.items?.length,