Download automation/src/modules/hcm/api.ts from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 4.54 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/automation/src/modules/hcm/api.ts
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/automation/src/modules/hcm/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/automation/src/modules/hcm/api.ts
4.54 kB
| import { expect } from '@playwright/test'; | |
| import { MockApi, MOCK, Persona, unique } from '../../api'; | |
| import { DATA, PROCESS } from './labels'; | |
| export type RunResult = { PayrollFlow: string; PersonNumber: string; ElementName: string; ElementClassification: string; ResultValue: number }; | |
| const iso = (d: Date) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; | |
| /** {{dates.next_monday}} / {{dates.next_tuesday}}. */ | |
| export const nextWeekday = (dow: number) => { const d = new Date(); d.setDate(d.getDate() + (((dow - d.getDay() + 7) % 7) || 7)); return iso(d); }; | |
| /** | |
| * HCM data recipes (tests/data-recipes/hcm) through the MOCK HCM pack: REST facade, /api/hcm (internal) and /api/processes. | |
| * SYNTHETIC people only: 'Testworker' names, ZZ-NID-* national ids, example.invalid mail. | |
| */ | |
| export class HCMApi { | |
| constructor(public api: MockApi) {} | |
| rest(as: Persona, method: string, path: string, data?: unknown) { return this.api.call(as, method, path, data, MOCK.restBase); } | |
| async restQ<T = any>(as: Persona, resource: string, q: string) { const r = await this.rest(as, 'GET', `/${resource}?q=${encodeURIComponent(q)}`); expect(r.status, `GET ${resource}?q=${q}`).toBe(200); return (r.body as { items: T[] }).items; } | |
| async process(as: Persona, name: string, params: Record<string, unknown> = {}) { const p = await this.api.ok(as, 'POST', '/processes', { name, params }); expect(p.status, `${name}: ${p.log}`).toBe('SUCCEEDED'); return p; } | |
| /** DR-HCM-HIRE-001: synthetic hire payload (suffix keeps names unique per run). */ | |
| hirePayload(suffix = unique('').replace(/[^A-Za-z0-9]/g, '').slice(-6)) { | |
| return { last: `Testworker${suffix}`, first: 'Alpha', email: `alpha.${suffix}@example.invalid`, nid: `ZZ-NID-${suffix}`, le: DATA.le, bu: DATA.bu, job: DATA.jobG1, grade: 'G1', manager: DATA.manager, | |
| payroll: DATA.payroll, salaryBasis: DATA.salaryBasis, salary: 60000 }; | |
| } | |
| async submitHire(suffix?: string) { return this.api.ok('hr_specialist', 'POST', '/hcm/hires', this.hirePayload(suffix)) as Promise<{ number: string; subject: string }>; } | |
| /** Hire submitted and approved; returns the new person number. */ | |
| async hired(suffix?: string) { const t = await this.submitHire(suffix); const d = await this.api.ok('zz_hr_approver', 'POST', `/hcm/transactions/${t.number}/approve`); return d.personNumber as string; } | |
| async worker(pn: string, as: Persona = 'hcm_integration_user') { return (await this.restQ(as, 'workers', `PersonNumber='${pn}'`))[0]; } | |
| async user(pn: string) { return (await this.restQ('it_security_manager', 'userAccounts', `PersonNumber='${pn}'`))[0]; } | |
| /** DR-HCM-TL-001: submitted (and optionally approved) weekly time card for ZZ-W1. */ | |
| async timeCard(hours: Record<string, number> = { Mon: 10, Tue: 10, Wed: 10, Thu: 10, Fri: 10 }, approve = true) { | |
| const c = await this.api.ok('zz_employee', 'POST', '/hcm/timeCards', hours); if (approve) await this.api.ok('zz_manager', 'POST', `/hcm/timeCards/${c.number}/approve`); return c.number as string; | |
| } | |
| /** DR-HCM-PAY-001 chain: 10 OT hours transferred (TL-003), Medical Pre-Tax 150.00 entry, then Calculate Payroll on the ZZ monthly payroll. */ | |
| async payrollReady() { | |
| await this.timeCard(); await this.process('payroll_admin_zz', PROCESS.loadTime, { payroll: DATA.payroll }); | |
| await this.api.ok('payroll_admin_zz', 'POST', '/hcm/elementEntries', { person: DATA.worker, element: 'Medical Pre-Tax', amount: 150 }); | |
| } | |
| async calculatedPayroll(payroll: string = DATA.payroll) { return this.process('payroll_admin_zz', PROCESS.payrollFlow, { flowPattern: 'Calculate Payroll', payroll }); } | |
| async results(q: string) { return this.restQ<RunResult>('payroll_admin_zz', 'payrollRunResults', q); } | |
| static value(rows: RunResult[], pn: string, el: string) { const r = rows.find((x) => x.PersonNumber === pn && x.ElementName === el); return r ? r.ResultValue : undefined; } | |
| async balance(pn: string) { return (await this.api.ok('absence_admin', 'GET', `/hcm/absenceBalances/${pn}`)).balance as number; } | |
| async approvedAbsence(start: string, end: string) { | |
| const a = await this.api.ok('zz_employee', 'POST', '/hcm/absences', { type: 'Vacation', start, end }); await this.api.ok('zz_manager', 'POST', `/hcm/absences/${a.number}/approve`); return a.number as string; | |
| } | |
| async stageHdl(name: string, content: string) { return this.api.ok('hcm_integration_user', 'POST', '/hcm/hdl/files', { name, content }); } | |
| } | |