Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/api/StockMovementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,39 @@ class StockMovementService extends BaseServiceModel {
}
}

async rollbackLastShipmentStatus(id: string) {
// request.delete does not throw on HTTP error statuses, and a swallowed
// failed rollback makes the follow-up delete fail with a status error
const apiResponse = await this.request.delete(STOCK_MOVEMENT_STATUS(id));
if (!apiResponse.ok()) {
throw new Error(
`Problem rolling back shipment status of stock movement ${id}: ${apiResponse.status()}`
);
}
}

/*
Rolls back shipment events (received, shipped) one by one until the
shipment reaches the given status, e.g. back to PENDING so the stock
movement can be deleted regardless of the status it reached in the test.
*/
async rollbackShipmentToStatus(id: string, status: string) {
// a shipment accumulates one shipped event plus one receipt event per
// (partial) receipt, so a sane shipment needs just a few rollbacks
const maxRollbacks = 10;
for (let i = 0; i < maxRollbacks; i++) {
const { data } = await this.getStockMovement(id);
const shipmentStatus = data?.associations?.shipment?.status;
if (!shipmentStatus || shipmentStatus === status) {
return;
}
await this.rollbackLastShipmentStatus(id);
}
throw new Error(
`Shipment of stock movement ${id} did not get back to ${status} after ${maxRollbacks} rollbacks`
);
}

