Skip to content

Commit ad4a224

Browse files
authored
Revert "OBPIH-6969 Improve approach to product creation and stock data (#61)" (#63)
This reverts commit a973e09.
1 parent a973e09 commit ad4a224

File tree

54 files changed

+320
-472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+320
-472
lines changed

playwright.config.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default defineConfig({
3232

3333
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3434
trace: 'retain-on-failure',
35-
35+
3636
launchOptions: {
3737
// slowMo: 1000,
3838
},
@@ -60,23 +60,14 @@ export default defineConfig({
6060
storageState: appConfig.users['main'].storagePath,
6161
},
6262
},
63-
{
64-
name: 'data-import-setup',
65-
testMatch: 'dataImport.setup.ts',
66-
testDir: './src/setup',
67-
dependencies: ['create-data-setup'],
68-
use: {
69-
storageState: appConfig.users['main'].storagePath,
70-
},
71-
},
7263
{
7364
name: 'chromium',
7465
use: {
7566
...devices['Desktop Chrome'],
7667
viewport: { width: 1366, height: 768 },
7768
storageState: appConfig.users['main'].storagePath,
7869
},
79-
dependencies: ['auth-setup', 'create-data-setup', 'data-import-setup'],
70+
dependencies: ['auth-setup', 'create-data-setup'],
8071
},
8172
],
8273
});

src/api/InventoryService.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/api/ProductService.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import BaseServiceModel from '@/api/BaseServiceModel';
22
import { ApiResponse, ProductDemandResponse, ProductResponse } from '@/types';
3-
import { jsonToCsv, parseRequestToJSON } from '@/utils/ServiceUtils';
3+
import { parseRequestToJSON } from '@/utils/ServiceUtils';
44

55
class ProductService extends BaseServiceModel {
66
async getDemand(id: string): Promise<ApiResponse<ProductDemandResponse>> {
@@ -22,24 +22,6 @@ class ProductService extends BaseServiceModel {
2222
throw new Error('Problem fetching product data');
2323
}
2424
}
25-
26-
async importProducts(data: Record<string, string>[]): Promise<ApiResponse<ProductResponse[]>> {
27-
try {
28-
const csvContent = jsonToCsv(data);
29-
30-
const apiResponse = await this.request.post(
31-
'./api/products/import',
32-
{
33-
data: csvContent,
34-
headers: { 'Content-Type': 'text/csv' }
35-
}
36-
);
37-
38-
return await parseRequestToJSON(apiResponse);
39-
} catch (error) {
40-
throw new Error(`Problem importing products: ${error instanceof Error ? error.message : String(error)}`);
41-
}
42-
}
4325
}
4426

4527
export default ProductService;

src/config/AppConfig.ts

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import TestUserConfig from '@/config/TestUserConfig';
88
import { ActivityCode } from '@/constants/ActivityCodes';
99
import { LocationTypeCode } from '@/constants/LocationTypeCode';
1010
import RoleType from '@/constants/RoleTypes';
11-
import { readCsvFile } from '@/utils/FileIOUtils';
1211
import UniqueIdentifier from '@/utils/UniqueIdentifier';
1312

