Test - PaymentService - Refactored payMoney test
Refactored the payMoney test to work with 3.8. The output is no longer returned, but updated by reference.
This commit is contained in:
parent
fe7ef06c6c
commit
7d3eaf735a
@ -71,48 +71,50 @@ describe("PaymentService", () =>
|
|||||||
|
|
||||||
const itemEventRouterResponse = {
|
const itemEventRouterResponse = {
|
||||||
warnings: [],
|
warnings: [],
|
||||||
profileChanges: { sessionID: { _id: sessionID, items: { new: [], change: [], del: [] } } },
|
profileChanges: { [sessionID]: { _id: sessionID, items: { new: [], change: [], del: [] } } },
|
||||||
} as unknown as IItemEventRouterResponse;
|
} as unknown as IItemEventRouterResponse;
|
||||||
|
|
||||||
// Mock the logger debug method to return void.
|
// Mock the logger debug method to return void.
|
||||||
vi.spyOn((paymentService as any).logger, "debug").mockImplementation(() =>
|
vi.spyOn((paymentService as any).logger, "debug").mockResolvedValue(undefined);
|
||||||
{});
|
|
||||||
|
|
||||||
// Mock the trader helper to return a trader with the currency of Roubles.
|
// Mock the trader helper to return a trader with the currency of Roubles.
|
||||||
const traderHelperGetTraderSpy = vi.spyOn((paymentService as any).traderHelper, "getTrader")
|
const getTraderSpy = vi.spyOn((paymentService as any).traderHelper, "getTrader").mockReturnValue(
|
||||||
.mockReturnValue({ tid: traderId, currency: "RUB" } as unknown as ITraderBase);
|
{ tid: traderId, currency: "RUB" } as unknown as ITraderBase,
|
||||||
|
);
|
||||||
|
|
||||||
// Mock the addPaymentToOutput method to subtract the item cost from the money stack.
|
// Mock the addPaymentToOutput method to subtract the item cost from the money stack.
|
||||||
const addPaymentToOutputSpy = vi.spyOn(paymentService as any, "addPaymentToOutput").mockImplementation(() =>
|
const addPaymentToOutputSpy = vi.spyOn(paymentService as any, "addPaymentToOutput").mockImplementation(
|
||||||
|
(
|
||||||
|
pmcData: IPmcData,
|
||||||
|
currencyTpl: string,
|
||||||
|
amountToPay: number,
|
||||||
|
sessionIdentifier: string,
|
||||||
|
output: IItemEventRouterResponse,
|
||||||
|
) =>
|
||||||
{
|
{
|
||||||
moneyItem.upd.StackObjectsCount -= costAmount;
|
moneyItem.upd.StackObjectsCount -= costAmount;
|
||||||
return { warnings: [], profileChanges: { [sessionID]: { items: { change: [moneyItem] } } } };
|
output.profileChanges[sessionIdentifier].items.change.push(moneyItem);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Mock the traderHelper lvlUp method to return void.
|
// Mock the traderHelper lvlUp method to return void.
|
||||||
const traderHelperLvlUpSpy = vi.spyOn((paymentService as any).traderHelper, "lvlUp").mockImplementation(
|
const lvlUpSpy = vi.spyOn((paymentService as any).traderHelper, "lvlUp").mockResolvedValue(undefined);
|
||||||
() =>
|
|
||||||
{},
|
|
||||||
);
|
|
||||||
|
|
||||||
const output = paymentService.payMoney(
|
paymentService.payMoney(pmcData, processBuyTradeRequestData, sessionID, itemEventRouterResponse);
|
||||||
pmcData,
|
|
||||||
processBuyTradeRequestData,
|
|
||||||
sessionID,
|
|
||||||
itemEventRouterResponse,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Check for absence of output warnings.
|
// Check for absence of output warnings.
|
||||||
expect(output.warnings).toHaveLength(0);
|
expect(itemEventRouterResponse.warnings).toHaveLength(0);
|
||||||
|
|
||||||
// Check that the currency change was correctly handled.
|
// Check that the currency change was correctly handled.
|
||||||
expect(output.profileChanges[sessionID].items.change).toHaveLength(1);
|
expect(itemEventRouterResponse.profileChanges[sessionID].items.change).toHaveLength(1);
|
||||||
expect(output.profileChanges[sessionID].items.change[0]._id).toBe(costItemId);
|
expect(itemEventRouterResponse.profileChanges[sessionID].items.change[0]._id).toBe(costItemId);
|
||||||
expect(output.profileChanges[sessionID].items.change[0]._tpl).toBe(costItemTpl);
|
expect(itemEventRouterResponse.profileChanges[sessionID].items.change[0]._tpl).toBe(costItemTpl);
|
||||||
expect(output.profileChanges[sessionID].items.change[0].upd.StackObjectsCount).toBe(costAmount * 3);
|
expect(itemEventRouterResponse.profileChanges[sessionID].items.change[0].upd.StackObjectsCount).toBe(
|
||||||
|
costAmount * 3,
|
||||||
|
);
|
||||||
|
|
||||||
// Check if mocked methods were called as expected.
|
// Check if mocked methods were called as expected.
|
||||||
expect(traderHelperGetTraderSpy).toBeCalledTimes(1);
|
expect(getTraderSpy).toBeCalledTimes(1);
|
||||||
expect(addPaymentToOutputSpy).toBeCalledWith(
|
expect(addPaymentToOutputSpy).toBeCalledWith(
|
||||||
expect.anything(),
|
expect.anything(),
|
||||||
costItemTpl,
|
costItemTpl,
|
||||||
@ -120,7 +122,7 @@ describe("PaymentService", () =>
|
|||||||
sessionID,
|
sessionID,
|
||||||
expect.anything(),
|
expect.anything(),
|
||||||
);
|
);
|
||||||
expect(traderHelperLvlUpSpy).toBeCalledTimes(1);
|
expect(lvlUpSpy).toBeCalledTimes(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user