Sfoglia il codice sorgente

chore(core): Fix failing tests

Michael Bromley 1 anno fa
parent
commit
2cac885269

+ 2 - 3
packages/core/src/api/config/generate-resolvers.ts

@@ -255,9 +255,8 @@ function generateCustomFieldRelationResolvers(
                 } as any;
             }
         }
-        const allCustomFieldsAreNonPublic = customFields.every(
-            f => f.public === false || f.internal === true,
-        );
+        const allCustomFieldsAreNonPublic =
+            customFields.length && customFields.every(f => f.public === false || f.internal === true);
         if (allCustomFieldsAreNonPublic) {
             // When an entity has only non-public custom fields, the GraphQL type used for the
             // customFields field is `JSON`. This type will simply return the full object, which

+ 1 - 1
packages/core/src/service/helpers/order-calculator/order-calculator.ts

@@ -9,7 +9,7 @@ import { CacheKey } from '../../../common/constants';
 import { InternalServerError } from '../../../common/error/errors';
 import { idsAreEqual } from '../../../common/utils';
 import { ConfigService } from '../../../config/config.service';
-import { OrderLine, TaxCategory, TaxRate } from '../../../entity';
+import { OrderLine, TaxRate } from '../../../entity';
 import { Order } from '../../../entity/order/order.entity';
 import { Promotion } from '../../../entity/promotion/promotion.entity';
 import { Zone } from '../../../entity/zone/zone.entity';

+ 17 - 2
packages/core/src/testing/order-test-utils.ts

@@ -76,7 +76,9 @@ export const taxRateDefaultStandard = new TaxRate({
     value: 20,
     enabled: true,
     zone: zoneDefault,
+    zoneId: zoneDefault.id,
     category: taxCategoryStandard,
+    categoryId: taxCategoryStandard.id,
 });
 export const taxRateDefaultReduced = new TaxRate({
     id: 'taxRateDefaultReduced',
@@ -84,7 +86,9 @@ export const taxRateDefaultReduced = new TaxRate({
     value: 10,
     enabled: true,
     zone: zoneDefault,
+    zoneId: zoneDefault.id,
     category: taxCategoryReduced,
+    categoryId: taxCategoryReduced.id,
 });
 export const taxRateDefaultZero = new TaxRate({
     id: 'taxRateDefaultZero',
@@ -92,7 +96,9 @@ export const taxRateDefaultZero = new TaxRate({
     value: 0,
     enabled: true,
     zone: zoneDefault,
+    zoneId: zoneDefault.id,
     category: taxCategoryZero,
+    categoryId: taxCategoryZero.id,
 });
 export const taxRateOtherStandard = new TaxRate({
     id: 'taxRateOtherStandard',
@@ -100,7 +106,9 @@ export const taxRateOtherStandard = new TaxRate({
     value: 15,
     enabled: true,
     zone: zoneOther,
+    zoneId: zoneOther.id,
     category: taxCategoryStandard,
+    categoryId: taxCategoryStandard.id,
 });
 export const taxRateOtherReduced = new TaxRate({
     id: 'taxRateOtherReduced',
@@ -108,7 +116,9 @@ export const taxRateOtherReduced = new TaxRate({
     value: 5,
     enabled: true,
     zone: zoneOther,
+    zoneId: zoneOther.id,
     category: taxCategoryReduced,
+    categoryId: taxCategoryReduced.id,
 });
 
 export class MockTaxRateService {
@@ -124,14 +134,18 @@ export class MockTaxRateService {
         /* noop */
     }
 
-    async getApplicableTaxRate(ctx: RequestContext, zone: Zone, taxCategory: TaxCategory): Promise<TaxRate> {
+    async getApplicableTaxRate(
+        ctx: RequestContext,
+        zone: Zone | ID,
+        taxCategory: TaxCategory | ID,
+    ): Promise<TaxRate> {
         const rate = this.activeTaxRates.find(r => r.test(zone, taxCategory));
         return rate || taxRateDefaultStandard;
     }
 }
 
 export function createOrder(
-    orderConfig: Partial<Omit<Order, 'lines', 'surcharges'>> & {
+    orderConfig: Partial<Omit<Order, 'lines' | 'surcharges'>> & {
         ctx: RequestContext;
         lines: Array<{
             listPrice: number;
@@ -145,6 +159,7 @@ export function createOrder(
         ({ listPrice, taxCategory, quantity }) =>
             new OrderLine({
                 taxCategory,
+                taxCategoryId: taxCategory.id,
                 quantity,
                 orderPlacedQuantity: 0,
                 listPrice,