async getStockMovement(
id: string
): Promise<ApiResponse<StockMovementResponse>> {
Expand Down
17 changes: 3 additions & 14 deletions src/tests/putaway/addCommentToPutaway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Product } from '@/generated/ProductCodes.generated';
import { StockMovementResponse } from '@/types';
import RefreshCachesUtils from '@/utils/RefreshCaches';
import {
deleteReceivedShipment,
deleteShipment,
getShipmentId,
getShipmentItemId,
} from '@/utils/shipmentUtils';
Expand Down Expand Up @@ -57,13 +57,7 @@ test.describe('Add comment to Putaway', () => {
);

test.afterEach(
async ({
stockMovementShowPage,
stockMovementService,
navbar,
transactionListPage,
oldViewShipmentPage,
}) => {
async ({ stockMovementService, navbar, transactionListPage }) => {
await navbar.configurationButton.click();
await navbar.transactions.click();
await transactionListPage.table.row(1).actionsButton.click();
Expand All @@ -73,12 +67,7 @@ test.describe('Add comment to Putaway', () => {
await transactionListPage.table.deleteButton.click();
await expect(transactionListPage.successMessage).toBeVisible();

await deleteReceivedShipment({
stockMovementShowPage,
oldViewShipmentPage,
stockMovementService,
STOCK_MOVEMENT,
});
await deleteShipment({ stockMovementService, STOCK_MOVEMENT });
}
);

Expand Down
17 changes: 3 additions & 14 deletions src/tests/putaway/assertAttemptToEditCompletedPutaway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Product } from '@/generated/ProductCodes.generated';
import { StockMovementResponse } from '@/types';
import RefreshCachesUtils from '@/utils/RefreshCaches';
import {
deleteReceivedShipment,
deleteShipment,
getShipmentId,
getShipmentItemId,
} from '@/utils/shipmentUtils';
Expand Down Expand Up @@ -57,13 +57,7 @@ test.describe('Assert attempt to edit completed putaway', () => {
);

test.afterEach(
async ({
stockMovementShowPage,
stockMovementService,
navbar,
transactionListPage,
oldViewShipmentPage,
}) => {
async ({ stockMovementService, navbar, transactionListPage }) => {
await navbar.configurationButton.click();
await navbar.transactions.click();
await transactionListPage.table.row(1).actionsButton.click();
Expand All @@ -73,12 +67,7 @@ test.describe('Assert attempt to edit completed putaway', () => {
await transactionListPage.table.deleteButton.click();
await expect(transactionListPage.successMessage).toBeVisible();

await deleteReceivedShipment({
stockMovementShowPage,
oldViewShipmentPage,
stockMovementService,
STOCK_MOVEMENT,
});
await deleteShipment({ stockMovementService, STOCK_MOVEMENT });
}
);

Expand Down
17 changes: 3 additions & 14 deletions src/tests/putaway/assertPutawayDetailsPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { deleteFile, writeBufferToFile } from '@/utils/FileIOUtils';
import { pdfContainsValues } from '@/utils/pdfUtils';
import RefreshCachesUtils from '@/utils/RefreshCaches';
import {
deleteReceivedShipment,
deleteShipment,
getShipmentId,
getShipmentItemId,
} from '@/utils/shipmentUtils';
Expand Down Expand Up @@ -65,13 +65,7 @@ test.describe('Assert putaway details page', () => {
);

test.afterEach(
async ({
stockMovementShowPage,
stockMovementService,
navbar,
transactionListPage,
oldViewShipmentPage,
}) => {
async ({ stockMovementService, navbar, transactionListPage }) => {
await navbar.configurationButton.click();
await navbar.transactions.click();
await transactionListPage.table.row(1).actionsButton.click();
Expand All @@ -81,12 +75,7 @@ test.describe('Assert putaway details page', () => {
await transactionListPage.table.deleteButton.click();
await expect(transactionListPage.successMessage).toBeVisible();

await deleteReceivedShipment({
stockMovementShowPage,
oldViewShipmentPage,
stockMovementService,
STOCK_MOVEMENT,
});
await deleteShipment({ stockMovementService, STOCK_MOVEMENT });

while (downloadedFilePaths.length) {
deleteFile(downloadedFilePaths.pop() as string);
Expand Down
18 changes: 4 additions & 14 deletions src/tests/putaway/assertReceivingBinsOnCreatePutawayPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { StockMovementResponse } from '@/types';
import { formatDate, getDateByOffset } from '@/utils/DateUtils';
import RefreshCachesUtils from '@/utils/RefreshCaches';
import {
deleteReceivedShipment,
deleteShipment,
getShipmentId,
getShipmentItemId,
} from '@/utils/shipmentUtils';
Expand Down Expand Up @@ -123,29 +123,19 @@ test.describe('Assert receiving bin on create putaway page', () => {
);

test.afterEach(
async ({
stockMovementShowPage,
stockMovementService,
navbar,
transactionListPage,
oldViewShipmentPage,
}) => {
async ({ stockMovementService, navbar, transactionListPage }) => {
await navbar.configurationButton.click();
await navbar.transactions.click();
for (let n = 1; n < 4; n++) {
await transactionListPage.deleteTransaction(1);
}

await deleteReceivedShipment({
stockMovementShowPage,
oldViewShipmentPage,
await deleteShipment({
stockMovementService,
STOCK_MOVEMENT: PRIMARY_STOCK_MOVEMENT,
});

await deleteReceivedShipment({
stockMovementShowPage,
oldViewShipmentPage,
await deleteShipment({
stockMovementService,
STOCK_MOVEMENT: SECONDARY_STOCK_MOVEMENT,
});
Expand Down
11 changes: 2 additions & 9 deletions src/tests/putaway/assertZonesInPutaways.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Product } from '@/generated/ProductCodes.generated';
import { ProductResponse, StockMovementResponse } from '@/types';
import RefreshCachesUtils from '@/utils/RefreshCaches';
import {
deleteReceivedShipment,
deleteShipment,
getShipmentId,
getShipmentItemId,
} from '@/utils/shipmentUtils';
Expand Down Expand Up @@ -141,11 +141,9 @@ test.describe('Assert zones on putaway pages', () => {

test.afterEach(
async ({
stockMovementShowPage,
stockMovementService,
navbar,
transactionListPage,
oldViewShipmentPage,
productService,
productShowPage,
productEditPage,
Expand All @@ -160,12 +158,7 @@ test.describe('Assert zones on putaway pages', () => {
for (let n = 1; n < 4; n++) {
await transactionListPage.deleteTransaction(1);
}
await deleteReceivedShipment({
stockMovementShowPage,
oldViewShipmentPage,
stockMovementService,
STOCK_MOVEMENT,
});
await deleteShipment({ stockMovementService, STOCK_MOVEMENT });
const product = await productService.getProduct(Product.FOUR);

await test.step('Delete inventory level', async () => {
Expand Down
40 changes: 14 additions & 26 deletions src/tests/putaway/changeLocationOnCreatePutawayPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Product } from '@/generated/ProductCodes.generated';
import { StockMovementResponse } from '@/types';
import RefreshCachesUtils from '@/utils/RefreshCaches';
import {
deleteReceivedShipment,
deleteShipment,
getShipmentId,
getShipmentItemId,
} from '@/utils/shipmentUtils';
Expand Down Expand Up @@ -58,32 +58,20 @@ test.describe('Change location on putaway create page and list pages', () => {
}
);

test.afterEach(
async ({
stockMovementShowPage,
stockMovementService,
putawayListPage,
oldViewShipmentPage,
}) => {
// the received shipment must be cleaned up even when the test fails
// before the putaway is created
if (putawayOrderIdentifier) {
await putawayListPage.goToPage();
await putawayListPage.table
.rowByOrderNumber(`${putawayOrderIdentifier}`.toString().trim())
.actionsButton.click();
await putawayListPage.table.clickDeleteOrderButton(1);
await putawayListPage.emptyPutawayList.isVisible();
}

await deleteReceivedShipment({
stockMovementShowPage,
oldViewShipmentPage,
stockMovementService,
STOCK_MOVEMENT,
});
test.afterEach(async ({ stockMovementService, putawayListPage }) => {
// the received shipment must be cleaned up even when the test fails
// before the putaway is created
if (putawayOrderIdentifier) {
await putawayListPage.goToPage();
await putawayListPage.table
.rowByOrderNumber(`${putawayOrderIdentifier}`.toString().trim())
.actionsButton.click();
await putawayListPage.table.clickDeleteOrderButton(1);
await putawayListPage.emptyPutawayList.isVisible();
}
);

await deleteShipment({ stockMovementService, STOCK_MOVEMENT });
});

test('Change location on putaway create page and list page', async ({
stockMovementShowPage,
Expand Down
17 changes: 3 additions & 14 deletions src/tests/putaway/createMoreThan1PutawayForTheSameItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Product } from '@/generated/ProductCodes.generated';
import { StockMovementResponse } from '@/types';
import RefreshCachesUtils from '@/utils/RefreshCaches';
import {
deleteReceivedShipment,
deleteShipment,
getShipmentId,
getShipmentItemId,
} from '@/utils/shipmentUtils';
Expand Down Expand Up @@ -57,13 +57,7 @@ test.describe('Create more than 1 putaway from the same item', () => {
);

test.afterEach(
async ({
stockMovementShowPage,
stockMovementService,
navbar,
transactionListPage,
oldViewShipmentPage,
}) => {
async ({ stockMovementService, navbar, transactionListPage }) => {
await navbar.configurationButton.click();
await navbar.transactions.click();
await transactionListPage.table.row(1).actionsButton.click();
Expand All @@ -73,12 +67,7 @@ test.describe('Create more than 1 putaway from the same item', () => {
await transactionListPage.table.deleteButton.click();
await expect(transactionListPage.successMessage).toBeVisible();

await deleteReceivedShipment({
stockMovementShowPage,
oldViewShipmentPage,
stockMovementService,
STOCK_MOVEMENT,
});
await deleteShipment({ stockMovementService, STOCK_MOVEMENT });
}
);

Expand Down
17 changes: 3 additions & 14 deletions src/tests/putaway/createPutaway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Product } from '@/generated/ProductCodes.generated';
import { StockMovementResponse } from '@/types';
import RefreshCachesUtils from '@/utils/RefreshCaches';
import {
deleteReceivedShipment,
deleteShipment,
getShipmentId,
getShipmentItemId,
} from '@/utils/shipmentUtils';
Expand Down Expand Up @@ -57,13 +57,7 @@ test.describe('Putaway received inbound shipment', () => {
);

test.afterEach(
async ({
stockMovementShowPage,
stockMovementService,
navbar,
transactionListPage,
oldViewShipmentPage,
}) => {
async ({ stockMovementService, navbar, transactionListPage }) => {
await navbar.configurationButton.click();
await navbar.transactions.click();
await transactionListPage.table.row(1).actionsButton.click();
Expand All @@ -73,12 +67,7 @@ test.describe('Putaway received inbound shipment', () => {
await transactionListPage.table.deleteButton.click();
await expect(transactionListPage.successMessage).toBeVisible();

await deleteReceivedShipment({
stockMovementShowPage,
oldViewShipmentPage,
stockMovementService,
STOCK_MOVEMENT,
});
await deleteShipment({ stockMovementService, STOCK_MOVEMENT });
}
);

Expand Down
17 changes: 3 additions & 14 deletions src/tests/putaway/deleteItemsFromPutaway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Product } from '@/generated/ProductCodes.generated';
import { ProductResponse, StockMovementResponse } from '@/types';
import RefreshCachesUtils from '@/utils/RefreshCaches';
import {
deleteReceivedShipment,
deleteShipment,
getShipmentId,
getShipmentItemId,
} from '@/utils/shipmentUtils';
Expand Down Expand Up @@ -71,24 +71,13 @@ test.describe('Delete items from putaway', () => {
);

test.afterEach(
async ({
stockMovementShowPage,
stockMovementService,
navbar,
transactionListPage,
oldViewShipmentPage,
}) => {
async ({ stockMovementService, navbar, transactionListPage }) => {
await navbar.configurationButton.click();
await navbar.transactions.click();
for (let n = 1; n < 3; n++) {
await transactionListPage.deleteTransaction(1);
}
await deleteReceivedShipment({
stockMovementShowPage,
oldViewShipmentPage,
stockMovementService,
STOCK_MOVEMENT,
});
await deleteShipment({ stockMovementService, STOCK_MOVEMENT });
}
);

Expand Down
Loading
Loading