Skip to content

Commit

Permalink
add tests for default precision config
Browse files Browse the repository at this point in the history
  • Loading branch information
ddadaal committed Aug 13, 2024
1 parent 1a02796 commit fa899eb
Show file tree
Hide file tree
Showing 5 changed files with 995 additions and 38 deletions.
4 changes: 2 additions & 2 deletions apps/mis-server/config/mis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ periodicSyncUserAccountBlockStatus:
enabled: false

# 为保证测试用例通过,消费精度和最小消费金额改为原有值
jobChargeDecimalPrecision: 3
jobMinCharge: 0
# jobChargeDecimalPrecision: 3
# jobMinCharge: 0
30 changes: 24 additions & 6 deletions apps/mis-server/tests/job/billingItems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* See the Mulan PSL v2 for more details.
*/

import { after, before } from "node:test";

Check warning on line 13 in apps/mis-server/tests/job/billingItems.test.ts

View workflow job for this annotation

GitHub Actions / Test and version packages

'after' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 13 in apps/mis-server/tests/job/billingItems.test.ts

View workflow job for this annotation

GitHub Actions / Test and version packages

'before' is defined but never used. Allowed unused vars must match /^_/u

import { asyncClientCall } from "@ddadaal/tsgrpc-client";
import { Server } from "@ddadaal/tsgrpc-server";
import { ChannelCredentials } from "@grpc/grpc-js";
Expand All @@ -19,6 +21,7 @@ import { Decimal, decimalToMoney, numberToMoney } from "@scow/lib-decimal";
import { AddBillingItemRequest, JobBillingItem, JobServiceClient } from "@scow/protos/build/server/job";
import { createServer } from "src/app";
import { createPriceMap } from "src/bl/PriceMap";
import { misConfig } from "src/config/mis";
import { AmountStrategy, JobPriceItem } from "src/entities/JobPriceItem";
import { Tenant } from "src/entities/Tenant";
import { createPriceItems } from "src/tasks/createBillingItems";
Expand Down Expand Up @@ -236,14 +239,9 @@ it("adds billing item to another tenant", async () => {
expect(reply.historyItems.length).toBe(0);
});

it("calculates price", async () => {

const calculatePrice = async (testData: typeof import("./testData.json")) => {
const priceMap = await createPriceMap(orm.em.fork(), server.ext.clusters, server.logger);


// obtain test data by running the following data in db
const testData = (await import("./testData.json")).default;

const wrongPrices = [] as {
tenantPrice: { expected: number; actual: number | undefined };
accountPrice: { expected: number; actual: number | undefined }
Expand Down Expand Up @@ -272,8 +270,28 @@ it("calculates price", async () => {
}
};

console.log(wrongPrices);

expect(wrongPrices).toBeArrayOfSize(0);
};

it("calculates job price in precision 3 and min charge 0", async () => {

const beforeJobChargeDecimalPrecision = misConfig.jobChargeDecimalPrecision;
const beforeJobMinCharge = misConfig.jobMinCharge;

misConfig.jobChargeDecimalPrecision = 3;
misConfig.jobMinCharge = 0;

await calculatePrice((await import("./testData-precision3.json")).default).finally(() => {

misConfig.jobChargeDecimalPrecision = beforeJobChargeDecimalPrecision;
misConfig.jobMinCharge = beforeJobMinCharge;
});
});

it.only("calculates job prices", async () => {
await calculatePrice((await import("./testData.json")).default);
});

it("gets missing price items in platform scope", async () => {
Expand Down
Loading

0 comments on commit fa899eb

Please sign in to comment.