Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CoryKleinjanCACI committed Jan 31, 2025
1 parent d750297 commit 38c40f6
Show file tree
Hide file tree
Showing 3 changed files with 315 additions and 0 deletions.
191 changes: 191 additions & 0 deletions pkg/testdatagen/testharness/make_move.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,197 @@ func MakeHHGMoveWithIntlCratingServiceItemsTOO(appCtx appcontext.AppContext) mod
return *newmove
}

// MakeHHGMoveWithIntlShuttleServiceItemsTOO is a function
// that creates an HHG move with international service items
// from the Prime for review by the TOO
func MakeHHGMoveWithIntlShuttleServiceItemsTOO(appCtx appcontext.AppContext) models.Move {
userUploader := newUserUploader(appCtx)
primeUploader := newPrimeUploader(appCtx)
userInfo := newUserInfo("customer")

user := factory.BuildUser(appCtx.DB(), []factory.Customization{
{
Model: models.User{
OktaEmail: userInfo.email,
Active: true,
},
},
}, nil)
customer := factory.BuildExtendedServiceMember(appCtx.DB(), []factory.Customization{
{
Model: models.ServiceMember{
PersonalEmail: &userInfo.email,
FirstName: &userInfo.firstName,
LastName: &userInfo.lastName,
CacValidated: true,
},
},
{
Model: user,
LinkOnly: true,
},
}, nil)
dependentsAuthorized := true
entitlements := factory.BuildEntitlement(appCtx.DB(), []factory.Customization{
{
Model: models.Entitlement{
DependentsAuthorized: &dependentsAuthorized,
},
},
}, nil)
orders := factory.BuildOrder(appCtx.DB(), []factory.Customization{
{
Model: customer,
LinkOnly: true,
},
{
Model: entitlements,
LinkOnly: true,
},
{
Model: models.UserUpload{},
ExtendedParams: &factory.UserUploadExtendedParams{
UserUploader: userUploader,
AppContext: appCtx,
},
},
}, nil)
mto := factory.BuildMove(appCtx.DB(), []factory.Customization{
{
Model: orders,
LinkOnly: true,
},
{
Model: models.Move{
Status: models.MoveStatusSUBMITTED,
},
},
}, nil)
estimatedWeight := unit.Pound(1400)
actualWeight := unit.Pound(2000)
actualPickupDate := time.Now().AddDate(0, 0, 1)

MTOShipment := factory.BuildMTOShipment(appCtx.DB(), []factory.Customization{
{
Model: models.MTOShipment{
PrimeEstimatedWeight: &estimatedWeight,
PrimeActualWeight: &actualWeight,
ShipmentType: models.MTOShipmentTypeHHG,
Status: models.MTOShipmentStatusSubmitted,
ActualPickupDate: &actualPickupDate,
},
},
{
Model: mto,
LinkOnly: true,
},
}, nil)

agentUserInfo := newUserInfo("agent")
factory.BuildMTOAgent(appCtx.DB(), []factory.Customization{
{
Model: MTOShipment,
LinkOnly: true,
},
{
Model: models.MTOAgent{
FirstName: &agentUserInfo.firstName,
LastName: &agentUserInfo.lastName,
Email: &agentUserInfo.email,
MTOAgentType: models.MTOAgentReleasing,
},
},
}, nil)

paymentRequest := factory.BuildPaymentRequest(appCtx.DB(), []factory.Customization{
{
Model: models.PaymentRequest{
IsFinal: false,
Status: models.PaymentRequestStatusPending,
},
},
{
Model: mto,
LinkOnly: true,
},
}, nil)

_ = factory.BuildMTOServiceItem(appCtx.DB(), []factory.Customization{
{
Model: mto,
LinkOnly: true,
},
{
Model: MTOShipment,
LinkOnly: true,
},
{
Model: models.ReService{
ID: uuid.FromStringOrNil("22fc07ed-be15-4f50-b941-cbd38153b378"), // IDSHUT - International Destination Shuttle
},
},
}, nil)

_ = factory.BuildMTOServiceItem(appCtx.DB(), []factory.Customization{
{
Model: mto,
LinkOnly: true,
},
{
Model: MTOShipment,
LinkOnly: true,
},
{
Model: models.ReService{
ID: uuid.FromStringOrNil("624a97c5-dfbf-4da9-a6e9-526b4f95af8d"), // IOSHUT - International Origin Shuttle
},
},
}, nil)

factory.BuildPrimeUpload(appCtx.DB(), []factory.Customization{
{
Model: paymentRequest,
LinkOnly: true,
},
}, nil)
posImage := factory.BuildProofOfServiceDoc(appCtx.DB(), []factory.Customization{
{
Model: paymentRequest,
LinkOnly: true,
},
}, nil)
primeContractor := uuid.FromStringOrNil("5db13bb4-6d29-4bdb-bc81-262f4513ecf6")

// Creates custom test.jpg prime upload
file := testdatagen.Fixture("test.jpg")
_, verrs, err := primeUploader.CreatePrimeUploadForDocument(appCtx, &posImage.ID, primeContractor, uploader.File{File: file}, uploader.AllowedTypesPaymentRequest)
if verrs.HasAny() || err != nil {
appCtx.Logger().Error("errors encountered saving test.jpg prime upload", zap.Error(err))
}

// Creates custom test.png prime upload
file = testdatagen.Fixture("test.png")
_, verrs, err = primeUploader.CreatePrimeUploadForDocument(appCtx, &posImage.ID, primeContractor, uploader.File{File: file}, uploader.AllowedTypesPaymentRequest)
if verrs.HasAny() || err != nil {
appCtx.Logger().Error("errors encountered saving test.png prime upload", zap.Error(err))
}

// re-fetch the move so that we ensure we have exactly what is in
// the db
newmove, err := models.FetchMove(appCtx.DB(), &auth.Session{}, mto.ID)
if err != nil {
log.Panic(fmt.Errorf("failed to fetch move: %w", err))
}

// load payment requests so tests can confirm
err = appCtx.DB().Load(newmove, "PaymentRequests")
if err != nil {
log.Panic(fmt.Errorf("failed to fetch move payment requestse: %w", err))
}

return *newmove
}

