Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
BTreston committed Jan 7, 2025
1 parent c7cde29 commit d0f260d
Showing 1 changed file with 20 additions and 31 deletions.
51 changes: 20 additions & 31 deletions jslib/common/src/services/batch-requests.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,35 @@ import { SingleRequestBuilder } from "./single-request.service";
describe("BatchingService", () => {
let batchRequestBuilder: BatchRequestBuilder;
let singleRequestBuilder: SingleRequestBuilder;
let userSimulator: (userCount: number) => UserEntry[];
let groupSimulator: (userCount: number) => GroupEntry[];

beforeEach(async () => {
const batchSize = 2000;
function userSimulator(userCount: number) {
const simulatedArray: UserEntry[] = [];
for (let i = 0; i <= userCount; i++) {
simulatedArray.push(new UserEntry());
}
return simulatedArray;
}

function groupSimulator(groupCount: number) {
const simulatedArray: GroupEntry[] = [];
for (let i = 0; i <= groupCount; i++) {
simulatedArray.push(new GroupEntry());
}
return simulatedArray;
}

batchRequestBuilder = new BatchRequestBuilder(batchSize);
beforeEach(async () => {
batchRequestBuilder = new BatchRequestBuilder();
singleRequestBuilder = new SingleRequestBuilder();

userSimulator = (userCount: number) => {
const simulatedArray: UserEntry[] = [];
for (let i = 0; i < userCount; i += batchSize) {
for (let j = 0; j <= batchSize; j++) {
simulatedArray.push(new UserEntry());
}
}
return simulatedArray;
};

groupSimulator = (groupCount: number) => {
const simulatedArray: GroupEntry[] = [];
for (let i = 0; i < groupCount; i += batchSize) {
for (let j = 0; j <= batchSize; j++) {
simulatedArray.push(new GroupEntry());
}
}
return simulatedArray;
};
});

it("Batches requests for > 2000 users", () => {
it("BatchRequestBuilder batches requests for > 2000 users", () => {
const mockGroups = groupSimulator(11000);
const mockUsers = userSimulator(11000);

const requests = batchRequestBuilder.buildRequest(mockGroups, mockUsers, true, true);

expect(requests.length).toEqual(14);
expect(requests.length).toEqual(12);
});

it("SingleRequestBuilder returns single request for 200 users", () => {
Expand All @@ -56,10 +48,7 @@ describe("BatchingService", () => {
});

it("BatchRequestBuilder retuns an empty array when there are no users or groups", () => {
const mockGroups = groupSimulator(0);
const mockUsers = userSimulator(0);

const requests = batchRequestBuilder.buildRequest(mockGroups, mockUsers, true, true);
const requests = batchRequestBuilder.buildRequest([], [], true, true);

expect(requests).toEqual([]);
});
Expand Down

0 comments on commit d0f260d

Please sign in to comment.