Skip to content

Commit

Permalink
fix(test): add root_tech_user to test
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Baulig committed Oct 21, 2024
1 parent 9eef5a6 commit 00344a4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 22 deletions.
58 changes: 36 additions & 22 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export class OrderingService
this.contact_point_type_ids = {
...this.contact_point_type_ids,
...cfg.get('contactPointTypeIds')
}
};

this.product_service = createClient(
{
Expand Down Expand Up @@ -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);
}
}
);
Expand Down Expand Up @@ -1851,7 +1851,7 @@ export class OrderingService
).map(
item => {
item.payload!.order_state = OrderState.PENDING;
return item
return item;
}
),
operation_status: response.operation_status
Expand Down Expand Up @@ -1895,7 +1895,7 @@ export class OrderingService
response.operation_status = r.operation_status;
return r.items;
}
)
);
}

if (this.creates_invoices_on_submit) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
}
);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2246,6 +2246,12 @@ export class OrderingService
orders?: OrderMap,
context?: any,
): Promise<FulfillmentResponse[]> {
orders ??= await this.getOrderMap(
request.items?.map(item => item.order_id!),
request.subject,
context
) ?? {};

const solutions = await this.getPackingSolution(
request,
context,
Expand Down Expand Up @@ -2313,6 +2319,12 @@ export class OrderingService
context?: any,
): Promise<FulfillmentListResponse> {
try {
orders ??= await this.getOrderMap(
request.items?.map(item => item.order_id!),
request.subject,
context
) ?? {};

const prototypes = await this.toFulfillmentResponsePrototypes(
request,
orders,
Expand All @@ -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
Expand Down Expand Up @@ -2378,7 +2391,7 @@ export class OrderingService
request: FulfillmentRequestList,
context?: any
): Promise<FulfillmentListResponse> {
return this._createFulfillment(request, undefined, context);
return this._createFulfillment(request, undefined, context);
}

@resolves_subject(
Expand Down Expand Up @@ -2407,6 +2420,7 @@ export class OrderingService

const items = await this.toFulfillmentResponsePrototypes(
request,
undefined,
context
).then(
prototypes => {
Expand Down
39 changes: 39 additions & 0 deletions test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions test/ordering-srv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 00344a4

Please sign in to comment.