// MakeHHGMoveForTOOAfterActualPickupDate is a function
// that creates an HHG move with an actual pickup date in the past for diversion testing
// copied almost verbatim from e2ebasic createHHGMoveWithServiceItemsAndPaymentRequestsAndFiles
Expand Down
116 changes: 116 additions & 0 deletions playwright/tests/office/txo/tooFlowsInternational.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,121 @@ test.describe('TOO user', () => {

await expect(getServiceItemsInTable(requestedServiceItemsTable)).toHaveCount(requestedServiceItemCount - 1);
});

test.skip(alaskaEnabled === 'false', 'Skip if Alaska FF is disabled.');
test('is able to approve and reject international shuttle service items', async ({ officePage, page }) => {
const move = await officePage.testHarness.buildHHGMoveWithIntlShuttleServiceItemsTOO();
await officePage.signInAsNewTOOUser();
tooFlowPage = new TooFlowPage(officePage, move);
await tooFlowPage.waitForLoading();
await officePage.tooNavigateToMove(tooFlowPage.moveLocator);

// Edit the shipment address to AK
await page.locator('[data-testid="ShipmentContainer"] .usa-button').first().click();
await page.locator('input[id="delivery.address-location-input"]').fill('99505');
await page.keyboard.press('Enter');

await page.getByRole('button', { name: 'Save' }).click();
await tooFlowPage.waitForPage.moveDetails();

await tooFlowPage.waitForLoading();
await tooFlowPage.approveAllShipments();

await page.getByTestId('MoveTaskOrder-Tab').click();
await tooFlowPage.waitForLoading();
expect(page.url()).toContain(`/moves/${tooFlowPage.moveLocator}/mto`);

// Wait for page to load to deal with flakiness resulting from Service Item tables loading
await tooFlowPage.page.waitForLoadState();

// Move Task Order page
await expect(page.getByTestId('ShipmentContainer')).toHaveCount(1);

/**
* @function
* @description This test approves and rejects service items, which moves them from one table to another
* and expects the counts of each table to increment/decrement by one item each time
* This function gets the service items for a given table to help count them
* @param {import("playwright-core").Locator} table
* @returns {import("playwright-core").Locator}
*/
const getServiceItemsInTable = (table) => {
return table.getByRole('rowgroup').nth(1).getByRole('row');
};

const requestedServiceItemsTable = page.getByTestId('RequestedServiceItemsTable');
let requestedServiceItemCount = await getServiceItemsInTable(requestedServiceItemsTable).count();
const approvedServiceItemsTable = page.getByTestId('ApprovedServiceItemsTable');
let approvedServiceItemCount = await getServiceItemsInTable(approvedServiceItemsTable).count();
const rejectedServiceItemsTable = page.getByTestId('RejectedServiceItemsTable');
let rejectedServiceItemCount = await getServiceItemsInTable(rejectedServiceItemsTable).count();

await expect(page.getByText('Requested Service Items', { exact: false })).toBeVisible();
await expect(getServiceItemsInTable(requestedServiceItemsTable).nth(1)).toBeVisible();

await expect(page.getByTestId('modal')).not.toBeVisible();

// Approve a requested service item
expect((await getServiceItemsInTable(requestedServiceItemsTable).count()) > 0);
// ICRT
await requestedServiceItemsTable.getByRole('button', { name: 'Accept' }).first().click();
await tooFlowPage.waitForLoading();

await expect(getServiceItemsInTable(approvedServiceItemsTable)).toHaveCount(approvedServiceItemCount + 1);
approvedServiceItemCount = await getServiceItemsInTable(approvedServiceItemsTable).count();

await expect(getServiceItemsInTable(requestedServiceItemsTable)).toHaveCount(requestedServiceItemCount - 1);
requestedServiceItemCount = await getServiceItemsInTable(requestedServiceItemsTable).count();

// IUCRT
await requestedServiceItemsTable.getByRole('button', { name: 'Accept' }).first().click();
await tooFlowPage.waitForLoading();

await expect(getServiceItemsInTable(approvedServiceItemsTable)).toHaveCount(approvedServiceItemCount + 1);
approvedServiceItemCount = await getServiceItemsInTable(approvedServiceItemsTable).count();

await expect(getServiceItemsInTable(requestedServiceItemsTable)).toHaveCount(requestedServiceItemCount - 1);
requestedServiceItemCount = await getServiceItemsInTable(requestedServiceItemsTable).count();

// Reject a requested service item
await expect(page.getByText('Requested Service Items', { exact: false })).toBeVisible();
expect((await getServiceItemsInTable(requestedServiceItemsTable).count()) > 0);
// ICRT
await requestedServiceItemsTable.getByRole('button', { name: 'Reject' }).first().click();

await expect(page.getByTestId('modal')).toBeVisible();
let modal = page.getByTestId('modal');

await expect(modal.getByRole('button', { name: 'Submit' })).toBeDisabled();
await modal.getByRole('textbox').fill('my very valid reason');
await modal.getByRole('button', { name: 'Submit' }).click();

await expect(page.getByTestId('modal')).not.toBeVisible();

await expect(page.getByText('Rejected Service Items', { exact: false })).toBeVisible();
await expect(getServiceItemsInTable(rejectedServiceItemsTable)).toHaveCount(rejectedServiceItemCount + 1);
rejectedServiceItemCount = await getServiceItemsInTable(rejectedServiceItemsTable).count();

await expect(getServiceItemsInTable(requestedServiceItemsTable)).toHaveCount(requestedServiceItemCount - 1);
requestedServiceItemCount = await getServiceItemsInTable(requestedServiceItemsTable).count();

// IUCRT
await requestedServiceItemsTable.getByRole('button', { name: 'Reject' }).first().click();

await expect(page.getByTestId('modal')).toBeVisible();
modal = page.getByTestId('modal');

await expect(modal.getByRole('button', { name: 'Submit' })).toBeDisabled();
await modal.getByRole('textbox').fill('my very valid reason');
await modal.getByRole('button', { name: 'Submit' }).click();

await expect(page.getByTestId('modal')).not.toBeVisible();

await expect(page.getByText('Rejected Service Items', { exact: false })).toBeVisible();
await expect(getServiceItemsInTable(rejectedServiceItemsTable)).toHaveCount(rejectedServiceItemCount + 1);
rejectedServiceItemCount = await getServiceItemsInTable(rejectedServiceItemsTable).count();

await expect(getServiceItemsInTable(requestedServiceItemsTable)).toHaveCount(requestedServiceItemCount - 1);
});
});
});
8 changes: 8 additions & 0 deletions playwright/tests/utils/testharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ export class TestHarness {
return this.buildDefault('HHGMoveWithIntlCratingServiceItemsTOO');
}

/**
* Use testharness to build hhg move with international crating service items for TOO
* @returns {Promise<Move>}
*/
async buildHHGMoveWithIntlShuttleServiceItemsTOO() {
return this.buildDefault('HHGMoveWithIntlShuttleServiceItemsTOO');
}

/**
* Use testharness to build hhg move for TOO with actualPickupDate in the past
* @returns {Promise<Move>}
Expand Down

0 comments on commit 38c40f6

Please sign in to comment.