Skip to content

Commit

Permalink
fix: Refactor Rule assignment task and types (#237)
Browse files Browse the repository at this point in the history
* fix: task and types

* fix: add review feedback

---------

Co-authored-by: Daniel Meyer <[email protected]>
  • Loading branch information
GitEvil and Daniel Meyer authored Dec 19, 2024
1 parent d42b6f8 commit 49a585f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
28 changes: 14 additions & 14 deletions src/tasks/shop-admin/Rule/AssignEntitiesToRule.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Locator, test as base} from '@playwright/test';
import type {Task} from '../../../types/Task';
import type {FixtureTypes} from '../../../types/FixtureTypes';
import {RuleType} from '../../../types/ShopwareTypes';
import {RuleAssignmentEntity} from '../../../types/ShopwareTypes';
import { Locator, test as base } from '@playwright/test';
import type { Task } from '../../../types/Task';
import type { FixtureTypes } from '../../../types/FixtureTypes';
import { RuleType } from '../../../types/ShopwareTypes';
import { RuleAssignmentEntity } from '../../../types/ShopwareTypes';

export const AssignEntitiesToRule = base.extend<{ AssignEntitiesToRule: Task }, FixtureTypes>({
AssignEntitiesToRule: async ({ AdminRuleDetail }, use ) => {
Expand All @@ -15,28 +15,28 @@ export const AssignEntitiesToRule = base.extend<{ AssignEntitiesToRule: Task },
await AdminRuleDetail.page.locator('.sw-data-grid__row').filter({hasText: entityName}).getByRole('checkbox').click();
await AdminRuleDetail.page.locator('.sw-button--primary').getByText('Add').click();
}
for (const entity of assignableEntities) {
switch (entity.ruleType) {
for (const assignableEntity of assignableEntities) {
switch (assignableEntity.ruleType) {
case RuleType.shippingAvailability:
await entityAssignment(entity.name, AdminRuleDetail.shippingMethodAvailabilityRulesCard);
await entityAssignment(assignableEntity.entity.name, AdminRuleDetail.shippingMethodAvailabilityRulesCard);
break;
case RuleType.taxAvailability:
await entityAssignment(entity.name, AdminRuleDetail.taxProviderRulesCard);
await entityAssignment(assignableEntity.entity.name, AdminRuleDetail.taxProviderRulesCard);
break;
case RuleType.paymentAvailability:
await entityAssignment(entity.name, AdminRuleDetail.paymentMethodsAvailabilityRulesCard);
await entityAssignment(assignableEntity.entity.name, AdminRuleDetail.paymentMethodsAvailabilityRulesCard);
break;
case RuleType.promotionOrder:
await entityAssignment(entity.name, AdminRuleDetail.promotionOrderRulesCard);
await entityAssignment(assignableEntity.entity.name, AdminRuleDetail.promotionOrderRulesCard);
break;
case RuleType.promotionCustomer:
await entityAssignment(entity.name, AdminRuleDetail.promotionCustomerRulesCard);
await entityAssignment(assignableEntity.entity.name, AdminRuleDetail.promotionCustomerRulesCard);
break;
case RuleType.promotionCart:
await entityAssignment(entity.name, AdminRuleDetail.promotionCartRulesCard);
await entityAssignment(assignableEntity.entity.name, AdminRuleDetail.promotionCartRulesCard);
break;
default:
throw new Error(`Unknown rule type "${entity.ruleType}". Valid rule types: "${Object.values(RuleType).join('", "')}".`);
throw new Error(`Unknown rule type "${assignableEntity.ruleType}". Valid rule types: "${Object.values(RuleType).join('", "')}".`);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/types/ShopwareTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,13 @@ export enum RuleType {
promotionCustomer = 'promotionCustomerRule',
promotionCart = 'promotionCartRule',
}

export interface RuleAssignmentEntity {
entity: {
id: string;
name: string;
ruleType: RuleType;
}
ruleType: RuleType
}

export interface CategoryData {
Expand Down

0 comments on commit 49a585f

Please sign in to comment.