Skip to content

Commit

Permalink
delete some tests that are failing
Browse files Browse the repository at this point in the history
- represent behavior we don't want anymore
- uses mocks when NOT necessary, which makes them much more difficult to
  maintain
  • Loading branch information
williamstein committed Dec 11, 2024
1 parent 7dfa59a commit ffa11da
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 86 deletions.
86 changes: 0 additions & 86 deletions src/packages/server/purchases/shopping-cart-checkout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,92 +52,6 @@ afterEach(() => {
});

describe("shopping-cart-checkout", () => {
describe("#shoppingCartCheckout", () => {
const account_id = uuid();
const testCheckout = {
account_id,
};

const testPoolClient = {
query: jest.fn(),
release: jest.fn(),
};

it("uses account balance when available", async () => {
// Arrange
//
jest.spyOn(sut, "getShoppingCartCheckoutParams").mockReturnValue(
Promise.resolve({
balance: NaN,
minPayment: NaN,
amountDue: 0.0,
chargeAmount: 0.0,
total: NaN,
minBalance: NaN,
minimumPaymentCharge: NaN,
cureAmount: NaN,
cart: [],
}),
);

mockTransactionClient.mockImplementation(() =>
Promise.resolve(testPoolClient as any),
);

// Act
//
await sut.shoppingCartCheckout({
...testCheckout,
});

// Assert
//
expect(testPoolClient.query).toHaveBeenCalledWith("COMMIT");
expect(testPoolClient.release).toHaveBeenCalled();
});

it("bails on the shopping cart transaction when shopping cart purchase fails", async () => {
// Arrange
//
jest.spyOn(sut, "getShoppingCartCheckoutParams").mockReturnValue(
Promise.resolve({
balance: NaN,
minPayment: NaN,
amountDue: NaN,
chargeAmount: 2,
total: NaN,
minBalance: NaN,
minimumPaymentCharge: NaN,
cureAmount: NaN,
cart: [
{
foo: "bar",
},
],
}),
);

const ackbError = new Error(
"Insufficient credit on your account to complete the purchase (you need $2.00). Please refresh your browser and try again or contact support.",
);

mockTransactionClient.mockImplementation(() =>
Promise.resolve(testPoolClient as any),
);
mockPurchaseShoppingCartItem.mockImplementation(() => {
throw ackbError;
});

// Act
//
await expect(
sut.shoppingCartCheckout({
...testCheckout,
}),
).rejects.toThrow(ackbError);
});
});

describe("#getCheckoutCart", () => {
const account_id = uuid();

Expand Down
1 change: 1 addition & 0 deletions src/packages/server/purchases/shopping-cart-checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export async function getCheckoutCart(
processing,
cart_ids,
});
console.log({ cart });
cart = cart.filter(
filter ??
((item) =>
Expand Down
1 change: 1 addition & 0 deletions src/packages/server/shopping/cart/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default async function getCart({
}
const { rows } = await pool.query(query, params);
await ensureValidLicenseIntervals(rows, pool);
console.log({ query, rows });
return rows as any as Item[];
}

Expand Down

0 comments on commit ffa11da

Please sign in to comment.