/**
* Mock Rippling client for unit testing tools without API calls.
*/
import { RipplingClient } from "../../src/clients/rippling-client.js";
// Sample data fixtures
export const MOCK_COMPANY = {
id: "company_123",
name: "Acme Corp",
address: {
street: "123 Main St",
city: "San Francisco",
state: "CA",
zip: "94105",
country: "US",
},
};
export const MOCK_EMPLOYEES = [
{
id: "role_001",
userId: "user_001",
name: "Alice Johnson",
firstName: "Alice",
lastName: "Johnson",
workEmail: "alice@acme.com",
title: "Senior Engineer",
department: "Engineering",
roleState: "ACTIVE",
employmentType: "FULL_TIME",
},
{
id: "role_002",
userId: "user_002",
name: "Bob Smith",
firstName: "Bob",
lastName: "Smith",
workEmail: "bob@acme.com",
title: "Product Manager",
department: "Product",
roleState: "ACTIVE",
employmentType: "FULL_TIME",
},
{
id: "role_003",
userId: "user_003",
name: "Charlie Brown",
firstName: "Charlie",
lastName: "Brown",
workEmail: "charlie@acme.com",
title: "Designer",
department: "Design",
roleState: "TERMINATED",
employmentType: "FULL_TIME",
},
];
export const MOCK_DEPARTMENTS = [
{ id: "dept_001", name: "Engineering", parent: null },
{ id: "dept_002", name: "Product", parent: null },
{ id: "dept_003", name: "Design", parent: null },
{ id: "dept_004", name: "Frontend", parent: "dept_001" },
];
export const MOCK_LEAVE_BALANCES = {
roleId: "role_001",
leaveBalances: [
{
companyLeaveTypeId: "lt_001",
isUnlimited: false,
remainingBalanceInMinutes: 4800,
remainingBalanceInMinutesWithFuture: 4320,
},
{
companyLeaveTypeId: "lt_002",
isUnlimited: false,
remainingBalanceInMinutes: 2400,
remainingBalanceInMinutesWithFuture: 2400,
},
],
};
export const MOCK_LEAVE_REQUESTS = [
{
id: "lr_001",
role: "role_001",
status: "PENDING",
startDate: "2025-03-10",
endDate: "2025-03-14",
requestedBy: "role_001",
},
{
id: "lr_002",
role: "role_002",
status: "APPROVED",
startDate: "2025-04-01",
endDate: "2025-04-05",
requestedBy: "role_002",
},
];
export const MOCK_GROUPS = [
{
id: "grp_001",
name: "Alpha Team",
spokeId: "alpha",
userIds: ["user_001", "user_002"],
version: 1,
},
];
export const MOCK_TEAMS = [
{ id: "team_001", name: "Platform", subteams: ["team_002"] },
{ id: "team_002", name: "Frontend", subteams: [] },
];
export const MOCK_LEVELS = [
{ id: "level_001", name: "Individual Contributor" },
{ id: "level_002", name: "Manager" },
{ id: "level_003", name: "Executive" },
];
export const MOCK_WORK_LOCATIONS = [
{
id: "loc_001",
name: "SF HQ",
address: { city: "San Francisco", state: "CA" },
},
{
id: "loc_002",
name: "Remote",
address: null,
},
];
export const MOCK_CUSTOM_FIELDS = [
{ id: "cf_001", name: "T-Shirt Size", type: "string" },
{ id: "cf_002", name: "Start Date", type: "date" },
];
export const MOCK_ACTIVITY = [
{
id: "act_001",
type: "employee.created",
timestamp: "2025-01-15T10:00:00Z",
},
{
id: "act_002",
type: "employee.updated",
timestamp: "2025-01-16T14:30:00Z",
},
];
export const MOCK_LEAVE_TYPES = [
{ id: "lt_001", name: "PTO" },
{ id: "lt_002", name: "Sick Leave" },
];
/**
* Create a mock RipplingClient with all methods stubbed.
*/
export function createMockClient(): RipplingClient {
const client = Object.create(RipplingClient.prototype) as RipplingClient;
// Company
(client as any).getCompany = vi.fn().mockResolvedValue(MOCK_COMPANY);
(client as any).listDepartments = vi
.fn()
.mockResolvedValue(MOCK_DEPARTMENTS);
(client as any).listWorkLocations = vi
.fn()
.mockResolvedValue(MOCK_WORK_LOCATIONS);
(client as any).listTeams = vi.fn().mockResolvedValue(MOCK_TEAMS);
(client as any).listLevels = vi.fn().mockResolvedValue(MOCK_LEVELS);
(client as any).listCustomFields = vi
.fn()
.mockResolvedValue(MOCK_CUSTOM_FIELDS);
(client as any).getCompanyActivity = vi
.fn()
.mockResolvedValue(MOCK_ACTIVITY);
// Employees
(client as any).listEmployees = vi
.fn()
.mockResolvedValue(MOCK_EMPLOYEES.filter((e) => e.roleState === "ACTIVE"));
(client as any).getEmployee = vi.fn().mockImplementation((id: string) => {
const emp = MOCK_EMPLOYEES.find((e) => e.id === id);
if (!emp) throw new Error("Not found");
return Promise.resolve(emp);
});
(client as any).listAllEmployees = vi
.fn()
.mockResolvedValue(MOCK_EMPLOYEES);
// Leave
(client as any).getLeaveBalances = vi
.fn()
.mockResolvedValue(MOCK_LEAVE_BALANCES);
(client as any).listLeaveRequests = vi
.fn()
.mockResolvedValue(MOCK_LEAVE_REQUESTS);
(client as any).processLeaveRequest = vi
.fn()
.mockResolvedValue({ success: true });
(client as any).updateLeaveRequest = vi
.fn()
.mockResolvedValue({ success: true });
(client as any).listLeaveTypes = vi
.fn()
.mockResolvedValue(MOCK_LEAVE_TYPES);
// Groups
(client as any).listGroups = vi.fn().mockResolvedValue(MOCK_GROUPS);
(client as any).createGroup = vi.fn().mockResolvedValue({
id: "grp_new",
name: "New Group",
spokeId: "new",
userIds: ["user_001"],
version: 1,
});
(client as any).updateGroup = vi.fn().mockResolvedValue({
id: "grp_001",
name: "Updated",
userIds: ["user_001"],
version: 2,
});
(client as any).deleteGroup = vi.fn().mockResolvedValue(undefined);
return client;
}