Skip to content

Commit

Permalink
fix: Add local type overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil23 authored and pweyck committed Jun 11, 2024
1 parent 49b5cc4 commit 870931c
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 27 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/data-fixtures/Category/Category.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test as base, expect } from '@playwright/test';
import type { FixtureTypes } from '../../types/FixtureTypes';
import type { components } from '@shopware/api-client/admin-api-types';
import type { Category } from '../../types/ShopwareTypes';

export const CategoryData = base.extend<FixtureTypes>({
CategoryData: async ({ IdProvider, AdminApiContext, DefaultSalesChannel, ProductData }, use) => {
Expand All @@ -26,7 +26,7 @@ export const CategoryData = base.extend<FixtureTypes>({

expect(categoryResponse.ok()).toBeTruthy();

const { data: category } = (await categoryResponse.json()) as { data: components['schemas']['Category'] };
const { data: category } = (await categoryResponse.json()) as { data: Category };

await use(category);

Expand Down
19 changes: 5 additions & 14 deletions src/data-fixtures/DataFixtures.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mergeTests } from '@playwright/test';
import type { components } from '@shopware/api-client/admin-api-types';
import type { Product, Category, Order } from '../types/ShopwareTypes';
import { ProductData } from './Product/Product';
import { CategoryData } from './Category/Category';
import { DigitalProductData } from './Product/DigitalProduct';
Expand All @@ -10,21 +11,11 @@ import { MediaData } from './Media/Media';
import { OrderData } from './Order/Order';
import { TagData } from './Tag/Tag';

export type ProductType = components['schemas']['Product'] & {
id: string,
price: {
gross: number,
net: number,
linked: boolean,
currencyId: string,
}[]
}

export interface DataFixtureTypes {
ProductData: ProductType,
CategoryData: components['schemas']['Category'],
ProductData: Product,
CategoryData: Category,
DigitalProductData: {
product: ProductType,
product: Product,
fileContent: string
},
PromotionWithCodeData: components['schemas']['Promotion'],
Expand All @@ -34,7 +25,7 @@ export interface DataFixtureTypes {
propertyGroupSize: components['schemas']['PropertyGroup']
},
MediaData: components['schemas']['Media'],
OrderData: components['schemas']['Order'],
OrderData: Order,
TagData: components['schemas']['Tag'],
}

Expand Down
4 changes: 2 additions & 2 deletions src/data-fixtures/Order/Order.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test as base, expect } from '@playwright/test';
import type { FixtureTypes } from '../../types/FixtureTypes';
import type { components } from '@shopware/api-client/admin-api-types';
import type { Order } from '../../types/ShopwareTypes';
import {
getCurrency,
getSalutationId,
Expand Down Expand Up @@ -226,7 +226,7 @@ export const OrderData = base.extend<FixtureTypes>({

expect(orderResponse.ok()).toBeTruthy();

const { data: order } = (await orderResponse.json()) as { data: components['schemas']['Order'] };
const { data: order } = (await orderResponse.json()) as { data: Order };

// Use order data in the test
await use(order);
Expand Down
3 changes: 2 additions & 1 deletion src/data-fixtures/Product/DigitalProduct.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { test as base, expect } from '@playwright/test';
import type { FixtureTypes } from '../../types/FixtureTypes';
import type { Order } from '../../types/ShopwareTypes';
import type { components } from '@shopware/api-client/admin-api-types';

export const DigitalProductData = base.extend<FixtureTypes>({
Expand Down Expand Up @@ -58,7 +59,7 @@ export const DigitalProductData = base.extend<FixtureTypes>({
});
expect(orderSearchResponse.ok()).toBeTruthy();

const { data: ordersWithDigitalProduct } = (await orderSearchResponse.json()) as { data: components['schemas']['Order'][] };
const { data: ordersWithDigitalProduct } = (await orderSearchResponse.json()) as { data: Order[] };

// Delete Orders using the digital product, to be able to delete the uploaded media file
for (const order of ordersWithDigitalProduct) {
Expand Down
4 changes: 2 additions & 2 deletions src/data-fixtures/Product/Product.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test as base, expect } from '@playwright/test';
import type { FixtureTypes } from '../../types/FixtureTypes';
import type { ProductType } from '../DataFixtures';
import type { Product } from '../../types/ShopwareTypes';

export const ProductData = base.extend<FixtureTypes>({
ProductData: async ({ IdProvider, SalesChannelBaseConfig, AdminApiContext, DefaultSalesChannel }, use) => {
Expand Down Expand Up @@ -61,7 +61,7 @@ export const ProductData = base.extend<FixtureTypes>({
});
expect(productResponse.ok()).toBeTruthy();

const { data: product } = (await productResponse.json()) as { data: ProductType };
const { data: product } = (await productResponse.json()) as { data: Product };

// Use product data in the test
await use(product);
Expand Down
5 changes: 3 additions & 2 deletions src/fixtures/DefaultSalesChannel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { test as base, expect, APIResponse } from '@playwright/test';
import type { FixtureTypes } from '../types/FixtureTypes';
import type { Customer } from '../types/ShopwareTypes';
import type { components } from '@shopware/api-client/admin-api-types';
import { createHash } from 'crypto';
import {
Expand Down Expand Up @@ -33,7 +34,7 @@ export interface DefaultSalesChannelTypes {
SalesChannelBaseConfig: StoreBaseConfig;
DefaultSalesChannel: {
salesChannel: components['schemas']['SalesChannel'];
customer: components['schemas']['Customer'] & { password: string };
customer: Customer;
url: string;
}
}
Expand Down Expand Up @@ -295,7 +296,7 @@ export const test = base.extend<NonNullable<unknown>, FixtureTypes>({
expect(themeAssignResp.ok()).toBeTruthy();
expect(salesChannelResp.ok()).toBeTruthy();

const customer = (await customerResp.json()) as { data: components['schemas']['Customer'] };
const customer = (await customerResp.json()) as { data: Customer };
const salesChannel = (await salesChannelResp.json()) as { data: components['schemas']['SalesChannel'] };

await use({
Expand Down
2 changes: 1 addition & 1 deletion src/page-objects/administration/CustomerDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class CustomerDetail implements PageObject {
this.accountCard = page.locator('.sw-customer-card')
}

url(customerId: string | undefined) {
url(customerId: string) {
return `#/sw/customer/detail/${customerId}/base`
}
}
2 changes: 1 addition & 1 deletion src/page-objects/administration/OrderDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class OrderDetail implements PageObject {
this.orderTag = page.locator('.sw-select-selection-list__item');
}

url(orderId: string | undefined) {
url(orderId: string) {
return `#/sw/order/detail/${orderId}/general`;
}
}
4 changes: 2 additions & 2 deletions src/page-objects/storefront/ProductDetail.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Page, Locator } from '@playwright/test';
import type { PageObject } from '../../types/PageObject';
import type { ProductType } from '../../data-fixtures/DataFixtures';
import type { Product } from '../../types/ShopwareTypes';

export class ProductDetail implements PageObject {

Expand Down Expand Up @@ -29,7 +29,7 @@ export class ProductDetail implements PageObject {
this.offCanvasSummaryTotalPrice = page.locator('.offcanvas-summary').locator('dt:has-text("Subtotal") + dd');
}

url(productData: ProductType) {
url(productData: Product) {
let namePath = '';
if (productData.translated && productData.translated.name) {
namePath = productData.translated.name.replaceAll('_', '-');
Expand Down
24 changes: 24 additions & 0 deletions src/types/ShopwareTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { components } from '@shopware/api-client/admin-api-types';

export type Customer = components['schemas']['Customer'] & {
id: string,
password: string,
}

export type Product = components['schemas']['Product'] & {
id: string,
price: {
gross: number,
net: number,
linked: boolean,
currencyId: string,
}[]
}

export type Category = components['schemas']['Category'] & {
id: string,
}

export type Order = components['schemas']['Order'] & {
id: string,
}

0 comments on commit 870931c

Please sign in to comment.