8041a39dfd
- Added TourScheduleEngine class for managing user queues in a guild. - Implemented methods for joining, leaving, listing, and clearing queues. - Added functionality to promote users to speaker in a stage channel and send announcements. - Created integration tests for the TourScheduleEngine to verify FIFO behavior and announcement dispatch. test: Add unit tests for ping and sign-up commands - Created tests for ping command to ensure it replies with "Pong!". - Implemented tests for sign-up command to verify queue joining, listing, and permission checks. test: Add integration tests for mileage engine flow - Developed tests to validate mileage awarding, event persistence, and role upgrades based on mileage thresholds. chore: Update TypeScript configuration for ESLint - Added tsconfig.eslint.json for ESLint integration. - Modified tsconfig.json to exclude test files from the main compilation.
85 lines
1.9 KiB
TypeScript
85 lines
1.9 KiB
TypeScript
const mockClient = {
|
|
query: jest.fn(),
|
|
release: jest.fn(),
|
|
};
|
|
|
|
const mockPool = {
|
|
connect: jest.fn(async () => mockClient),
|
|
query: jest.fn(),
|
|
end: jest.fn(),
|
|
};
|
|
|
|
jest.mock("pg", () => ({
|
|
Pool: jest.fn(() => mockPool),
|
|
}));
|
|
|
|
import { MileageEngine } from "../../src/mileage";
|
|
|
|
describe("MileageEngine flow", () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
mockClient.query.mockImplementation(async (query: string) => {
|
|
if (query.includes("RETURNING total_miles")) {
|
|
return { rows: [{ total_miles: 120 }] };
|
|
}
|
|
|
|
return { rows: [] };
|
|
});
|
|
});
|
|
|
|
it("awards miles, persists event, and upgrades role when threshold reached", async () => {
|
|
const roleAdd = jest.fn().mockResolvedValue(undefined);
|
|
const member = {
|
|
roles: {
|
|
cache: {
|
|
has: jest.fn().mockReturnValue(false),
|
|
},
|
|
add: roleAdd,
|
|
},
|
|
guild: {
|
|
members: {
|
|
me: {
|
|
roles: {
|
|
highest: {
|
|
position: 100,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
roles: {
|
|
fetch: jest.fn().mockResolvedValue({
|
|
id: "role-1",
|
|
position: 10,
|
|
}),
|
|
},
|
|
},
|
|
} as any;
|
|
|
|
const engine = new MileageEngine({
|
|
databaseUrl: "postgres://test",
|
|
roleTiers: [{ roleId: "role-1", minMiles: 100 }],
|
|
eventScores: { command_execute: 10 },
|
|
});
|
|
|
|
const result = await engine.awardMiles({
|
|
guildId: "guild-1",
|
|
userId: "user-1",
|
|
eventType: "command_execute",
|
|
member,
|
|
});
|
|
|
|
expect(result).toEqual({
|
|
awardedMiles: 10,
|
|
totalMiles: 120,
|
|
upgradedRoleIds: ["role-1"],
|
|
});
|
|
|
|
expect(mockClient.query).toHaveBeenCalledWith("BEGIN");
|
|
expect(mockClient.query).toHaveBeenCalledWith("COMMIT");
|
|
expect(roleAdd).toHaveBeenCalledWith(
|
|
expect.objectContaining({ id: "role-1" }),
|
|
"Mileage upgrade: reached 100 miles",
|
|
);
|
|
});
|
|
});
|