Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: round robin reset interval for teams #19441

Merged
merged 29 commits into from
Mar 10, 2025
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
39ed8ce
add component to set interval
Feb 20, 2025
19fb164
fix variable namings
Feb 21, 2025
109523d
fetch data for given interval
Feb 21, 2025
a65b51d
migration
Feb 21, 2025
fedd7b6
fix type errors in test
Feb 24, 2025
8c5413f
test correct filtering for interval
Feb 24, 2025
b38aa40
fix start end end times to interval
Feb 24, 2025
1640706
fix type error
Feb 24, 2025
fdc050d
pass rrResetInterval to getOrderedListOfLuckyUsers
Feb 24, 2025
f746453
fix imports
Feb 24, 2025
704d113
add translations
Feb 24, 2025
748f37f
add missing translation
Feb 24, 2025
8c0f858
code clean up
Feb 24, 2025
6ec7d26
Merge branch 'main' into feat/rr-reset-interval
Feb 25, 2025
324547d
fix type errors
Mar 3, 2025
9e6977d
Merge branch 'main' into feat/rr-reset-interval
Mar 4, 2025
2b61f4e
fix type error
Mar 4, 2025
0eac46b
fix import
Mar 4, 2025
d5d5d84
Merge branch 'main' into feat/rr-reset-interval
Mar 5, 2025
4de1e41
Merge branch 'main' into feat/rr-reset-interval
emrysal Mar 6, 2025
a6f7ac6
add translation
Mar 6, 2025
ddc3f51
Merge branch 'main' into feat/rr-reset-interval
emrysal Mar 6, 2025
b7050c8
Merge branch 'main' into feat/rr-reset-interval
emrysal Mar 6, 2025
fe005f5
Merge branch 'main' into feat/rr-reset-interval
CarinaWolli Mar 7, 2025
0b725b3
Merge branch 'main' into feat/rr-reset-interval
emrysal Mar 7, 2025
999abf8
Define ZUpdateInputSchema explicitly to decrease depth
emrysal Mar 7, 2025
daa9bd6
Invalid nullable definitions, fixed
emrysal Mar 7, 2025
900344e
Merge branch 'main' into feat/rr-reset-interval
emrysal Mar 9, 2025
8521863
Merge branch 'main' into feat/rr-reset-interval
emrysal Mar 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test correct filtering for interval
  • Loading branch information
CarinaWolli committed Feb 24, 2025
commit 8c5413ffaf0da5b75bb7782fb8daddf9aefab265
95 changes: 91 additions & 4 deletions packages/lib/server/getLuckyUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,29 @@ describe("maximize availability and weights", () => {
routingFormResponse: null,
})
).resolves.toStrictEqual(users[1]);

await expect(
getLuckyUser({
availableUsers: users,
eventType: {
id: 1,
isRRWeightsEnabled: true,
team: { rrResetInterval: RRResetInterval.MONTH },
},
allRRHosts,
routingFormResponse: null,
})
).resolves.toStrictEqual(users[1]);

const queryArgs = prismaMock.booking.findMany.mock.calls[0][0];

// Today: 2021-06-20T11:59:59Z, monthly interval
expect(queryArgs.where?.createdAt).toEqual(
expect.objectContaining({
gte: new Date("2021-06-01T00:00:00Z"),
lte: new Date("2021-06-20T11:59:59.000Z"),
})
);
});

it("can find lucky user if hosts have different weights", async () => {
Expand Down Expand Up @@ -426,12 +449,22 @@ describe("maximize availability and weights", () => {
eventType: {
id: 1,
isRRWeightsEnabled: true,
team: { rrResetInterval: RRResetInterval.MONTH },
team: { rrResetInterval: RRResetInterval.DAY },
},
allRRHosts,
routingFormResponse: null,
})
).resolves.toStrictEqual(users[0]);

const queryArgs = prismaMock.booking.findMany.mock.calls[0][0];

// Today: 2021-06-20T11:59:59Z, daily interval
expect(queryArgs.where?.createdAt).toEqual(
expect.objectContaining({
gte: new Date("2021-06-20T00:00:00Z"),
lte: new Date("2021-06-20T11:59:59.000Z"),
})
);
});