1413
export enum USER_KEY {
@@ -53,12 +52,6 @@ class AppConfig {
5352

5453
public static TEST_DATA_FILE_PATH = path.join(process.cwd(), '.data.json');
5554

56-
public static DATA_IMPORT_DIRECTORY_PATH = path.join(process.cwd(), 'src/setup/dataImport');
57-
58-
public static PRODUCTS_IMPORT_FILE_PATH = path.join(AppConfig.DATA_IMPORT_DIRECTORY_PATH, '/products.csv');
59-
60-
public static INVENTORY_IMPORT_FILE_PATH = path.join(AppConfig.DATA_IMPORT_DIRECTORY_PATH, '/inventory.csv');
61-
6255
// Base URL to use in actions like `await page.goto('./dashboard')`.
6356
public appURL!: string;
6457

@@ -72,7 +65,7 @@ class AppConfig {
7265
public locations!: Record<LOCATION_KEY, LocationConfig>;
7366

7467
// test products used in all of the tests
75-
public products: Record<string, ProductConfig> = {};
68+
public products!: Record<PRODUCT_KEY, ProductConfig>;
7669

7770
//recivingbin configurable prefix
7871
public receivingBinPrefix!: string;
@@ -265,16 +258,44 @@ class AppConfig {
265258
}),
266259
};
267260

268-
// Fulfill products data in app config dynamically based on the products.csv
269-
const productsData = readCsvFile(AppConfig.PRODUCTS_IMPORT_FILE_PATH);
270-
productsData.forEach((productData) => {
271-
this.products[productData['ProductCode']] = new ProductConfig({
272-
key: productData['ProductCode'],
273-
name: productData['Name'],
274-
quantity: parseInt(productData['Quantity']),
261+
this.products = {
262+
productOne: new ProductConfig({
263+
id: env.get('PRODUCT_ONE').asString(),
264+
key: PRODUCT_KEY.ONE,
265+
name: this.uniqueIdentifier.generateUniqueString('product-one'),
266+
quantity: 122,
267+
required: false,
268+
}),
269+
productTwo: new ProductConfig({
270+
id: env.get('PRODUCT_TWO').asString(),
271+
key: PRODUCT_KEY.TWO,
272+
name: this.uniqueIdentifier.generateUniqueString('product-two'),
273+
quantity: 123,
274+
required: false,
275+
}),
276+
productThree: new ProductConfig({
277+
id: env.get('PRODUCT_THREE').asString(),
278+
key: PRODUCT_KEY.THREE,
279+
name: this.uniqueIdentifier.generateUniqueString('product-three'),
280+
quantity: 150,
275281
required: false,
276-
})
277-
})
282+
}),
283+
productFour: new ProductConfig({
284+
id: env.get('PRODUCT_FOUR').asString(),
285+
key: PRODUCT_KEY.FOUR,
286+
name: this.uniqueIdentifier.generateUniqueString('product-four'),
287+
quantity: 100,
288+
required: false,
289+
}),
290+
productFive: new ProductConfig({
291+
id: env.get('PRODUCT_FIVE').asString(),
292+
key: PRODUCT_KEY.FIVE,
293+
name: this.uniqueIdentifier.generateUniqueString('aa-product-five'),
294+
//'aa' part was added to improve visibility of ordering products alphabetically
295+
quantity: 160,
296+
required: false,
297+
}),
298+
};
278299

279300
this.receivingBinPrefix = env
280301
.get('RECEIVING_BIN_PREFIX')

src/config/ProductConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ProductConfig {
4444
* @returns {boolean}
4545
*/
4646
get isCreateNew() {
47-
return !this.readId();
47+
return !this.id;
4848
}
4949

5050
/**

src/fixtures/fixtures.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import LocationChooser from '@/components/LocationChooser';
1010
import Navbar from '@/components/Navbar';
1111
import AppConfig, {
1212
LOCATION_KEY,
13+
PRODUCT_KEY,
1314
USER_KEY,
1415
} from '@/config/AppConfig';
1516
import CreateInbound from '@/pages/inbound/create/CreateInboundPage';
@@ -81,7 +82,11 @@ type Fixtures = {
8182
wardLocationService: LocationData;
8283
noPickAndPutawayStockDepotService: LocationData;
8384
// PRODUCT DATA
84-
productService: ProductData;
85+
mainProductService: ProductData;
86+
otherProductService: ProductData;
87+
thirdProductService: ProductData;
88+
fourthProductService: ProductData;
89+
fifthProductService: ProductData;
8590
// USERS DATA
8691
mainUserService: UserData;
8792
altUserService: UserData;
@@ -154,8 +159,16 @@ export const test = baseTest.extend<Fixtures>({
154159
noPickAndPutawayStockDepotService: async ({ page }, use) =>
155160
use(new LocationData(LOCATION_KEY.NO_PICK_AND_PUTAWAY_STOCK, page.request)),
156161
// PRODUCTS
157-
productService: async ({ page }, use) =>
158-
use(new ProductData(page.request)),
162+
mainProductService: async ({ page }, use) =>
163+
use(new ProductData(PRODUCT_KEY.ONE, page.request)),
164+
otherProductService: async ({ page }, use) =>
165+
use(new ProductData(PRODUCT_KEY.TWO, page.request)),
166+
thirdProductService: async ({ page }, use) =>
167+
use(new ProductData(PRODUCT_KEY.THREE, page.request)),
168+
fourthProductService: async ({ page }, use) =>
169+
use(new ProductData(PRODUCT_KEY.FOUR, page.request)),
170+
fifthProductService: async ({ page }, use) =>
171+
use(new ProductData(PRODUCT_KEY.FIVE, page.request)),
159172
// USERS
160173
mainUserService: async ({ page }, use) =>
161174
use(new UserData(USER_KEY.MAIN, page.request)),

src/setup/createData.setup.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,58 @@
11
import AppConfig from '@/config/AppConfig';
22
import { test } from '@/fixtures/fixtures';
33
import { readFile, writeToFile } from '@/utils/FileIOUtils';
4+
import { parseUrl } from '@/utils/UrlUtils';
45

56
test('create data', async ({
7+
page,
8+
createProductPage,
9+
productShowPage,
610
locationService,
711
mainLocationService,
812
}) => {
913
// eslint-disable-next-line playwright/no-conditional-in-test
1014
const data = readFile(AppConfig.TEST_DATA_FILE_PATH) || {};
1115

12-
const seedData: Record<'locations', Record<string, string>> = {
16+
const seedData: Record<'products' | 'locations', Record<string, string>> = {
1317
...data,
18+
products: {},
1419
locations: {},
1520
};
1621

22+
// // PRODUCST
23+
const products = Object.values(AppConfig.instance.products).filter(
24+
(product) => product.isCreateNew
25+
);
26+
27+
for (const product of products) {
28+
await test.step(`create product ${product.key}`, async () => {
29+
await createProductPage.goToPage();
30+
await createProductPage.waitForUrl();
31+
await createProductPage.productDetails.nameField.fill(product.name);
32+
await createProductPage.productDetails.categorySelect.click();
33+
await createProductPage.productDetails.categorySelectDropdown
34+
.getByRole('listitem')
35+
.first()
36+
.click();
37+
await createProductPage.saveButton.click();
38+
39+
await productShowPage.recordStockButton.click();
40+
41+
await productShowPage.recordStock.lineItemsTable
42+
.row(1)
43+
.newQuantity.getByRole('textbox')
44+
.fill(`${product.quantity}`);
45+
await productShowPage.recordStock.lineItemsTable.saveButton.click();
46+
await productShowPage.showStockCardButton.click();
47+
48+
const productUrl = parseUrl(
49+
page.url(),
50+
'/openboxes/inventoryItem/showStockCard/$id'
51+
);
52+
seedData.products[`${product.key}`] = productUrl.id;
53+
});
54+
}
55+
1756
// LOCATIONS
1857
const { organization } = await mainLocationService.getLocation();
1958
const { data: locationTypes } = await locationService.getLocationTypes();

src/setup/dataImport.setup.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/setup/dataImport/inventory.csv

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/setup/dataImport/products.csv

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)