diff --git a/playwright.config.ts b/playwright.config.ts index 2622d12..9c551a9 100755 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -32,7 +32,7 @@ export default defineConfig({ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'retain-on-failure', - + launchOptions: { // slowMo: 1000, }, @@ -60,15 +60,6 @@ export default defineConfig({ storageState: appConfig.users['main'].storagePath, }, }, - { - name: 'data-import-setup', - testMatch: 'dataImport.setup.ts', - testDir: './src/setup', - dependencies: ['create-data-setup'], - use: { - storageState: appConfig.users['main'].storagePath, - }, - }, { name: 'chromium', use: { @@ -76,7 +67,7 @@ export default defineConfig({ viewport: { width: 1366, height: 768 }, storageState: appConfig.users['main'].storagePath, }, - dependencies: ['auth-setup', 'create-data-setup', 'data-import-setup'], + dependencies: ['auth-setup', 'create-data-setup'], }, ], }); diff --git a/src/api/InventoryService.ts b/src/api/InventoryService.ts deleted file mode 100644 index 67134fd..0000000 --- a/src/api/InventoryService.ts +++ /dev/null @@ -1,23 +0,0 @@ -import BaseServiceModel from '@/api/BaseServiceModel'; -import { jsonToCsv } from '@/utils/ServiceUtils'; - -class InventoryService extends BaseServiceModel { - async importInventories(data: Record[], facilityId: string): Promise { - try { - const csvContent = jsonToCsv(data); - - const response = await this.request.post(`./api/facilities/${facilityId}/inventories/import`, { - data: csvContent, - headers: { 'Content-Type': 'text/csv' }, - }); - - if (!response.ok()) { - throw new Error(`Import failed with status ${response.status()}: ${await response.text()}`); - } - } catch (error) { - throw new Error(`Problem importing inventories: ${error instanceof Error ? error.message : String(error)}`); - } - } -} - -export default InventoryService; diff --git a/src/api/ProductService.ts b/src/api/ProductService.ts index bf83b07..3150b63 100644 --- a/src/api/ProductService.ts +++ b/src/api/ProductService.ts @@ -1,6 +1,6 @@ import BaseServiceModel from '@/api/BaseServiceModel'; import { ApiResponse, ProductDemandResponse, ProductResponse } from '@/types'; -import { jsonToCsv, parseRequestToJSON } from '@/utils/ServiceUtils'; +import { parseRequestToJSON } from '@/utils/ServiceUtils'; class ProductService extends BaseServiceModel { async getDemand(id: string): Promise> { @@ -22,24 +22,6 @@ class ProductService extends BaseServiceModel { throw new Error('Problem fetching product data'); } } - - async importProducts(data: Record[]): Promise> { - try { - const csvContent = jsonToCsv(data); - - const apiResponse = await this.request.post( - './api/products/import', - { - data: csvContent, - headers: { 'Content-Type': 'text/csv' } - } - ); - - return await parseRequestToJSON(apiResponse); - } catch (error) { - throw new Error(`Problem importing products: ${error instanceof Error ? error.message : String(error)}`); - } - } } export default ProductService; diff --git a/src/config/AppConfig.ts b/src/config/AppConfig.ts index f8f0c62..7e3e14b 100644 --- a/src/config/AppConfig.ts +++ b/src/config/AppConfig.ts @@ -8,7 +8,6 @@ import TestUserConfig from '@/config/TestUserConfig'; import { ActivityCode } from '@/constants/ActivityCodes'; import { LocationTypeCode } from '@/constants/LocationTypeCode'; import RoleType from '@/constants/RoleTypes'; -import { readCsvFile } from '@/utils/FileIOUtils'; import UniqueIdentifier from '@/utils/UniqueIdentifier'; export enum USER_KEY { @@ -53,12 +52,6 @@ class AppConfig { public static TEST_DATA_FILE_PATH = path.join(process.cwd(), '.data.json'); - public static DATA_IMPORT_DIRECTORY_PATH = path.join(process.cwd(), 'src/setup/dataImport'); - - public static PRODUCTS_IMPORT_FILE_PATH = path.join(AppConfig.DATA_IMPORT_DIRECTORY_PATH, '/products.csv'); - - public static INVENTORY_IMPORT_FILE_PATH = path.join(AppConfig.DATA_IMPORT_DIRECTORY_PATH, '/inventory.csv'); - // Base URL to use in actions like `await page.goto('./dashboard')`. public appURL!: string; @@ -72,7 +65,7 @@ class AppConfig { public locations!: Record; // test products used in all of the tests - public products: Record = {}; + public products!: Record; //recivingbin configurable prefix public receivingBinPrefix!: string; @@ -265,16 +258,44 @@ class AppConfig { }), }; - // Fulfill products data in app config dynamically based on the products.csv - const productsData = readCsvFile(AppConfig.PRODUCTS_IMPORT_FILE_PATH); - productsData.forEach((productData) => { - this.products[productData['ProductCode']] = new ProductConfig({ - key: productData['ProductCode'], - name: productData['Name'], - quantity: parseInt(productData['Quantity']), + this.products = { + productOne: new ProductConfig({ + id: env.get('PRODUCT_ONE').asString(), + key: PRODUCT_KEY.ONE, + name: this.uniqueIdentifier.generateUniqueString('product-one'), + quantity: 122, + required: false, + }), + productTwo: new ProductConfig({ + id: env.get('PRODUCT_TWO').asString(), + key: PRODUCT_KEY.TWO, + name: this.uniqueIdentifier.generateUniqueString('product-two'), + quantity: 123, + required: false, + }), + productThree: new ProductConfig({ + id: env.get('PRODUCT_THREE').asString(), + key: PRODUCT_KEY.THREE, + name: this.uniqueIdentifier.generateUniqueString('product-three'), + quantity: 150, required: false, - }) - }) + }), + productFour: new ProductConfig({ + id: env.get('PRODUCT_FOUR').asString(), + key: PRODUCT_KEY.FOUR, + name: this.uniqueIdentifier.generateUniqueString('product-four'), + quantity: 100, + required: false, + }), + productFive: new ProductConfig({ + id: env.get('PRODUCT_FIVE').asString(), + key: PRODUCT_KEY.FIVE, + name: this.uniqueIdentifier.generateUniqueString('aa-product-five'), + //'aa' part was added to improve visibility of ordering products alphabetically + quantity: 160, + required: false, + }), + }; this.receivingBinPrefix = env .get('RECEIVING_BIN_PREFIX') diff --git a/src/config/ProductConfig.ts b/src/config/ProductConfig.ts index 1b6a6f2..dd3b1ac 100644 --- a/src/config/ProductConfig.ts +++ b/src/config/ProductConfig.ts @@ -44,7 +44,7 @@ class ProductConfig { * @returns {boolean} */ get isCreateNew() { - return !this.readId(); + return !this.id; } /** diff --git a/src/fixtures/fixtures.ts b/src/fixtures/fixtures.ts index 461b60b..164f4d7 100644 --- a/src/fixtures/fixtures.ts +++ b/src/fixtures/fixtures.ts @@ -10,6 +10,7 @@ import LocationChooser from '@/components/LocationChooser'; import Navbar from '@/components/Navbar'; import AppConfig, { LOCATION_KEY, + PRODUCT_KEY, USER_KEY, } from '@/config/AppConfig'; import CreateInbound from '@/pages/inbound/create/CreateInboundPage'; @@ -81,7 +82,11 @@ type Fixtures = { wardLocationService: LocationData; noPickAndPutawayStockDepotService: LocationData; // PRODUCT DATA - productService: ProductData; + mainProductService: ProductData; + otherProductService: ProductData; + thirdProductService: ProductData; + fourthProductService: ProductData; + fifthProductService: ProductData; // USERS DATA mainUserService: UserData; altUserService: UserData; @@ -154,8 +159,16 @@ export const test = baseTest.extend({ noPickAndPutawayStockDepotService: async ({ page }, use) => use(new LocationData(LOCATION_KEY.NO_PICK_AND_PUTAWAY_STOCK, page.request)), // PRODUCTS - productService: async ({ page }, use) => - use(new ProductData(page.request)), + mainProductService: async ({ page }, use) => + use(new ProductData(PRODUCT_KEY.ONE, page.request)), + otherProductService: async ({ page }, use) => + use(new ProductData(PRODUCT_KEY.TWO, page.request)), + thirdProductService: async ({ page }, use) => + use(new ProductData(PRODUCT_KEY.THREE, page.request)), + fourthProductService: async ({ page }, use) => + use(new ProductData(PRODUCT_KEY.FOUR, page.request)), + fifthProductService: async ({ page }, use) => + use(new ProductData(PRODUCT_KEY.FIVE, page.request)), // USERS mainUserService: async ({ page }, use) => use(new UserData(USER_KEY.MAIN, page.request)), diff --git a/src/setup/createData.setup.ts b/src/setup/createData.setup.ts index 0a6b42c..a4bc78e 100644 --- a/src/setup/createData.setup.ts +++ b/src/setup/createData.setup.ts @@ -1,19 +1,58 @@ import AppConfig from '@/config/AppConfig'; import { test } from '@/fixtures/fixtures'; import { readFile, writeToFile } from '@/utils/FileIOUtils'; +import { parseUrl } from '@/utils/UrlUtils'; test('create data', async ({ + page, + createProductPage, + productShowPage, locationService, mainLocationService, }) => { // eslint-disable-next-line playwright/no-conditional-in-test const data = readFile(AppConfig.TEST_DATA_FILE_PATH) || {}; - const seedData: Record<'locations', Record> = { + const seedData: Record<'products' | 'locations', Record> = { ...data, + products: {}, locations: {}, }; + // // PRODUCST + const products = Object.values(AppConfig.instance.products).filter( + (product) => product.isCreateNew + ); + + for (const product of products) { + await test.step(`create product ${product.key}`, async () => { + await createProductPage.goToPage(); + await createProductPage.waitForUrl(); + await createProductPage.productDetails.nameField.fill(product.name); + await createProductPage.productDetails.categorySelect.click(); + await createProductPage.productDetails.categorySelectDropdown + .getByRole('listitem') + .first() + .click(); + await createProductPage.saveButton.click(); + + await productShowPage.recordStockButton.click(); + + await productShowPage.recordStock.lineItemsTable + .row(1) + .newQuantity.getByRole('textbox') + .fill(`${product.quantity}`); + await productShowPage.recordStock.lineItemsTable.saveButton.click(); + await productShowPage.showStockCardButton.click(); + + const productUrl = parseUrl( + page.url(), + '/openboxes/inventoryItem/showStockCard/$id' + ); + seedData.products[`${product.key}`] = productUrl.id; + }); + } + // LOCATIONS const { organization } = await mainLocationService.getLocation(); const { data: locationTypes } = await locationService.getLocationTypes(); diff --git a/src/setup/dataImport.setup.ts b/src/setup/dataImport.setup.ts deleted file mode 100644 index d3589e8..0000000 --- a/src/setup/dataImport.setup.ts +++ /dev/null @@ -1,41 +0,0 @@ -import InventoryService from '@/api/InventoryService'; -import ProductService from '@/api/ProductService'; -import AppConfig from '@/config/AppConfig'; -import { test } from '@/fixtures/fixtures'; -import { readCsvFile, readFile, writeToFile } from '@/utils/FileIOUtils'; - -test('import data', async ({ request }) => { - // eslint-disable-next-line playwright/no-conditional-in-test - const data = readFile(AppConfig.TEST_DATA_FILE_PATH) || {}; - - const seedData: Record<'products', Record> = { - ...data, - products: {}, - }; - - // PRODUCTS - const productService = new ProductService(request); - - const productsData = readCsvFile(AppConfig.PRODUCTS_IMPORT_FILE_PATH); - - await test.step(`importing ${productsData.length} products`, async () => { - const importedData = await productService.importProducts(productsData); - importedData.data.forEach((product) => { - seedData.products[product.productCode] = product.id; - }) - }) - - // INVENTORIES - const inventoryService = new InventoryService(request); - - const inventoriesData = readCsvFile(AppConfig.INVENTORY_IMPORT_FILE_PATH); - - await test.step(`importing ${inventoriesData.length} inventories`, async () => { - await inventoryService.importInventories( - inventoriesData, - AppConfig.instance.locations.main.id, - ); - }); - - writeToFile(AppConfig.TEST_DATA_FILE_PATH, seedData); -}) diff --git a/src/setup/dataImport/inventory.csv b/src/setup/dataImport/inventory.csv deleted file mode 100644 index 402c381..0000000 --- a/src/setup/dataImport/inventory.csv +++ /dev/null @@ -1,3 +0,0 @@ -Product code,Product,Lot number,Expiration date,Bin location,Quantity,Comment -1,E2E-product-one,,,,122, -2,E2E-product-two,,,,123, diff --git a/src/setup/dataImport/products.csv b/src/setup/dataImport/products.csv deleted file mode 100644 index a3c4de7..0000000 --- a/src/setup/dataImport/products.csv +++ /dev/null @@ -1,6 +0,0 @@ -Id,ProductCode,ProductType,Name,ProductFamily,Category,GLAccount,Description,UnitOfMeasure,Tags,UnitCost,LotAndExpiryControl,ColdChain,ControlledSubstance,HazardousMaterial,Reconditioned,Manufacturer,BrandName,ManufacturerCode,ManufacturerName,Vendor,VendorCode,VendorName,UPC,NDC,Created,Updated -,1,Default,E2E-product-one,,ARVS,,,,,,,,,,,,,,,,,,,,, -,2,Default,E2E-product-two,,ARVS,,,,,,,,,,,,,,,,,,,,, -,3,Default,E2E-product-three,,ARVS,,,,,,,,,,,,,,,,,,,,, -,4,Default,E2E-product-four,,ARVS,,,,,,,,,,,,,,,,,,,,, -,5,Default,E2E-product-five,,ARVS,,,,,,,,,,,,,,,,,,,,, diff --git a/src/tests/inbound/createInbound/createInbound.test.ts b/src/tests/inbound/createInbound/createInbound.test.ts index 85a78b6..4968b5d 100644 --- a/src/tests/inbound/createInbound/createInbound.test.ts +++ b/src/tests/inbound/createInbound/createInbound.test.ts @@ -18,15 +18,14 @@ test.describe('Create inbound stock movement', () => { test.beforeEach( async ({ - productService, + mainProductService, + otherProductService, mainUserService, supplierLocationService, mainLocationService, }) => { - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); USER = await mainUserService.getUser(); ORIGIN = await supplierLocationService.getLocation(); CURRENT_LOCATION = await mainLocationService.getLocation(); @@ -189,16 +188,15 @@ test.describe('Values persistance between steps', () => { test.beforeEach( async ({ - productService, + mainProductService, + otherProductService, mainUserService, createInboundPage, mainLocationService, supplierLocationService, }) => { - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); USER = await mainUserService.getUser(); CURRENT_LOCATION = await mainLocationService.getLocation(); ORIGIN = await supplierLocationService.getLocation(); diff --git a/src/tests/inbound/createInbound/downloadDocsFromSendPage.test.ts b/src/tests/inbound/createInbound/downloadDocsFromSendPage.test.ts index 25c160f..08d892d 100644 --- a/src/tests/inbound/createInbound/downloadDocsFromSendPage.test.ts +++ b/src/tests/inbound/createInbound/downloadDocsFromSendPage.test.ts @@ -16,12 +16,11 @@ test.describe('Download documents from inbound send page', () => { test.beforeEach( async ({ - productService, + mainProductService, mainUserService, supplierLocationService, }) => { - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); USER = await mainUserService.getUser(); ORIGIN = await supplierLocationService.getLocation(); diff --git a/src/tests/inbound/createInbound/editDestinationFromSendPage.test.ts b/src/tests/inbound/createInbound/editDestinationFromSendPage.test.ts index 1e6141b..79be1dc 100644 --- a/src/tests/inbound/createInbound/editDestinationFromSendPage.test.ts +++ b/src/tests/inbound/createInbound/editDestinationFromSendPage.test.ts @@ -10,13 +10,12 @@ test.describe('Edit destination from send page', () => { async ({ supplierLocationService, stockMovementService, - productService, + otherProductService, + thirdProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); - productService.setProduct('3') - const PRODUCT_THREE = await productService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); + const PRODUCT_THREE = await thirdProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/inbound/createInbound/expectedDeliveryDate.test.ts b/src/tests/inbound/createInbound/expectedDeliveryDate.test.ts index 231ea80..fcc5737 100644 --- a/src/tests/inbound/createInbound/expectedDeliveryDate.test.ts +++ b/src/tests/inbound/createInbound/expectedDeliveryDate.test.ts @@ -12,14 +12,13 @@ test.describe('Expected delivery date tests', () => { supplierLocationService, mainUserService, stockMovementService, - productService, + thirdProductService, + fourthProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); USER = await mainUserService.getUser(); - productService.setProduct('3'); - const PRODUCT_THREE = await productService.getProduct(); - productService.setProduct('4'); - const PRODUCT_FOUR = await productService.getProduct(); + const PRODUCT_THREE = await thirdProductService.getProduct(); + const PRODUCT_FOUR = await fourthProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/inbound/createInbound/exportItems.test.ts b/src/tests/inbound/createInbound/exportItems.test.ts index 21ba584..e7b9d83 100644 --- a/src/tests/inbound/createInbound/exportItems.test.ts +++ b/src/tests/inbound/createInbound/exportItems.test.ts @@ -11,8 +11,9 @@ test.describe('Export all incoming items', () => { async ({ supplierLocationService, createInboundPage, - productService, + mainProductService, mainUserService, + otherProductService, stockMovementShowPage, inboundListPage, }) => { @@ -21,10 +22,8 @@ test.describe('Export all incoming items', () => { const USER = await mainUserService.getUser(); const TODAY = getToday(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); const SHIPMENT_TYPE = 'Land'; const EXPECTED_DELIVERY_DATE = getDateByOffset(TODAY, 1); diff --git a/src/tests/inbound/createInbound/fieldValidation.test.ts b/src/tests/inbound/createInbound/fieldValidation.test.ts index b215ca1..55b194f 100644 --- a/src/tests/inbound/createInbound/fieldValidation.test.ts +++ b/src/tests/inbound/createInbound/fieldValidation.test.ts @@ -11,13 +11,12 @@ let ORIGIN: LocationResponse; test.beforeEach( async ({ - productService, + mainProductService, mainUserService, createInboundPage, supplierLocationService, }) => { - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); USER = await mainUserService.getUser(); ORIGIN = await supplierLocationService.getLocation(); diff --git a/src/tests/inbound/createInbound/inboundStatusChanges.test.ts b/src/tests/inbound/createInbound/inboundStatusChanges.test.ts index df10818..374f6d0 100644 --- a/src/tests/inbound/createInbound/inboundStatusChanges.test.ts +++ b/src/tests/inbound/createInbound/inboundStatusChanges.test.ts @@ -22,14 +22,13 @@ test.describe('Status changes for inbound sm on view sm and inbound list page', test.beforeEach( async ({ - productService, + mainProductService, + otherProductService, mainUserService, supplierLocationService, }) => { - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); USER = await mainUserService.getUser(); ORIGIN = await supplierLocationService.getLocation(); diff --git a/src/tests/inbound/createInbound/itemTemplate.test.ts b/src/tests/inbound/createInbound/itemTemplate.test.ts index a33d16c..b6ad0cc 100644 --- a/src/tests/inbound/createInbound/itemTemplate.test.ts +++ b/src/tests/inbound/createInbound/itemTemplate.test.ts @@ -75,7 +75,8 @@ test.describe('Export items template on inbound add items page', () => { test('Downloaded template should contain all added items', async ({ createInboundPage, - productService, + mainProductService, + otherProductService, mainUserService, }) => { await test.step('Go to inbound list page', async () => { @@ -83,10 +84,8 @@ test.describe('Export items template on inbound add items page', () => { await createInboundPage.addItemsStep.isLoaded(); }); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); const USER = await mainUserService.getUser(); const ROWS = [ @@ -176,7 +175,8 @@ test.describe('Import template with data', () => { test('Import filled template on an empty table', async ({ createInboundPage, - productService, + mainProductService, + otherProductService, mainUserService, }) => { await test.step('Go to inbound list page', async () => { @@ -193,10 +193,8 @@ test.describe('Import template with data', () => { workbooks.push(downloadedTemplateFile); }); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); const USER = await mainUserService.getUser(); const ROWS = [ @@ -256,7 +254,8 @@ test.describe('Import template with data', () => { test.skip('Update existing values with template import', async ({ createInboundPage, - productService, + otherProductService, + mainProductService, altUserService, mainUserService, }) => { @@ -266,8 +265,7 @@ test.describe('Import template with data', () => { }); await test.step('Add items to table', async () => { - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); const USER = await mainUserService.getUser(); const ROWS = [ @@ -302,8 +300,7 @@ test.describe('Import template with data', () => { parsedDocumentData = downloadedTemplateFile.sheetToJSON(); }); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); const ALT_USER = await altUserService.getUser(); const NEW_ROW = { @@ -348,7 +345,8 @@ test.describe('Import template with data', () => { test('Add new row to with existing items in the table', async ({ createInboundPage, - productService, + otherProductService, + mainProductService, altUserService, mainUserService, }) => { @@ -359,8 +357,7 @@ test.describe('Import template with data', () => { let ROW: CreateInboundAddItemsTableEntity; await test.step('Add items to table', async () => { - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); const USER = await mainUserService.getUser(); ROW = { @@ -392,8 +389,7 @@ test.describe('Import template with data', () => { parsedDocumentData = downloadedTemplateFile.sheetToJSON(); }); - productService.setProduct('2') - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); const ALT_USER = await altUserService.getUser(); const NEW_ROW = { diff --git a/src/tests/inbound/createInbound/packLevels.test.ts b/src/tests/inbound/createInbound/packLevels.test.ts index 9d454ef..acbd47e 100644 --- a/src/tests/inbound/createInbound/packLevels.test.ts +++ b/src/tests/inbound/createInbound/packLevels.test.ts @@ -8,13 +8,12 @@ let INBOUND_ID: string; test.beforeEach( async ({ - productService, + mainProductService, mainUserService, createInboundPage, supplierLocationService, }) => { - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); const USER = await mainUserService.getUser(); const ORIGIN = await supplierLocationService.getLocation(); const DESCRIPTION = 'some description'; diff --git a/src/tests/inbound/createInbound/saveAndExit.test.ts b/src/tests/inbound/createInbound/saveAndExit.test.ts index b770aab..19d252a 100644 --- a/src/tests/inbound/createInbound/saveAndExit.test.ts +++ b/src/tests/inbound/createInbound/saveAndExit.test.ts @@ -8,13 +8,12 @@ let INBOUND_ID: string; test.beforeEach( async ({ - productService, + mainProductService, mainUserService, createInboundPage, supplierLocationService, }) => { - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); const USER = await mainUserService.getUser(); const ORIGIN = await supplierLocationService.getLocation(); const DESCRIPTION = 'some description'; diff --git a/src/tests/inbound/createInbound/selectPersonInRequestedBy.test.ts b/src/tests/inbound/createInbound/selectPersonInRequestedBy.test.ts index 3d0cb23..fceff99 100644 --- a/src/tests/inbound/createInbound/selectPersonInRequestedBy.test.ts +++ b/src/tests/inbound/createInbound/selectPersonInRequestedBy.test.ts @@ -18,14 +18,13 @@ test.describe('Select person in requested by', () => { test.beforeEach( async ({ - productService, + mainProductService, supplierLocationService, page, personsListPage, createPersonPage, }) => { - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); ORIGIN = await supplierLocationService.getLocation(); ROWS = [ diff --git a/src/tests/inbound/createInbound/switchLocations.test.ts b/src/tests/inbound/createInbound/switchLocations.test.ts index d5cab17..b750593 100644 --- a/src/tests/inbound/createInbound/switchLocations.test.ts +++ b/src/tests/inbound/createInbound/switchLocations.test.ts @@ -10,13 +10,12 @@ test.describe('Switching location on inbound stock movement', () => { test.beforeEach( async ({ - productService, + mainProductService, mainUserService, createInboundPage, supplierLocationService, }) => { - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); const USER = await mainUserService.getUser(); const ORIGIN = await supplierLocationService.getLocation(); const DESCRIPTION = 'some description'; diff --git a/src/tests/inbound/createInbound/tableShortcuts.test.ts b/src/tests/inbound/createInbound/tableShortcuts.test.ts index 22a5495..b17ef13 100644 --- a/src/tests/inbound/createInbound/tableShortcuts.test.ts +++ b/src/tests/inbound/createInbound/tableShortcuts.test.ts @@ -7,13 +7,12 @@ let INBOUND_ID: string; test.beforeEach( async ({ - productService, + mainProductService, mainUserService, createInboundPage, supplierLocationService, }) => { - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); const USER = await mainUserService.getUser(); const ORIGIN = await supplierLocationService.getLocation(); const DESCRIPTION = 'some description'; diff --git a/src/tests/inbound/listPage/exportStockMovements.test.ts b/src/tests/inbound/listPage/exportStockMovements.test.ts index 4be6ac8..05b266e 100644 --- a/src/tests/inbound/listPage/exportStockMovements.test.ts +++ b/src/tests/inbound/listPage/exportStockMovements.test.ts @@ -14,13 +14,12 @@ test.describe('Export stock movements', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); INBOUND1 = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/inbound/listPage/myStockMovementFilter.test.ts b/src/tests/inbound/listPage/myStockMovementFilter.test.ts index 6a4ec9d..7124ecb 100644 --- a/src/tests/inbound/listPage/myStockMovementFilter.test.ts +++ b/src/tests/inbound/listPage/myStockMovementFilter.test.ts @@ -11,14 +11,13 @@ test.describe('My Stock Movement filter', () => { supplierLocationService, mainUserService, stockMovementService, - productService, + mainProductService, + otherProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); USER = await mainUserService.getUser(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); INBOUND = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/inbound/listPage/receiptStatusFilter.test.ts b/src/tests/inbound/listPage/receiptStatusFilter.test.ts index 20cc56c..a8238f0 100644 --- a/src/tests/inbound/listPage/receiptStatusFilter.test.ts +++ b/src/tests/inbound/listPage/receiptStatusFilter.test.ts @@ -53,15 +53,14 @@ test.describe('Filter by "Shipped" status', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, }); - productService.setProduct('1'); - const product = await productService.getProduct(); + const product = await mainProductService.getProduct(); await stockMovementService.addItemsToInboundStockMovement( STOCK_MOVEMENT.id, @@ -117,7 +116,7 @@ test.describe('Filter by "Received" status', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, stockMovementShowPage, receivingPage, }) => { @@ -126,8 +125,7 @@ test.describe('Filter by "Received" status', () => { originId: supplierLocation.id, }); - productService.setProduct('1'); - const product = await productService.getProduct(); + const product = await mainProductService.getProduct(); await stockMovementService.addItemsToInboundStockMovement( STOCK_MOVEMENT.id, @@ -209,7 +207,8 @@ test.describe('Filter by "Receiving" status', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, stockMovementShowPage, receivingPage, }) => { @@ -218,10 +217,8 @@ test.describe('Filter by "Receiving" status', () => { originId: supplierLocation.id, }); - productService.setProduct('1'); - const product = await productService.getProduct(); - productService.setProduct('2'); - const productTwo = await productService.getProduct(); + const product = await mainProductService.getProduct(); + const productTwo = await otherProductService.getProduct(); await stockMovementService.addItemsToInboundStockMovement( STOCK_MOVEMENT.id, @@ -307,7 +304,7 @@ test.describe('Filter by multiple statuses - "Pending" and "Shipped"', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); STOCK_MOVEMENT = await stockMovementService.createInbound({ @@ -318,8 +315,7 @@ test.describe('Filter by multiple statuses - "Pending" and "Shipped"', () => { originId: supplierLocation.id, }); - productService.setProduct('1'); - const product = await productService.getProduct(); + const product = await mainProductService.getProduct(); await stockMovementService.addItemsToInboundStockMovement( STOCK_MOVEMENT_TWO.id, diff --git a/src/tests/inbound/listPage/shipmentTypeFilter.test.ts b/src/tests/inbound/listPage/shipmentTypeFilter.test.ts index b66e3bd..dfb21e2 100644 --- a/src/tests/inbound/listPage/shipmentTypeFilter.test.ts +++ b/src/tests/inbound/listPage/shipmentTypeFilter.test.ts @@ -16,12 +16,11 @@ test.describe('Shipment type filter', () => { test.beforeEach( async ({ supplierLocationService, - productService, + mainProductService, stockMovementService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const product = await productService.getProduct(); + const product = await mainProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, @@ -108,12 +107,11 @@ test.describe('Multiple shipment types', () => { test.beforeEach( async ({ supplierLocationService, - productService, + mainProductService, stockMovementService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const product = await productService.getProduct(); + const product = await mainProductService.getProduct(); STOCK_MOVEMENT_LAND = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/inbound/listPage/updatedByFilter.test.ts b/src/tests/inbound/listPage/updatedByFilter.test.ts index 1ac21e5..e7859a1 100644 --- a/src/tests/inbound/listPage/updatedByFilter.test.ts +++ b/src/tests/inbound/listPage/updatedByFilter.test.ts @@ -32,10 +32,9 @@ test.describe('Use "Updated By" filter', () => { test('Only show stock movements updated by filtered user', async ({ altUserContext, inboundListPage, - productService, + mainProductService, }) => { - productService.setProduct('1'); - const product = await productService.getProduct(); + const product = await mainProductService.getProduct(); await test.step('Go to inbound list page', async () => { await inboundListPage.goToPage(); diff --git a/src/tests/receiving/assertBinLocationField.test.ts b/src/tests/receiving/assertBinLocationField.test.ts index a7657c6..7dcd40b 100644 --- a/src/tests/receiving/assertBinLocationField.test.ts +++ b/src/tests/receiving/assertBinLocationField.test.ts @@ -10,11 +10,10 @@ test.describe('Assert bin location not clearable', () => { async ({ supplierLocationService, stockMovementService, - productService, + fourthProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('4'); - const PRODUCT_FOUR = await productService.getProduct(); + const PRODUCT_FOUR = await fourthProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/receiving/assertCreationOfGoodsReceiptNote.test.ts b/src/tests/receiving/assertCreationOfGoodsReceiptNote.test.ts index ce0c750..05eead7 100644 --- a/src/tests/receiving/assertCreationOfGoodsReceiptNote.test.ts +++ b/src/tests/receiving/assertCreationOfGoodsReceiptNote.test.ts @@ -9,13 +9,12 @@ test.describe('Assert Goods Receipt Note is created and opened', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + thirdProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('3'); - const PRODUCT_THREE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_THREE = await thirdProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/receiving/assertCreationOfReceivingBin.test.ts b/src/tests/receiving/assertCreationOfReceivingBin.test.ts index 90c314c..6245728 100644 --- a/src/tests/receiving/assertCreationOfReceivingBin.test.ts +++ b/src/tests/receiving/assertCreationOfReceivingBin.test.ts @@ -14,13 +14,12 @@ test.describe('Assert creation of receiving bin', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/receiving/assertQtyInputs.test.ts b/src/tests/receiving/assertQtyInputs.test.ts index f5acbc4..a74d102 100644 --- a/src/tests/receiving/assertQtyInputs.test.ts +++ b/src/tests/receiving/assertQtyInputs.test.ts @@ -10,15 +10,14 @@ test.describe('Assert if quantity inputs remain when split lines', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, + thirdProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); - productService.setProduct('3'); - const PRODUCT_THREE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); + const PRODUCT_THREE = await thirdProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/receiving/assertRecipientField.test.ts b/src/tests/receiving/assertRecipientField.test.ts index 0bb3abb..083c32e 100644 --- a/src/tests/receiving/assertRecipientField.test.ts +++ b/src/tests/receiving/assertRecipientField.test.ts @@ -9,14 +9,13 @@ test.describe('Assert recipient field when receive', () => { async ({ supplierLocationService, stockMovementService, - productService, + fourthProductService, + fifthProductService, mainUserService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('4'); - const PRODUCT_FOUR = await productService.getProduct(); - productService.setProduct('5'); - const PRODUCT_FIVE = await productService.getProduct(); + const PRODUCT_FOUR = await fourthProductService.getProduct(); + const PRODUCT_FIVE = await fifthProductService.getProduct(); const USER = await mainUserService.getUser(); STOCK_MOVEMENT = await stockMovementService.createInbound({ diff --git a/src/tests/receiving/cancelRemainingQty.test.ts b/src/tests/receiving/cancelRemainingQty.test.ts index 7fd315f..827b876 100644 --- a/src/tests/receiving/cancelRemainingQty.test.ts +++ b/src/tests/receiving/cancelRemainingQty.test.ts @@ -9,13 +9,12 @@ test.describe('Cancel qty in the middle of receipt', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/receiving/editBinLocationWhenReceive.test.ts b/src/tests/receiving/editBinLocationWhenReceive.test.ts index 5b09351..cfa3857 100644 --- a/src/tests/receiving/editBinLocationWhenReceive.test.ts +++ b/src/tests/receiving/editBinLocationWhenReceive.test.ts @@ -15,17 +15,16 @@ test.describe('Edit Bin Location when receive inbound stock movement', () => { supplierLocationService, mainLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, page, locationListPage, createLocationPage, }) => { const supplierLocation = await supplierLocationService.getLocation(); const mainLocation = await mainLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, @@ -74,14 +73,7 @@ test.describe('Edit Bin Location when receive inbound stock movement', () => { createLocationPage, }) => { await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); - - const hasRollbackLastReceipt = - await stockMovementShowPage.rollbackLastReceiptButton.isVisible().catch(() => false); - - if (hasRollbackLastReceipt) { - await stockMovementShowPage.rollbackLastReceiptButton.click(); - } - + await stockMovementShowPage.rollbackLastReceiptButton.click(); await stockMovementShowPage.rollbackButton.click(); await stockMovementService.deleteStockMovement(STOCK_MOVEMENT.id); @@ -178,17 +170,16 @@ test.describe('Edit Bin Location to bin with zone when receive inbound stock mov supplierLocationService, mainLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, page, locationListPage, createLocationPage, }) => { const supplierLocation = await supplierLocationService.getLocation(); const mainLocation = await mainLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, @@ -383,17 +374,16 @@ test.describe('Edit Bin Location when receive for all lines', () => { supplierLocationService, mainLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, page, locationListPage, createLocationPage, }) => { const supplierLocation = await supplierLocationService.getLocation(); const mainLocation = await mainLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/receiving/editOriginalLineQtyTo0.test.ts b/src/tests/receiving/editOriginalLineQtyTo0.test.ts index 5e7dcfe..801b95c 100644 --- a/src/tests/receiving/editOriginalLineQtyTo0.test.ts +++ b/src/tests/receiving/editOriginalLineQtyTo0.test.ts @@ -13,19 +13,18 @@ test.describe('Edit qty of original line to 0', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, + thirdProductService, + fourthProductService, + fifthProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); - productService.setProduct('3'); - const PRODUCT_THREE = await productService.getProduct(); - productService.setProduct('4') - const PRODUCT_FOUR = await productService.getProduct(); - productService.setProduct('5') - const PRODUCT_FIVE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); + const PRODUCT_THREE = await thirdProductService.getProduct(); + const PRODUCT_FOUR = await fourthProductService.getProduct(); + const PRODUCT_FIVE = await fifthProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, @@ -220,11 +219,10 @@ test.describe('Edit original line to other product in the middle of receipt', () async ({ supplierLocationService, stockMovementService, - productService, + fourthProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('4'); - const PRODUCT_FOUR = await productService.getProduct(); + const PRODUCT_FOUR = await fourthProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, @@ -263,7 +261,8 @@ test.describe('Edit original line to other product in the middle of receipt', () test('Edit qty of original line to 0 and edit product to other', async ({ stockMovementShowPage, receivingPage, - productService, + fifthProductService, + fourthProductService, }) => { await test.step('Go to stock movement show page', async () => { await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); @@ -276,8 +275,7 @@ test.describe('Edit original line to other product in the middle of receipt', () }); await test.step('Open edit modal for item', async () => { - productService.setProduct('5'); - const PRODUCT_FIVE = await productService.getProduct(); + const PRODUCT_FIVE = await fifthProductService.getProduct(); await receivingPage.receivingStep.table.row(1).editButton.click(); await receivingPage.receivingStep.editModal.isLoaded(); await receivingPage.receivingStep.editModal.addLineButton.click(); @@ -298,10 +296,8 @@ test.describe('Edit original line to other product in the middle of receipt', () }); await test.step('Assert line with qty 0 is disabled', async () => { - productService.setProduct('4'); - const PRODUCT_FOUR = await productService.getProduct(); - productService.setProduct('5') - const PRODUCT_FIVE = await productService.getProduct(); + const PRODUCT_FOUR = await fourthProductService.getProduct(); + const PRODUCT_FIVE = await fifthProductService.getProduct(); await expect( receivingPage.receivingStep.table.row(1).checkbox ).toBeDisabled(); @@ -341,8 +337,7 @@ test.describe('Edit original line to other product in the middle of receipt', () }); await test.step('Assert product name on check step', async () => { - productService.setProduct('5'); - const PRODUCT_FIVE = await productService.getProduct(); + const PRODUCT_FIVE = await fifthProductService.getProduct(); await receivingPage.nextButton.click(); await receivingPage.checkStep.isLoaded(); await expect( @@ -357,10 +352,8 @@ test.describe('Edit original line to other product in the middle of receipt', () }); await test.step('Assert received product on stock movement show page', async () => { - productService.setProduct('4'); - const PRODUCT_FOUR = await productService.getProduct(); - productService.setProduct('5'); - const PRODUCT_FIVE = await productService.getProduct(); + const PRODUCT_FOUR = await fourthProductService.getProduct(); + const PRODUCT_FIVE = await fifthProductService.getProduct(); await stockMovementShowPage.packingListTab.isVisible(); await expect( stockMovementShowPage.packingListTable.row(1).product diff --git a/src/tests/receiving/editsInReceiving.test.ts b/src/tests/receiving/editsInReceiving.test.ts index 22ba77a..2deeb46 100644 --- a/src/tests/receiving/editsInReceiving.test.ts +++ b/src/tests/receiving/editsInReceiving.test.ts @@ -14,13 +14,12 @@ test.describe('Edit items in the middle of receipt', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/receiving/exportReceivingTemplate.test.ts b/src/tests/receiving/exportReceivingTemplate.test.ts index 732683e..54414a6 100644 --- a/src/tests/receiving/exportReceivingTemplate.test.ts +++ b/src/tests/receiving/exportReceivingTemplate.test.ts @@ -18,15 +18,14 @@ test.describe('Export receiving template', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, + thirdProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); - productService.setProduct('3'); - const PRODUCT_THREE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); + const PRODUCT_THREE = await thirdProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, @@ -66,17 +65,16 @@ test.describe('Export receiving template', () => { test('Export receiving template', async ({ stockMovementShowPage, receivingPage, - productService, + mainProductService, + otherProductService, + thirdProductService }) => { let filePath: string; let downloadedExportTemplateFile: WorkbookUtils; - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); - productService.setProduct('3'); - const PRODUCT_THREE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); + const PRODUCT_THREE = await thirdProductService.getProduct(); const ROWS = [ { diff --git a/src/tests/receiving/importReceivingTemplate.test.ts b/src/tests/receiving/importReceivingTemplate.test.ts index 34e2c01..9a765bc 100644 --- a/src/tests/receiving/importReceivingTemplate.test.ts +++ b/src/tests/receiving/importReceivingTemplate.test.ts @@ -21,11 +21,10 @@ test.describe('Import receiving template', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/receiving/lotExpirySystemUpdateOnReceiving.test.ts b/src/tests/receiving/lotExpirySystemUpdateOnReceiving.test.ts index 1a47978..1a7052f 100644 --- a/src/tests/receiving/lotExpirySystemUpdateOnReceiving.test.ts +++ b/src/tests/receiving/lotExpirySystemUpdateOnReceiving.test.ts @@ -39,7 +39,7 @@ test.describe('Lot number system expiry date modification on receiving workflow' stockMovementShowPage, receivingPage, stockMovementService, - productService, + mainProductService, productShowPage, supplierLocationService, }) => { @@ -54,8 +54,7 @@ test.describe('Lot number system expiry date modification on receiving workflow' const UPDATED_EXPIRY_DATE_NEW_LOT = getDateByOffset(getToday(), 2); - productService.setProduct('1'); - const product = await productService.getProduct(); + const product = await mainProductService.getProduct(); await test.step('Ensure that lot number does not exist in product stock', async () => { await productShowPage.goToPage(product.id); @@ -171,7 +170,7 @@ test.describe('Lot number system expiry date modification on receiving workflow' stockMovementShowPage, receivingPage, stockMovementService, - productService, + mainProductService, productShowPage, supplierLocationService, }) => { @@ -179,8 +178,7 @@ test.describe('Lot number system expiry date modification on receiving workflow' let STOCK_MOVEMENT: StockMovementResponse; - productService.setProduct('1'); - const product = await productService.getProduct(); + const product = await mainProductService.getProduct(); TEST_INPUT_STOCK_EXISTING_LOT.lotNumber = uniqueIdentifier.generateUniqueString('lot'); @@ -263,14 +261,13 @@ test.describe('Lot number system expiry date modification on receiving workflow' stockMovementShowPage, receivingPage, stockMovementService, - productService, + mainProductService, productShowPage, supplierLocationService, }) => { let STOCK_MOVEMENT_2: StockMovementResponse; - productService.setProduct('1'); - const product = await productService.getProduct(); + const product = await mainProductService.getProduct(); await test.step('Create second inbound stock movement', async () => { const supplierLocation = await supplierLocationService.getLocation(); @@ -378,14 +375,13 @@ test.describe('Lot number system expiry date modification on receiving workflow' stockMovementShowPage, receivingPage, stockMovementService, - productService, + mainProductService, productShowPage, supplierLocationService, }) => { let STOCK_MOVEMENT_2: StockMovementResponse; - productService.setProduct('1'); - const product = await productService.getProduct(); + const product = await mainProductService.getProduct(); await test.step('Create second inbound stock movement', async () => { const supplierLocation = await supplierLocationService.getLocation(); diff --git a/src/tests/receiving/receiveInbound.test.ts b/src/tests/receiving/receiveInbound.test.ts index b983455..f117607 100644 --- a/src/tests/receiving/receiveInbound.test.ts +++ b/src/tests/receiving/receiveInbound.test.ts @@ -14,7 +14,8 @@ test.describe('Receive inbound stock movement', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); STOCK_MOVEMENT = await stockMovementService.createInbound({ @@ -23,10 +24,8 @@ test.describe('Receive inbound stock movement', () => { dateRequested, }); - productService.setProduct('1'); - const product = await productService.getProduct(); - productService.setProduct('2'); - const product2 = await productService.getProduct(); + const product = await mainProductService.getProduct(); + const product2 = await otherProductService.getProduct(); await stockMovementService.addItemsToInboundStockMovement( STOCK_MOVEMENT.id, @@ -62,7 +61,7 @@ test.describe('Receive inbound stock movement', () => { receivingPage, supplierLocationService, mainLocationService, - productService, + mainProductService, }) => { await test.step('Go to stock movement show page', async () => { await stockMovementShowPage.goToPage(STOCK_MOVEMENT.id); @@ -116,8 +115,7 @@ test.describe('Receive inbound stock movement', () => { }); await test.step('Assert product in receiving table', async () => { - productService.setProduct('1'); - const item = await productService.getProduct(); + const item = await mainProductService.getProduct(); await receivingPage.receivingStep.table.row(1).getItem(item.name).hover(); await expect(receivingPage.tooltip).toContainText(item.name); }); @@ -173,8 +171,7 @@ test.describe('Receive inbound stock movement', () => { }); await test.step('Assert product in checking table', async () => { - productService.setProduct('1'); - const item = await productService.getProduct(); + const item = await mainProductService.getProduct(); await receivingPage.checkStep.table.row(1).getItem(item.name).hover(); await expect(receivingPage.tooltip).toContainText(item.name); }); diff --git a/src/tests/receiving/receiveInboundWithoutPartialReceiving.test.ts b/src/tests/receiving/receiveInboundWithoutPartialReceiving.test.ts index a5ca82b..a99f753 100644 --- a/src/tests/receiving/receiveInboundWithoutPartialReceiving.test.ts +++ b/src/tests/receiving/receiveInboundWithoutPartialReceiving.test.ts @@ -13,15 +13,14 @@ test.describe('Receive inbound stock movement in location without partial receiv async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, depotLocationService, }) => { const supplierLocation = await supplierLocationService.getLocation(); const depotLocation = await depotLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, @@ -69,7 +68,8 @@ test.describe('Receive inbound stock movement in location without partial receiv receivingPage, supplierLocationService, depotLocationService, - productService, + mainProductService, + otherProductService, authService, }) => { await test.step('Go to stock movement show page', async () => { @@ -121,10 +121,8 @@ test.describe('Receive inbound stock movement in location without partial receiv }); await test.step('Assert product in receiving table', async () => { - productService.setProduct('1'); - const item = await productService.getProduct(); - productService.setProduct('2'); - const item2 = await productService.getProduct(); + const item = await mainProductService.getProduct(); + const item2 = await otherProductService.getProduct(); await receivingPage.receivingStep.table.row(1).getItem(item.name).hover(); await expect(receivingPage.tooltip).toContainText(item.name); await receivingPage.receivingStep.table @@ -168,7 +166,8 @@ test.describe('Receive inbound stock movement in location without partial receiv receivingPage, supplierLocationService, depotLocationService, - productService, + mainProductService, + otherProductService, authService, }) => { await test.step('Go to stock movement show page', async () => { @@ -246,10 +245,8 @@ test.describe('Receive inbound stock movement in location without partial receiv }); await test.step('Assert product in checking table', async () => { - productService.setProduct('1'); - const item = await productService.getProduct(); - productService.setProduct('2'); - const item2 = await productService.getProduct(); + const item = await mainProductService.getProduct(); + const item2 = await otherProductService.getProduct(); await receivingPage.checkStep.table.row(1).getItem(item.name).hover(); await expect(receivingPage.tooltip).toContainText(item.name); await receivingPage.receivingStep.table diff --git a/src/tests/receiving/receiveInboundWithoutPickAndPutawayStock.test.ts b/src/tests/receiving/receiveInboundWithoutPickAndPutawayStock.test.ts index 4c489b8..ebcc55a 100644 --- a/src/tests/receiving/receiveInboundWithoutPickAndPutawayStock.test.ts +++ b/src/tests/receiving/receiveInboundWithoutPickAndPutawayStock.test.ts @@ -13,13 +13,12 @@ test.describe('Receive inbound stock movement in location without pick and putaw async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, noPickAndPutawayStockDepotService, }) => { const supplierLocation = await supplierLocationService.getLocation(); const noPickAndPutawayStockDepot= await noPickAndPutawayStockDepotService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, @@ -101,7 +100,7 @@ test.describe('Receive inbound stock movement in location without pick and putaw await test.step('Go to and assert checking page is visible', async () => { - await receivingPage.nextButton.click(); + await receivingPage.nextButton.click(); await receivingPage.checkStep.isLoaded(); }); diff --git a/src/tests/receiving/receiveToHoldBin.test.ts b/src/tests/receiving/receiveToHoldBin.test.ts index 4844dc0..230772a 100644 --- a/src/tests/receiving/receiveToHoldBin.test.ts +++ b/src/tests/receiving/receiveToHoldBin.test.ts @@ -15,15 +15,14 @@ test.describe('Receive item into hold bin', () => { supplierLocationService, mainLocationService, stockMovementService, - productService, + mainProductService, page, locationListPage, createLocationPage, }) => { const supplierLocation = await supplierLocationService.getLocation(); const mainLocation = await mainLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/receiving/receivingStatusChanges.test.ts b/src/tests/receiving/receivingStatusChanges.test.ts index c08547d..90e9c47 100644 --- a/src/tests/receiving/receivingStatusChanges.test.ts +++ b/src/tests/receiving/receivingStatusChanges.test.ts @@ -14,13 +14,12 @@ test.describe('Status changes on sm view page when receive shipment', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/receiving/receivingStatusChangesWithoutPartialReceiving.test.ts b/src/tests/receiving/receivingStatusChangesWithoutPartialReceiving.test.ts index ee27081..81f7c7a 100644 --- a/src/tests/receiving/receivingStatusChangesWithoutPartialReceiving.test.ts +++ b/src/tests/receiving/receivingStatusChangesWithoutPartialReceiving.test.ts @@ -15,15 +15,14 @@ test.describe('Status changes on sm view page when receive shipment in location async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, depotLocationService, }) => { const supplierLocation = await supplierLocationService.getLocation(); const depotLocation = await depotLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/receiving/rollbackStatusChanges.test.ts b/src/tests/receiving/rollbackStatusChanges.test.ts index 855bc2a..0bf1c0f 100644 --- a/src/tests/receiving/rollbackStatusChanges.test.ts +++ b/src/tests/receiving/rollbackStatusChanges.test.ts @@ -14,13 +14,12 @@ test.describe('Status changes on sm view page when rollback receipts', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/receiving/sortByAlphabeticalOrderAndRemainInputs.test.ts b/src/tests/receiving/sortByAlphabeticalOrderAndRemainInputs.test.ts index de8831a..3bc8364 100644 --- a/src/tests/receiving/sortByAlphabeticalOrderAndRemainInputs.test.ts +++ b/src/tests/receiving/sortByAlphabeticalOrderAndRemainInputs.test.ts @@ -12,13 +12,12 @@ test.describe('Apply sorting by alphabetical order and remain inputs', () => { async ({ supplierLocationService, stockMovementService, - productService, + thirdProductService, + fourthProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('3'); - const PRODUCT_THREE = await productService.getProduct(); - productService.setProduct('4'); - const PRODUCT_FOUR = await productService.getProduct(); + const PRODUCT_THREE = await thirdProductService.getProduct(); + const PRODUCT_FOUR = await fourthProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, @@ -56,7 +55,7 @@ test.describe('Apply sorting by alphabetical order and remain inputs', () => { test('Apply sorting by alphabetical order and remain inputs', async ({ stockMovementShowPage, receivingPage, - productService, + fifthProductService, createInboundPage, }) => { await test.step('Go to stock movement show page', async () => { @@ -80,8 +79,7 @@ test.describe('Apply sorting by alphabetical order and remain inputs', () => { await createInboundPage.addItemsStep.confirmReloadPopup.yesButton.click(); await createInboundPage.addItemsStep.isLoaded(); await createInboundPage.addItemsStep.addLineButton.click(); - productService.setProduct('5'); - const item = await productService.getProduct(); + const item = await fifthProductService.getProduct(); const row = createInboundPage.addItemsStep.table.row(2); await row.productSelect.findAndSelectOption(item.name); await row.quantityField.numberbox.fill('100'); @@ -113,8 +111,7 @@ test.describe('Apply sorting by alphabetical order and remain inputs', () => { }); await test.step('Change ordering to alphabetical and assert order', async () => { - productService.setProduct('5'); - const item = await productService.getProduct(); + const item = await fifthProductService.getProduct(); await receivingPage.receivingStep.table.row(3).getItem(item.name).hover(); await expect(receivingPage.tooltip).toContainText(item.name); await expect(receivingPage.receivingStep.orderSelect).toBeVisible(); @@ -139,8 +136,7 @@ test.describe('Apply sorting by alphabetical order and remain inputs', () => { }); await test.step('Go to check page and assert applied order', async () => { - productService.setProduct('5'); - const item = await productService.getProduct(); + const item = await fifthProductService.getProduct(); await receivingPage.nextButton.click(); await receivingPage.checkStep.isLoaded(); await receivingPage.checkStep.table.row(1).getItem(item.name).hover(); @@ -148,8 +144,7 @@ test.describe('Apply sorting by alphabetical order and remain inputs', () => { }); await test.step('Go back to receive page and change order to shipment', async () => { - productService.setProduct('5'); - const item = await productService.getProduct(); + const item = await fifthProductService.getProduct(); await receivingPage.checkStep.backToEditButton.click(); await receivingPage.receivingStep.isLoaded(); await receivingPage.receivingStep.orderSelect.click(); diff --git a/src/tests/receiving/tableShortcutsInReceiving.test.ts b/src/tests/receiving/tableShortcutsInReceiving.test.ts index 3402be6..047d770 100644 --- a/src/tests/receiving/tableShortcutsInReceiving.test.ts +++ b/src/tests/receiving/tableShortcutsInReceiving.test.ts @@ -13,19 +13,18 @@ test.describe('Use table shortcuts on receiving page', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, + otherProductService, + thirdProductService, + fourthProductService, + fifthProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); - productService.setProduct('1'); - const PRODUCT_ONE = await productService.getProduct(); - productService.setProduct('2'); - const PRODUCT_TWO = await productService.getProduct(); - productService.setProduct('3'); - const PRODUCT_THREE = await productService.getProduct(); - productService.setProduct('4'); - const PRODUCT_FOUR = await productService.getProduct(); - productService.setProduct('5'); - const PRODUCT_FIVE = await productService.getProduct(); + const PRODUCT_ONE = await mainProductService.getProduct(); + const PRODUCT_TWO = await otherProductService.getProduct(); + const PRODUCT_THREE = await thirdProductService.getProduct(); + const PRODUCT_FOUR = await fourthProductService.getProduct(); + const PRODUCT_FIVE = await fifthProductService.getProduct(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, diff --git a/src/tests/receiving/validationsOnDeliverOnDate.test.ts b/src/tests/receiving/validationsOnDeliverOnDate.test.ts index 917c755..1f31e21 100644 --- a/src/tests/receiving/validationsOnDeliverOnDate.test.ts +++ b/src/tests/receiving/validationsOnDeliverOnDate.test.ts @@ -10,15 +10,14 @@ test.describe('Validations on edit Deliver On Date when receiving shipment', () async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); STOCK_MOVEMENT = await stockMovementService.createInbound({ originId: supplierLocation.id, }); - productService.setProduct('1'); - const product = await productService.getProduct(); + const product = await mainProductService.getProduct(); await stockMovementService.addItemsToInboundStockMovement( STOCK_MOVEMENT.id, diff --git a/src/tests/receiving/validationsOnEditAndReceive.test.ts b/src/tests/receiving/validationsOnEditAndReceive.test.ts index 5aadcd2..1c510cc 100644 --- a/src/tests/receiving/validationsOnEditAndReceive.test.ts +++ b/src/tests/receiving/validationsOnEditAndReceive.test.ts @@ -12,7 +12,7 @@ test.describe('Validations on edit and receive inbound stock movement', () => { async ({ supplierLocationService, stockMovementService, - productService, + mainProductService, }) => { const supplierLocation = await supplierLocationService.getLocation(); STOCK_MOVEMENT = await stockMovementService.createInbound({ @@ -21,8 +21,7 @@ test.describe('Validations on edit and receive inbound stock movement', () => { dateRequested, }); - productService.setProduct('1'); - const product = await productService.getProduct(); + const product = await mainProductService.getProduct(); await stockMovementService.addItemsToInboundStockMovement( STOCK_MOVEMENT.id, diff --git a/src/utils/FileIOUtils.ts b/src/utils/FileIOUtils.ts index 4cf04c7..da0913d 100644 --- a/src/utils/FileIOUtils.ts +++ b/src/utils/FileIOUtils.ts @@ -15,36 +15,6 @@ const readFile = (path: string) => { } }; -export const readCsvFile = (path: string): Record[] => { - try { - const rawdata = fs.readFileSync(path, 'utf8'); - const lines = rawdata.trim().split('\n'); - - if (!lines.length) { - return []; - } - - const headers = lines[0].split(','); - return lines.slice(1).map(line => { - const values = line.split(','); - const obj: Record = {}; - headers.forEach((header, i) => { - obj[header.trim()] = values[i]?.trim() ?? ''; - }); - - return obj; - }); - } catch (error) { - if ( - error instanceof Error && - (error as NodeJS.ErrnoException).code === 'ENOENT' - ) { - return []; - } - throw error; - } -}; - const writeToFile = (path: string, data: unknown) => { const parsedData = JSON.stringify(data, null, 2); fs.writeFileSync(path, parsedData, 'utf8'); diff --git a/src/utils/ProductData.ts b/src/utils/ProductData.ts index 2916b1d..567b74d 100644 --- a/src/utils/ProductData.ts +++ b/src/utils/ProductData.ts @@ -10,15 +10,12 @@ class ProductData { private productConfig: ProductConfig; constructor( + productType: keyof AppConfig['products'], request: APIRequestContext ) { this.productService = new ProductService(request); - this.productConfig = AppConfig.instance.products['1']; - } - - setProduct(productCode: string) { - this.productConfig = AppConfig.instance.products[productCode]; + this.productConfig = AppConfig.instance.products[productType]; } async getProduct() { diff --git a/src/utils/ServiceUtils.ts b/src/utils/ServiceUtils.ts index ae9745d..b626eb1 100644 --- a/src/utils/ServiceUtils.ts +++ b/src/utils/ServiceUtils.ts @@ -18,19 +18,3 @@ export function unflatten(obj: object) { return result; } - -export function jsonToCsv(data: Record[]): string { - if (!Array.isArray(data) || !data.length) { - throw new Error('Input JSON array is empty'); - } - - const headers = Object.keys(data[0]); - const csvRows = [ - headers.join(','), - ...data.map(row => headers.map(header => - JSON.stringify(row[header] ?? '')).join(',') - ), - ]; - - return csvRows.join('\n'); -}