it("can find lucky user with weights and adjusted weights", async () => {
Expand Down Expand Up @@ -524,12 +557,22 @@ describe("maximize availability and weights", () => {
eventType: {
id: 1,
isRRWeightsEnabled: true,
team: { rrResetInterval: RRResetInterval.MONTH },
team: { rrResetInterval: RRResetInterval.DAY },
},
allRRHosts,
routingFormResponse: null,
})
).resolves.toStrictEqual(users[0]);

const queryArgs = prismaMock.booking.findMany.mock.calls[0][0];

// Today: 2021-06-20T11:59:59Z, daily interval
expect(queryArgs.where?.createdAt).toEqual(
expect.objectContaining({
gte: new Date("2021-06-20T00:00:00Z"),
lte: new Date("2021-06-20T11:59:59.000Z"),
})
);
});

it("applies calibration when user had OOO entries this month", async () => {
Expand Down Expand Up @@ -615,6 +658,16 @@ describe("maximize availability and weights", () => {
routingFormResponse: null,
})
).resolves.toStrictEqual(users[1]); // user[1] has one more bookings, but user[0] has calibration 2

const queryArgs = prismaMock.booking.findMany.mock.calls[0][0];

// Today: 2021-06-20T11:59:59Z, monthly interval
expect(queryArgs.where?.createdAt).toEqual(
expect.objectContaining({
gte: new Date("2021-06-01T00:00:00Z"),
lte: new Date("2021-06-20T11:59:59.000Z"),
})
);
});

it("applies calibration when user had full day calendar events this month", async () => {
Expand Down Expand Up @@ -712,6 +765,16 @@ describe("maximize availability and weights", () => {
routingFormResponse: null,
})
).resolves.toStrictEqual(users[1]); // user[1] has one more booking, but user[0] has calibration 2

const queryArgs = prismaMock.booking.findMany.mock.calls[0][0];

// Today: 2021-06-20T11:59:59Z, monthly interval
expect(queryArgs.where?.createdAt).toEqual(
expect.objectContaining({
gte: new Date("2021-06-01T00:00:00Z"),
lte: new Date("2021-06-20T11:59:59.000Z"),
})
);
});

it("applies calibration to newly added hosts so they are not penalized unfairly compared to their peers", async () => {
Expand Down Expand Up @@ -822,6 +885,16 @@ describe("maximize availability and weights", () => {
routingFormResponse: null,
})
).resolves.toStrictEqual(users[0]);

const queryArgs = prismaMock.booking.findMany.mock.calls[0][0];

// Today: 2021-06-20T11:59:59Z, monthly interval
expect(queryArgs.where?.createdAt).toEqual(
expect.objectContaining({
gte: new Date("2021-06-01T00:00:00Z"),
lte: new Date("2021-06-20T11:59:59.000Z"),
})
);
});
});

Expand Down Expand Up @@ -950,7 +1023,11 @@ describe("attribute weights and virtual queues", () => {
});

const queuesAndAttributesData = await prepareQueuesAndAttributesData({
eventType: { id: 1, isRRWeightsEnabled: true, team: { parentId: 1 } },
eventType: {
id: 1,
isRRWeightsEnabled: true,
team: { parentId: 1, rrResetInterval: RRResetInterval.DAY },
},
routingFormResponse,
allRRHosts: [
{
Expand Down Expand Up @@ -1190,11 +1267,21 @@ describe("attribute weights and virtual queues", () => {
eventType: {
id: 1,
isRRWeightsEnabled: true,
team: { parentId: 1, rrResetInterval: RRResetInterval.MONTH },
team: { parentId: 1, rrResetInterval: RRResetInterval.DAY },
},
allRRHosts,
routingFormResponse,
})
).resolves.toStrictEqual(users[1]);

const queryArgs = prismaMock.booking.findMany.mock.calls[0][0];

// Today: 2021-06-20T11:59:59Z, daily interval
expect(queryArgs.where?.createdAt).toEqual(
expect.objectContaining({
gte: new Date("2021-06-20T00:00:00Z"),
lte: new Date("2021-06-20T11:59:59.000Z"),
})
);
});
});
Loading