Skip to content

Commit

Permalink
feat(driver,customer-order)!: add Magento 2.4.6 support (#2896)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `@daffodil/customer/driver/magento` has been renamed to `@daffodil/customer/driver/magento/2-4-5`
  • Loading branch information
griest024 authored Jul 3, 2024
1 parent 0c1ad29 commit 265d54a
Show file tree
Hide file tree
Showing 123 changed files with 1,631 additions and 42 deletions.
6 changes: 6 additions & 0 deletions libs/customer-order/driver/magento/2-4-5/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "../../../../../node_modules/ng-packagr/ng-entrypoint.schema.json",
"lib": {
"entryFile": "src/index.ts"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS,
} from './order.token';

describe('@daffodil/customer-order/driver/magento | daffProvideCustomerOrderMagentoExtraOrderFragments', () => {
describe('@daffodil/customer-order/driver/magento/2-4-5 | daffProvideCustomerOrderMagentoExtraOrderFragments', () => {
let fragments: DocumentNode[];
let result: DocumentNode[];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { TestBed } from '@angular/core/testing';

import { DaffMagentoCustomerOrderExtraTransform } from '@daffodil/customer-order/driver/magento';
import { DaffMagentoCustomerOrderExtraTransform } from '@daffodil/customer-order/driver/magento/2-4-5';

import {
daffProvideCustomerOrderMagentoExtraOrderTransforms,
DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS,
} from './extra.token';

describe('@daffodil/customer-order/driver/magento | daffProvideCustomerOrderMagentoExtraOrderTransforms', () => {
describe('@daffodil/customer-order/driver/magento/2-4-5 | daffProvideCustomerOrderMagentoExtraOrderTransforms', () => {
let transforms: DaffMagentoCustomerOrderExtraTransform[];
let result: DaffMagentoCustomerOrderExtraTransform[];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import {
DaffMagentoCustomerOrderTransform,
daffProvideCustomerOrderMagentoExtraOrderTransforms,
MagentoCustomerOrder,
} from '@daffodil/customer-order/driver/magento';
import { MagentoCustomerOrderFactory } from '@daffodil/customer-order/driver/magento/testing';
} from '@daffodil/customer-order/driver/magento/2-4-5';
import { MagentoCustomerOrderFactory } from '@daffodil/customer-order/driver/magento/2-4-5/testing';
import { DaffOrder } from '@daffodil/order';

import { DAFF_CUSTOMER_ORDER_MAGENTO_ORDER_TRANSFORM } from './token';

describe('@daffodil/customer-order/driver/magento | DAFF_CUSTOMER_ORDER_MAGENTO_ORDER_TRANSFORM', () => {
describe('@daffodil/customer-order/driver/magento/2-4-5 | DAFF_CUSTOMER_ORDER_MAGENTO_ORDER_TRANSFORM', () => {
let magentoOrderFactory: MagentoCustomerOrderFactory;
let magentoOrder: MagentoCustomerOrder;
let result: DaffOrder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import {
MagentoCustomerOrders,
MagentoGetCustomerOrderResponse,
MagentoGetCustomerOrdersResponse,
} from '@daffodil/customer-order/driver/magento';
import { MagentoCustomerOrdersFactory } from '@daffodil/customer-order/driver/magento/testing';
} from '@daffodil/customer-order/driver/magento/2-4-5';
import { MagentoCustomerOrdersFactory } from '@daffodil/customer-order/driver/magento/2-4-5/testing';
import {
DaffDriverMagentoError,
schema,
} from '@daffodil/driver/magento';

import { DaffCustomerOrderMagentoService } from './order.service';

describe('@daffodil/customer-order/driver/magento | DaffCustomerOrderMagentoService', () => {
describe('@daffodil/customer-order/driver/magento/2-4-5 | DaffCustomerOrderMagentoService', () => {
let service: DaffCustomerOrderMagentoService;
let controller: ApolloTestingController;
let authStorageSpy: jasmine.SpyObj<DaffAuthStorageService>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TestBed } from '@angular/core/testing';

import { MagentoCustomerOrder } from '@daffodil/customer-order/driver/magento';
import { MagentoCustomerOrderFactory } from '@daffodil/customer-order/driver/magento/testing';
import { MagentoCustomerOrder } from '@daffodil/customer-order/driver/magento/2-4-5';
import { MagentoCustomerOrderFactory } from '@daffodil/customer-order/driver/magento/2-4-5/testing';
import { DaffOrder } from '@daffodil/order';

import { daffMagentoCustomerOrderTransformOrder } from './order';

describe('@daffodil/customer-order/driver/magento | daffMagentoCustomerOrderTransformOrder', () => {
describe('@daffodil/customer-order/driver/magento/2-4-5 | daffMagentoCustomerOrderTransformOrder', () => {
let orderFactory: MagentoCustomerOrderFactory;

let mockMagentoOrder: MagentoCustomerOrder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { TestBed } from '@angular/core/testing';
import { ApolloQueryResult } from '@apollo/client/core';

import { DaffCustomerInvalidAPIResponseError } from '@daffodil/customer-order/driver';
import { MagentoGetCustomerOrderResponse } from '@daffodil/customer-order/driver/magento';
import { MagentoCustomerOrderFactory } from '@daffodil/customer-order/driver/magento/testing';
import { MagentoGetCustomerOrderResponse } from '@daffodil/customer-order/driver/magento/2-4-5';
import { MagentoCustomerOrderFactory } from '@daffodil/customer-order/driver/magento/2-4-5/testing';

import { validateGetCustomerOrderResponse as validator } from './get-order';

describe('@daffodil/customer-order/driver/magento | validateGetCustomerOrderResponse', () => {
describe('@daffodil/customer-order/driver/magento/2-4-5 | validateGetCustomerOrderResponse', () => {
let response: ApolloQueryResult<MagentoGetCustomerOrderResponse>;
let orderFactory: MagentoCustomerOrderFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { TestBed } from '@angular/core/testing';
import { ApolloQueryResult } from '@apollo/client/core';

import { DaffCustomerInvalidAPIResponseError } from '@daffodil/customer-order/driver';
import { MagentoGetCustomerOrdersResponse } from '@daffodil/customer-order/driver/magento';
import { MagentoCustomerOrdersFactory } from '@daffodil/customer-order/driver/magento/testing';
import { MagentoGetCustomerOrdersResponse } from '@daffodil/customer-order/driver/magento/2-4-5';
import { MagentoCustomerOrdersFactory } from '@daffodil/customer-order/driver/magento/2-4-5/testing';

import { validateGetCustomerOrdersResponse as validator } from './get-orders';

describe('@daffodil/customer-order/driver/magento | validateGetCustomerOrdersResponse', () => {
describe('@daffodil/customer-order/driver/magento/2-4-5 | validateGetCustomerOrdersResponse', () => {
let response: ApolloQueryResult<MagentoGetCustomerOrdersResponse>;
let ordersFactory: MagentoCustomerOrdersFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestBed } from '@angular/core/testing';

import { MagentoCustomerOrder } from '@daffodil/customer-order/driver/magento';
import { MagentoCustomerOrder } from '@daffodil/customer-order/driver/magento/2-4-5';

import { MagentoCustomerOrderFactory } from './order.factory';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { faker } from '@faker-js/faker/locale/en_US';

import { DaffModelFactory } from '@daffodil/core/testing';
import { MagentoCustomerOrder } from '@daffodil/customer-order/driver/magento';
import { MagentoCustomerOrder } from '@daffodil/customer-order/driver/magento/2-4-5';
import {
MagentoOrderAddressFactory,
MagentoOrderInvoiceFactory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { TestBed } from '@angular/core/testing';

import { MagentoCustomerOrders } from '@daffodil/customer-order/driver/magento';
import { MagentoCustomerOrders } from '@daffodil/customer-order/driver/magento/2-4-5';

import { MagentoCustomerOrdersFactory } from './orders.factory';

describe('@daffodil/customer-order/driver/magento/testing | MagentoCustomerOrdersFactory', () => {
describe('@daffodil/customer-order/driver/magento/2-4-5/testing | MagentoCustomerOrdersFactory', () => {
let factory: MagentoCustomerOrdersFactory;

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DaffModelFactory } from '@daffodil/core/testing';
import {
MagentoCustomerOrders,
MagentoCustomerOrder,
} from '@daffodil/customer-order/driver/magento';
} from '@daffodil/customer-order/driver/magento/2-4-5';
import { MagentoSearchResultPageInfo } from '@daffodil/driver/magento';
import { MagentoSearchResultPageInfoFactory } from '@daffodil/driver/magento/testing';

Expand Down
6 changes: 6 additions & 0 deletions libs/customer-order/driver/magento/2-4-6/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "../../../../../node_modules/ng-packagr/ng-entrypoint.schema.json",
"lib": {
"entryFile": "src/index.ts"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { DaffSortOptions } from '@daffodil/core';

import { MagentoCustomerOrderSortableField } from '../../models/public_api';

export const magentoCustomerOrderSortFields: DaffSortOptions = {
options: [
{
label: 'Date',
value: MagentoCustomerOrderSortableField.CREATED_AT,
},
{
label: 'Number',
value: MagentoCustomerOrderSortableField.NUMBER,
},
],
default: MagentoCustomerOrderSortableField.CREATED_AT,
};
30 changes: 30 additions & 0 deletions libs/customer-order/driver/magento/2-4-6/src/driver.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { CommonModule } from '@angular/common';
import {
NgModule,
ModuleWithProviders,
} from '@angular/core';

import { DaffOrderDriver } from '@daffodil/order/driver';

import { DaffCustomerOrderMagentoService } from './order.service';
import { MagentoCustomerOrderCollectionTransformer } from './transforms/public_api';

@NgModule({
imports: [
CommonModule,
],
})
export class DaffCustomerOrderMagentoDriverModule {
static forRoot(): ModuleWithProviders<DaffCustomerOrderMagentoDriverModule> {
return {
ngModule: DaffCustomerOrderMagentoDriverModule,
providers: [
MagentoCustomerOrderCollectionTransformer,
{
provide: DaffOrderDriver,
useExisting: DaffCustomerOrderMagentoService,
},
],
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { transformMagentoReviewsError } from './transform';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DaffCustomerInvalidAPIResponseError } from '@daffodil/customer-order/driver';
import { daffTransformMagentoError } from '@daffodil/driver/magento';

export function transformMagentoReviewsError(error: any) {
return daffTransformMagentoError(error, {}) || new DaffCustomerInvalidAPIResponseError(error.message);
}
1 change: 1 addition & 0 deletions libs/customer-order/driver/magento/2-4-6/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './public_api';
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { TestBed } from '@angular/core/testing';
import { gql } from 'apollo-angular';
import { DocumentNode } from 'graphql';

import {
daffProvideCustomerOrderMagentoExtraOrderFragments,
DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS,
} from './order.token';

describe('@daffodil/customer-order/driver/magento/2-4-6 | daffProvideCustomerOrderMagentoExtraOrderFragments', () => {
let fragments: DocumentNode[];
let result: DocumentNode[];

beforeEach(() => {
fragments = [
gql`
fragment one on Query {
__typename
}
`,
gql`
fragment two on Query {
__typename
}
`,
];

TestBed.configureTestingModule({
providers: [
...daffProvideCustomerOrderMagentoExtraOrderFragments(...fragments),
],
});

result = TestBed.inject(DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS);
});

it('should provide the fragments to the token', () => {
fragments.forEach(fragment => {
expect(result).toContain(fragment);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
InjectionToken,
Provider,
} from '@angular/core';
import { DocumentNode } from 'graphql';

/**
* A multi-provider injection token for providing extra GraphQL fragments that will be spread into order queries.
* This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces.
*
* Fragment structure is platform-specific and this feature should be used with care.
*
* This can increase query complexity above the Magento default of 300.
* Daffodil only guarantees that stock queries don't exceed the limit of 300.
* Apps using this token should therefore increase the query complexity limit
* to accommodate the extra complexity contributed by the provided fragments.
*/
export const DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS = new InjectionToken<DocumentNode[]>(
'DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS',
{ factory: () => []},
);

/**
* Provides extra GraphQL fragments for the Magento order driver.
*
* See {@link DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS}.
*
* ```ts
* providers: [
* ...daffProvideCustomerOrderMagentoExtraOrderFragments(
* myExtraOrderFragment
* )
* ]
* ```
*/
export function daffProvideCustomerOrderMagentoExtraOrderFragments(...fragments: DocumentNode[]): Provider[] {
return fragments.map(fragment => ({
provide: DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS,
useValue: fragment,
multi: true,
}));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export {
daffProvideCustomerOrderMagentoExtraOrderFragments,
DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS,
} from './fragments/order.token';
export {
daffProvideCustomerOrderMagentoExtraOrderTransforms,
DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS,
} from './transforms/extra.token';
export { DAFF_CUSTOMER_ORDER_MAGENTO_ORDER_TRANSFORM } from './transforms/token';
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { TestBed } from '@angular/core/testing';

import { DaffMagentoCustomerOrderExtraTransform } from '@daffodil/customer-order/driver/magento/2-4-6';

import {
daffProvideCustomerOrderMagentoExtraOrderTransforms,
DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS,
} from './extra.token';

describe('@daffodil/customer-order/driver/magento/2-4-6 | daffProvideCustomerOrderMagentoExtraOrderTransforms', () => {
let transforms: DaffMagentoCustomerOrderExtraTransform[];
let result: DaffMagentoCustomerOrderExtraTransform[];

beforeEach(() => {
transforms = [
() => null,
() => null,
];

TestBed.configureTestingModule({
providers: [
...daffProvideCustomerOrderMagentoExtraOrderTransforms(...transforms),
],
});

result = TestBed.inject(DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS);
});

it('should provide the transforms to the token', () => {
transforms.forEach(fragment => {
expect(result).toContain(fragment);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
InjectionToken,
Provider,
} from '@angular/core';

// workaround https://github.com/graycoreio/daffodil/issues/1667
import { DaffOrder } from '@daffodil/order';

import { DaffMagentoCustomerOrderExtraTransform } from '../../interfaces/public_api';
import { MagentoCustomerOrder } from '../../models/public_api';

/**
* A multi-provider injection token for providing extra transform logic in the Order Magento driver.
* It is run after the standard transforms for each customer order preview and passed both the current transformed Daffodil customer order and the Magento customer order.
*
* See {@link MagentoCustomerOrder} for more info.
*/
export const DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS = new InjectionToken<DaffMagentoCustomerOrderExtraTransform[]>(
'DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS',
{ factory: () => []},
);

/**
* Provides extra customer order preview transforms for the Magento customer order driver.
*
* See {@link DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS}.
*
* ```ts
* providers: [
* ...daffProvideCustomerOrderMagentoExtraOrderTransforms(
* myExtraOrderTransform
* )
* ]
* ```
*/
export function daffProvideCustomerOrderMagentoExtraOrderTransforms<T extends MagentoCustomerOrder = MagentoCustomerOrder, V extends DaffOrder = DaffOrder>(...transforms: DaffMagentoCustomerOrderExtraTransform<T, V>[]): Provider[] {
return transforms.map(transform => ({
provide: DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS,
useValue: transform,
multi: true,
}));
}
Loading

0 comments on commit 265d54a

Please sign in to comment.