@nannykeeper/mcp-server 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +5 -3
- package/CLAUDE.md +1 -0
- package/README.md +21 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +40 -1
- package/dist/tools/run-payroll.d.ts +21 -0
- package/dist/tools/run-payroll.js +63 -0
- package/manifest.json +2 -2
- package/package.json +1 -1
- package/dist/__tests__/tools.test.d.ts +0 -7
- package/dist/__tests__/tools.test.js +0 -269
package/AGENTS.md
CHANGED
|
@@ -6,6 +6,7 @@ Calculate US household employer (nanny) taxes for all 50 states + DC.
|
|
|
6
6
|
## Tools Available
|
|
7
7
|
- `calculate_nanny_taxes(state, annual_wages, pay_frequency?)` — returns full tax breakdown
|
|
8
8
|
- `check_threshold(state, annual_wages, tax_year?)` — checks if employer obligations apply
|
|
9
|
+
- `run_payroll(employer_id, employee_id, ...)` — run payroll with full tax calc, YTD tracking, and DB persistence (Starter+ required)
|
|
9
10
|
|
|
10
11
|
## When to Use
|
|
11
12
|
- User asks about nanny taxes, household employer taxes, or paying a caregiver
|
|
@@ -19,9 +20,10 @@ Calculate US household employer (nanny) taxes for all 50 states + DC.
|
|
|
19
20
|
- Schedule H filed with personal 1040
|
|
20
21
|
|
|
21
22
|
## After Calculation
|
|
22
|
-
The
|
|
23
|
-
to run payroll
|
|
24
|
-
|
|
23
|
+
The `calculate_nanny_taxes` response includes `next_actions` and a `signup_url`.
|
|
24
|
+
If the user wants to run payroll with persistence, use the `run_payroll` tool
|
|
25
|
+
(requires Starter+ subscription). For documents and direct deposit, guide them
|
|
26
|
+
to the NannyKeeper web app.
|
|
25
27
|
|
|
26
28
|
## API Key
|
|
27
29
|
Requires `NANNYKEEPER_API_KEY` environment variable.
|
package/CLAUDE.md
CHANGED
|
@@ -6,6 +6,7 @@ Calculate nanny taxes for all 50 US states.
|
|
|
6
6
|
## Tools
|
|
7
7
|
- `calculate_nanny_taxes` — Full federal + state tax breakdown
|
|
8
8
|
- `check_threshold` — Whether wages trigger employer tax obligations
|
|
9
|
+
- `run_payroll` — Run payroll with full tax calc, YTD tracking, and DB persistence (Starter+ required)
|
|
9
10
|
|
|
10
11
|
## Setup
|
|
11
12
|
Requires API key (free): https://www.nannykeeper.com/developers/keys
|
package/README.md
CHANGED
|
@@ -46,6 +46,24 @@ Check if annual wages cross the household employer tax threshold.
|
|
|
46
46
|
- `annual_wages` (required) — Annual wages to check
|
|
47
47
|
- `tax_year` (optional) — Tax year (default: current year)
|
|
48
48
|
|
|
49
|
+
### `run_payroll`
|
|
50
|
+
|
|
51
|
+
Run payroll for a household employee with full tax calculations, YTD tracking, and database persistence. Creates a payroll record. Requires a Starter+ subscription.
|
|
52
|
+
|
|
53
|
+
**Parameters:**
|
|
54
|
+
- `employer_id` (required) — Employer UUID from your NannyKeeper account
|
|
55
|
+
- `employee_id` (required) — Employee UUID to run payroll for
|
|
56
|
+
- `pay_period_start` (required) — Start of pay period (YYYY-MM-DD)
|
|
57
|
+
- `pay_period_end` (required) — End of pay period (YYYY-MM-DD)
|
|
58
|
+
- `pay_date` (required) — Date employee is paid (YYYY-MM-DD)
|
|
59
|
+
- `pay_frequency` (required) — weekly, biweekly, semimonthly, or monthly
|
|
60
|
+
- `regular_hours` (optional) — Regular hours worked
|
|
61
|
+
- `overtime_hours` (optional) — Overtime hours worked
|
|
62
|
+
- `bonus` (optional) — Bonus amount
|
|
63
|
+
- `payment_method` (optional) — direct_deposit, check, or cash (default: check)
|
|
64
|
+
- `notes` (optional) — Use "catch-up" for retroactive payrolls
|
|
65
|
+
- `idempotency_key` (optional) — Prevent duplicate payroll creation
|
|
66
|
+
|
|
49
67
|
## Examples
|
|
50
68
|
|
|
51
69
|
### Example 1: Full tax calculation
|
|
@@ -95,15 +113,15 @@ Check if annual wages cross the household employer tax threshold.
|
|
|
95
113
|
## Key Facts
|
|
96
114
|
|
|
97
115
|
- **FICA threshold (2026):** $3,000/year — above this you must pay employer Social Security + Medicare
|
|
98
|
-
- **Social Security:** 6.2% employer + 6.2% employee (wage base $
|
|
116
|
+
- **Social Security:** 6.2% employer + 6.2% employee (wage base $184,500)
|
|
99
117
|
- **Medicare:** 1.45% employer + 1.45% employee (no wage base)
|
|
100
118
|
- **FUTA:** 0.6% on first $7,000 per employee
|
|
101
119
|
- **Schedule H:** Filed with your personal 1040 tax return
|
|
102
120
|
|
|
103
121
|
## Need More Than Calculations?
|
|
104
122
|
|
|
105
|
-
The free tier covers tax calculations (50/day).
|
|
106
|
-
- **Run payroll** with year-to-date tracking
|
|
123
|
+
The free tier covers tax calculations (50/day). With a paid plan you can also use the `run_payroll` tool:
|
|
124
|
+
- **Run payroll** with year-to-date tracking via MCP
|
|
107
125
|
- **Generate pay stubs** and **W-2s**
|
|
108
126
|
- **Process direct deposit** via ACH
|
|
109
127
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
* NannyKeeper MCP Server
|
|
4
4
|
*
|
|
5
5
|
* Model Context Protocol server for calculating US household employer
|
|
6
|
-
* (nanny) taxes. Provides
|
|
6
|
+
* (nanny) taxes. Provides three tools:
|
|
7
7
|
* - calculate_nanny_taxes: Full tax breakdown for any US state
|
|
8
8
|
* - check_threshold: Whether wages trigger employer obligations
|
|
9
|
+
* - run_payroll: Run payroll with YTD tracking and DB persistence
|
|
9
10
|
*
|
|
10
11
|
* Requires NANNYKEEPER_API_KEY environment variable.
|
|
11
12
|
* Get a free key at: https://www.nannykeeper.com/developers/keys
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
* NannyKeeper MCP Server
|
|
4
4
|
*
|
|
5
5
|
* Model Context Protocol server for calculating US household employer
|
|
6
|
-
* (nanny) taxes. Provides
|
|
6
|
+
* (nanny) taxes. Provides three tools:
|
|
7
7
|
* - calculate_nanny_taxes: Full tax breakdown for any US state
|
|
8
8
|
* - check_threshold: Whether wages trigger employer obligations
|
|
9
|
+
* - run_payroll: Run payroll with YTD tracking and DB persistence
|
|
9
10
|
*
|
|
10
11
|
* Requires NANNYKEEPER_API_KEY environment variable.
|
|
11
12
|
* Get a free key at: https://www.nannykeeper.com/developers/keys
|
|
@@ -15,6 +16,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
15
16
|
import { z } from "zod";
|
|
16
17
|
import { executeCalculate } from "./tools/calculate.js";
|
|
17
18
|
import { executeThreshold } from "./tools/threshold.js";
|
|
19
|
+
import { executeRunPayroll } from "./tools/run-payroll.js";
|
|
18
20
|
const server = new McpServer({
|
|
19
21
|
name: "nannykeeper",
|
|
20
22
|
version: "1.0.0",
|
|
@@ -60,6 +62,43 @@ server.tool("check_threshold", "Check if annual wages to a household employee cr
|
|
|
60
62
|
const result = await executeThreshold(args);
|
|
61
63
|
return { content: [{ type: "text", text: result }] };
|
|
62
64
|
});
|
|
65
|
+
// Register run_payroll tool
|
|
66
|
+
server.tool("run_payroll", "Run payroll for a household employee. Calculates all taxes (federal, state, FICA, FUTA) " +
|
|
67
|
+
"with year-to-date tracking and creates a payroll record. " +
|
|
68
|
+
"Returns the full tax breakdown, net pay, employer costs, and a payroll ID for reference. " +
|
|
69
|
+
"Requires a Starter+ subscription. The payroll is created with 'draft' status " +
|
|
70
|
+
"(or 'completed' for catch-up payrolls with notes='catch-up').", {
|
|
71
|
+
employer_id: z.string().uuid().describe("Employer UUID from NannyKeeper account"),
|
|
72
|
+
employee_id: z.string().uuid().describe("Employee UUID to run payroll for"),
|
|
73
|
+
pay_period_start: z.string().describe("Start of pay period (YYYY-MM-DD)"),
|
|
74
|
+
pay_period_end: z.string().describe("End of pay period (YYYY-MM-DD)"),
|
|
75
|
+
pay_date: z.string().describe("Date employee is paid (YYYY-MM-DD)"),
|
|
76
|
+
pay_frequency: z
|
|
77
|
+
.enum(["weekly", "biweekly", "semimonthly", "monthly"])
|
|
78
|
+
.describe("How often the employee is paid"),
|
|
79
|
+
regular_hours: z.number().optional().describe("Regular hours worked this period"),
|
|
80
|
+
overtime_hours: z.number().optional().describe("Overtime hours worked this period"),
|
|
81
|
+
bonus: z.number().optional().describe("Bonus amount for this period"),
|
|
82
|
+
other_earnings: z.number().optional().describe("Other earnings for this period"),
|
|
83
|
+
payment_method: z
|
|
84
|
+
.enum(["direct_deposit", "check", "cash"])
|
|
85
|
+
.optional()
|
|
86
|
+
.describe("How the employee is paid (default: check)"),
|
|
87
|
+
notes: z.string().optional().describe("Notes (use 'catch-up' for retroactive payrolls)"),
|
|
88
|
+
idempotency_key: z
|
|
89
|
+
.string()
|
|
90
|
+
.optional()
|
|
91
|
+
.describe("Unique key to prevent duplicate payroll creation"),
|
|
92
|
+
}, {
|
|
93
|
+
title: "Run Payroll",
|
|
94
|
+
readOnlyHint: false,
|
|
95
|
+
destructiveHint: false,
|
|
96
|
+
idempotentHint: false,
|
|
97
|
+
openWorldHint: true,
|
|
98
|
+
}, async (args) => {
|
|
99
|
+
const result = await executeRunPayroll(args);
|
|
100
|
+
return { content: [{ type: "text", text: result }] };
|
|
101
|
+
});
|
|
63
102
|
// Start server
|
|
64
103
|
async function main() {
|
|
65
104
|
const transport = new StdioServerTransport();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* run_payroll MCP tool
|
|
3
|
+
*
|
|
4
|
+
* Calls the NannyKeeper API to run payroll for a household employee.
|
|
5
|
+
* Creates a payroll record with full tax calculations and YTD tracking.
|
|
6
|
+
*/
|
|
7
|
+
export declare function executeRunPayroll(args: {
|
|
8
|
+
employer_id: string;
|
|
9
|
+
employee_id: string;
|
|
10
|
+
pay_period_start: string;
|
|
11
|
+
pay_period_end: string;
|
|
12
|
+
pay_date: string;
|
|
13
|
+
pay_frequency: string;
|
|
14
|
+
regular_hours?: number;
|
|
15
|
+
overtime_hours?: number;
|
|
16
|
+
bonus?: number;
|
|
17
|
+
other_earnings?: number;
|
|
18
|
+
payment_method?: string;
|
|
19
|
+
notes?: string;
|
|
20
|
+
idempotency_key?: string;
|
|
21
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* run_payroll MCP tool
|
|
3
|
+
*
|
|
4
|
+
* Calls the NannyKeeper API to run payroll for a household employee.
|
|
5
|
+
* Creates a payroll record with full tax calculations and YTD tracking.
|
|
6
|
+
*/
|
|
7
|
+
const API_BASE = process.env.NANNYKEEPER_API_URL || "https://www.nannykeeper.com";
|
|
8
|
+
export async function executeRunPayroll(args) {
|
|
9
|
+
const apiKey = process.env.NANNYKEEPER_API_KEY;
|
|
10
|
+
if (!apiKey) {
|
|
11
|
+
return JSON.stringify({
|
|
12
|
+
error: "NANNYKEEPER_API_KEY environment variable is not set. Get a key at nannykeeper.com/developers/keys",
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const headers = {
|
|
17
|
+
Authorization: `Bearer ${apiKey}`,
|
|
18
|
+
"Content-Type": "application/json",
|
|
19
|
+
};
|
|
20
|
+
if (args.idempotency_key) {
|
|
21
|
+
headers["Idempotency-Key"] = args.idempotency_key;
|
|
22
|
+
}
|
|
23
|
+
const response = await fetch(`${API_BASE}/api/v1/payroll/run`, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
headers,
|
|
26
|
+
body: JSON.stringify({
|
|
27
|
+
employer_id: args.employer_id,
|
|
28
|
+
pay_period_start: args.pay_period_start,
|
|
29
|
+
pay_period_end: args.pay_period_end,
|
|
30
|
+
pay_date: args.pay_date,
|
|
31
|
+
pay_frequency: args.pay_frequency,
|
|
32
|
+
employees: [
|
|
33
|
+
{
|
|
34
|
+
employee_id: args.employee_id,
|
|
35
|
+
regular_hours: args.regular_hours,
|
|
36
|
+
overtime_hours: args.overtime_hours,
|
|
37
|
+
bonus: args.bonus,
|
|
38
|
+
other_earnings: args.other_earnings,
|
|
39
|
+
payment_method: args.payment_method || "check",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
notes: args.notes,
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
const data = await response.json();
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
if (response.status === 429) {
|
|
48
|
+
return JSON.stringify({
|
|
49
|
+
error: "Rate limit exceeded. Upgrade at nannykeeper.com/developers/pricing",
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return JSON.stringify({
|
|
53
|
+
error: data.error?.message || `API error: ${response.status}`,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return JSON.stringify(data);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
return JSON.stringify({
|
|
60
|
+
error: `Network error: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
package/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": "0.3",
|
|
3
3
|
"name": "nannykeeper",
|
|
4
|
-
"version": "1.1
|
|
5
|
-
"description": "Calculate US household employer (nanny) taxes for all 50 states.
|
|
4
|
+
"version": "1.2.1",
|
|
5
|
+
"description": "Calculate US household employer (nanny) taxes and run payroll for all 50 states. Tax breakdowns, threshold checks, and payroll with YTD tracking.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "imaznation",
|
|
8
8
|
"url": "https://github.com/imaznation"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nannykeeper/mcp-server",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"mcpName": "com.nannykeeper.www/mcp-server",
|
|
5
5
|
"description": "MCP server for calculating US household employer (nanny) taxes. All 50 states. Works with Claude, ChatGPT, and any MCP-compatible AI agent.",
|
|
6
6
|
"keywords": [
|
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for MCP tool handlers: calculate_nanny_taxes and check_threshold.
|
|
3
|
-
*
|
|
4
|
-
* Fetch is mocked via vi.fn() so no real HTTP calls are made.
|
|
5
|
-
* Each test group restores the env and resets mocks to keep tests isolated.
|
|
6
|
-
*/
|
|
7
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
8
|
-
import { executeCalculate } from "../tools/calculate.js";
|
|
9
|
-
import { executeThreshold } from "../tools/threshold.js";
|
|
10
|
-
// ---------------------------------------------------------------------------
|
|
11
|
-
// Helpers
|
|
12
|
-
// ---------------------------------------------------------------------------
|
|
13
|
-
/** Build a minimal fetch Response mock. */
|
|
14
|
-
function makeFetchResponse(body, status = 200) {
|
|
15
|
-
return {
|
|
16
|
-
ok: status >= 200 && status < 300,
|
|
17
|
-
status,
|
|
18
|
-
json: async () => body,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
/** Minimal valid calculate API response (mirrors the real API shape). */
|
|
22
|
-
const CALCULATE_SUCCESS_RESPONSE = {
|
|
23
|
-
tax_year: 2026,
|
|
24
|
-
state: "CA",
|
|
25
|
-
state_name: "California",
|
|
26
|
-
annual_wages: 30000,
|
|
27
|
-
pay_frequency: "biweekly",
|
|
28
|
-
employer_taxes: {
|
|
29
|
-
social_security: 1860,
|
|
30
|
-
medicare: 435,
|
|
31
|
-
futa: 42,
|
|
32
|
-
state_unemployment: 1110,
|
|
33
|
-
total: 3447,
|
|
34
|
-
effective_rate: 11.49,
|
|
35
|
-
},
|
|
36
|
-
employee_taxes_estimate: {
|
|
37
|
-
federal_income_tax: 1898,
|
|
38
|
-
state_income_tax: 450,
|
|
39
|
-
social_security: 1860,
|
|
40
|
-
medicare: 435,
|
|
41
|
-
total: 4643,
|
|
42
|
-
note: "Estimate based on standard deduction.",
|
|
43
|
-
},
|
|
44
|
-
per_paycheck: {
|
|
45
|
-
gross_pay: 1153.85,
|
|
46
|
-
employer_taxes: 132.58,
|
|
47
|
-
total_cost: 1286.43,
|
|
48
|
-
periods_per_year: 26,
|
|
49
|
-
},
|
|
50
|
-
threshold: {
|
|
51
|
-
fica_threshold: 3000,
|
|
52
|
-
federal_status: "above",
|
|
53
|
-
action_required: true,
|
|
54
|
-
state_suta_status: "above",
|
|
55
|
-
state_suta_threshold: 750,
|
|
56
|
-
},
|
|
57
|
-
limitations: [
|
|
58
|
-
"This estimate assumes $0 in prior wages this year.",
|
|
59
|
-
"State unemployment rate uses the new-employer default.",
|
|
60
|
-
],
|
|
61
|
-
next_actions: {
|
|
62
|
-
available: ["calculate", "check_threshold"],
|
|
63
|
-
requires_account: [
|
|
64
|
-
{ action: "run_payroll", description: "Calculate exact taxes with YTD tracking" },
|
|
65
|
-
],
|
|
66
|
-
signup_url: "https://www.nannykeeper.com/signup?ref=test_abc123&utm_source=api&utm_medium=agent",
|
|
67
|
-
},
|
|
68
|
-
continue_url: "https://www.nannykeeper.com/signup?ref=test_abc123&prefill_state=CA&prefill_wages=30000",
|
|
69
|
-
};
|
|
70
|
-
/** Minimal valid threshold API response. */
|
|
71
|
-
const THRESHOLD_SUCCESS_RESPONSE = {
|
|
72
|
-
tax_year: 2026,
|
|
73
|
-
state: "CA",
|
|
74
|
-
annual_wages: 30000,
|
|
75
|
-
federal: {
|
|
76
|
-
fica_threshold: 3000,
|
|
77
|
-
approaching_threshold: 2400,
|
|
78
|
-
status: "above",
|
|
79
|
-
action_required: true,
|
|
80
|
-
explanation: "At $30,000/year, you exceed the $3,000 FICA threshold for 2026. You are a household employer.",
|
|
81
|
-
},
|
|
82
|
-
state_threshold: {
|
|
83
|
-
threshold_quarterly: 750,
|
|
84
|
-
status: "above",
|
|
85
|
-
explanation: "CA has a lower state threshold of $750/quarter.",
|
|
86
|
-
},
|
|
87
|
-
futa: {
|
|
88
|
-
quarterly_threshold: 1000,
|
|
89
|
-
note: "FUTA is triggered when you pay $1,000+ in any calendar quarter.",
|
|
90
|
-
},
|
|
91
|
-
next_actions: {
|
|
92
|
-
available: ["calculate", "check_threshold"],
|
|
93
|
-
requires_account: [
|
|
94
|
-
{ action: "run_payroll", description: "Calculate exact taxes and generate a pay stub" },
|
|
95
|
-
],
|
|
96
|
-
signup_url: "https://www.nannykeeper.com/signup?ref=test_abc123&utm_source=api&utm_medium=agent",
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
// ---------------------------------------------------------------------------
|
|
100
|
-
// Test setup
|
|
101
|
-
// ---------------------------------------------------------------------------
|
|
102
|
-
const originalFetch = global.fetch;
|
|
103
|
-
beforeEach(() => {
|
|
104
|
-
// Provide a valid API key by default; individual tests may delete it.
|
|
105
|
-
process.env.NANNYKEEPER_API_KEY = "test_key_abc123";
|
|
106
|
-
process.env.NANNYKEEPER_API_URL = "https://mock.nannykeeper.com";
|
|
107
|
-
});
|
|
108
|
-
afterEach(() => {
|
|
109
|
-
vi.restoreAllMocks();
|
|
110
|
-
global.fetch = originalFetch;
|
|
111
|
-
delete process.env.NANNYKEEPER_API_KEY;
|
|
112
|
-
delete process.env.NANNYKEEPER_API_URL;
|
|
113
|
-
});
|
|
114
|
-
// ---------------------------------------------------------------------------
|
|
115
|
-
// calculate_nanny_taxes
|
|
116
|
-
// ---------------------------------------------------------------------------
|
|
117
|
-
describe("executeCalculate (calculate_nanny_taxes)", () => {
|
|
118
|
-
it("returns a formatted JSON result for valid inputs", async () => {
|
|
119
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(CALCULATE_SUCCESS_RESPONSE, 200));
|
|
120
|
-
const result = await executeCalculate({
|
|
121
|
-
state: "CA",
|
|
122
|
-
annual_wages: 30000,
|
|
123
|
-
pay_frequency: "biweekly",
|
|
124
|
-
});
|
|
125
|
-
const parsed = JSON.parse(result);
|
|
126
|
-
expect(parsed.state).toBe("CA");
|
|
127
|
-
expect(parsed.annual_wages).toBe(30000);
|
|
128
|
-
expect(parsed.employer_taxes).toBeDefined();
|
|
129
|
-
expect(parsed.employer_taxes.total).toBeGreaterThan(0);
|
|
130
|
-
expect(parsed.threshold.action_required).toBe(true);
|
|
131
|
-
expect(parsed.next_actions.signup_url).toContain("nannykeeper.com/signup");
|
|
132
|
-
});
|
|
133
|
-
it("uppercases the state code before sending to the API", async () => {
|
|
134
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(CALCULATE_SUCCESS_RESPONSE, 200));
|
|
135
|
-
await executeCalculate({ state: "ca", annual_wages: 30000 });
|
|
136
|
-
const [, init] = global.fetch.mock.calls[0];
|
|
137
|
-
const body = JSON.parse(init.body);
|
|
138
|
-
expect(body.state).toBe("CA");
|
|
139
|
-
});
|
|
140
|
-
it("defaults pay_frequency to biweekly when not provided", async () => {
|
|
141
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(CALCULATE_SUCCESS_RESPONSE, 200));
|
|
142
|
-
await executeCalculate({ state: "NY", annual_wages: 20000 });
|
|
143
|
-
const [, init] = global.fetch.mock.calls[0];
|
|
144
|
-
const body = JSON.parse(init.body);
|
|
145
|
-
expect(body.pay_frequency).toBe("biweekly");
|
|
146
|
-
});
|
|
147
|
-
it("returns a clear error when NANNYKEEPER_API_KEY is not set", async () => {
|
|
148
|
-
delete process.env.NANNYKEEPER_API_KEY;
|
|
149
|
-
const result = await executeCalculate({ state: "TX", annual_wages: 25000 });
|
|
150
|
-
const parsed = JSON.parse(result);
|
|
151
|
-
expect(parsed.error).toContain("NANNYKEEPER_API_KEY");
|
|
152
|
-
expect(parsed.error).toContain("nannykeeper.com/developers/keys");
|
|
153
|
-
});
|
|
154
|
-
it("returns rate limit error on 429 response", async () => {
|
|
155
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({ error: { message: "Too many requests" } }, 429));
|
|
156
|
-
const result = await executeCalculate({ state: "FL", annual_wages: 15000 });
|
|
157
|
-
const parsed = JSON.parse(result);
|
|
158
|
-
expect(parsed.error).toContain("Rate limit exceeded");
|
|
159
|
-
expect(parsed.error).toContain("50 requests/day");
|
|
160
|
-
});
|
|
161
|
-
it("returns server error message on 500 response", async () => {
|
|
162
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({ error: { message: "Internal server error" } }, 500));
|
|
163
|
-
const result = await executeCalculate({ state: "WA", annual_wages: 40000 });
|
|
164
|
-
const parsed = JSON.parse(result);
|
|
165
|
-
expect(parsed.error).toBeTruthy();
|
|
166
|
-
expect(typeof parsed.error).toBe("string");
|
|
167
|
-
});
|
|
168
|
-
it("returns server error using status code when API error body has no message", async () => {
|
|
169
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({}, 500));
|
|
170
|
-
const result = await executeCalculate({ state: "WA", annual_wages: 40000 });
|
|
171
|
-
const parsed = JSON.parse(result);
|
|
172
|
-
expect(parsed.error).toContain("500");
|
|
173
|
-
});
|
|
174
|
-
it("returns a network error when fetch throws", async () => {
|
|
175
|
-
global.fetch = vi.fn().mockRejectedValue(new Error("Connection refused"));
|
|
176
|
-
const result = await executeCalculate({ state: "OR", annual_wages: 10000 });
|
|
177
|
-
const parsed = JSON.parse(result);
|
|
178
|
-
expect(parsed.error).toContain("Network error");
|
|
179
|
-
expect(parsed.error).toContain("Connection refused");
|
|
180
|
-
});
|
|
181
|
-
it("sends the Authorization header with the API key", async () => {
|
|
182
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(CALCULATE_SUCCESS_RESPONSE, 200));
|
|
183
|
-
await executeCalculate({ state: "IL", annual_wages: 35000 });
|
|
184
|
-
const [, init] = global.fetch.mock.calls[0];
|
|
185
|
-
expect(init.headers["Authorization"]).toBe("Bearer test_key_abc123");
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
// ---------------------------------------------------------------------------
|
|
189
|
-
// check_threshold
|
|
190
|
-
// ---------------------------------------------------------------------------
|
|
191
|
-
describe("executeThreshold (check_threshold)", () => {
|
|
192
|
-
it("returns threshold status for valid inputs", async () => {
|
|
193
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(THRESHOLD_SUCCESS_RESPONSE, 200));
|
|
194
|
-
const result = await executeThreshold({ state: "CA", annual_wages: 30000 });
|
|
195
|
-
const parsed = JSON.parse(result);
|
|
196
|
-
expect(parsed.state).toBe("CA");
|
|
197
|
-
expect(parsed.annual_wages).toBe(30000);
|
|
198
|
-
expect(parsed.federal.status).toBe("above");
|
|
199
|
-
expect(parsed.federal.action_required).toBe(true);
|
|
200
|
-
expect(parsed.state_threshold).toBeDefined();
|
|
201
|
-
expect(parsed.state_threshold.threshold_quarterly).toBe(750);
|
|
202
|
-
});
|
|
203
|
-
it("includes tax_year in the response when provided", async () => {
|
|
204
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({ ...THRESHOLD_SUCCESS_RESPONSE, tax_year: 2025 }, 200));
|
|
205
|
-
const result = await executeThreshold({
|
|
206
|
-
state: "NY",
|
|
207
|
-
annual_wages: 5000,
|
|
208
|
-
tax_year: 2025,
|
|
209
|
-
});
|
|
210
|
-
const parsed = JSON.parse(result);
|
|
211
|
-
expect(parsed.tax_year).toBe(2025);
|
|
212
|
-
// Verify tax_year was forwarded in the query string
|
|
213
|
-
const [url] = global.fetch.mock.calls[0];
|
|
214
|
-
expect(url).toContain("tax_year=2025");
|
|
215
|
-
});
|
|
216
|
-
it("uppercases the state code in the query string", async () => {
|
|
217
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(THRESHOLD_SUCCESS_RESPONSE, 200));
|
|
218
|
-
await executeThreshold({ state: "ca", annual_wages: 30000 });
|
|
219
|
-
const [url] = global.fetch.mock.calls[0];
|
|
220
|
-
expect(url).toContain("state=CA");
|
|
221
|
-
expect(url).not.toContain("state=ca");
|
|
222
|
-
});
|
|
223
|
-
it("returns a clear error when NANNYKEEPER_API_KEY is not set", async () => {
|
|
224
|
-
delete process.env.NANNYKEEPER_API_KEY;
|
|
225
|
-
const result = await executeThreshold({ state: "TX", annual_wages: 5000 });
|
|
226
|
-
const parsed = JSON.parse(result);
|
|
227
|
-
expect(parsed.error).toContain("NANNYKEEPER_API_KEY");
|
|
228
|
-
expect(parsed.error).toContain("nannykeeper.com/developers/keys");
|
|
229
|
-
});
|
|
230
|
-
it("returns an API error message on non-ok response", async () => {
|
|
231
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({ error: { message: "Invalid state code" } }, 422));
|
|
232
|
-
const result = await executeThreshold({ state: "ZZ", annual_wages: 5000 });
|
|
233
|
-
const parsed = JSON.parse(result);
|
|
234
|
-
expect(parsed.error).toBe("Invalid state code");
|
|
235
|
-
});
|
|
236
|
-
it("returns rate limit error on 429 response", async () => {
|
|
237
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({ error: { message: "Too many requests" } }, 429));
|
|
238
|
-
const result = await executeThreshold({ state: "FL", annual_wages: 10000 });
|
|
239
|
-
const parsed = JSON.parse(result);
|
|
240
|
-
// The threshold tool falls through to the generic error handler (no special 429 branch)
|
|
241
|
-
expect(parsed.error).toBeTruthy();
|
|
242
|
-
expect(typeof parsed.error).toBe("string");
|
|
243
|
-
});
|
|
244
|
-
it("returns server error on 500 response", async () => {
|
|
245
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({ error: { message: "Internal server error" } }, 500));
|
|
246
|
-
const result = await executeThreshold({ state: "WA", annual_wages: 20000 });
|
|
247
|
-
const parsed = JSON.parse(result);
|
|
248
|
-
expect(parsed.error).toBe("Internal server error");
|
|
249
|
-
});
|
|
250
|
-
it("returns server error using status code when error body has no message", async () => {
|
|
251
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({}, 500));
|
|
252
|
-
const result = await executeThreshold({ state: "WA", annual_wages: 20000 });
|
|
253
|
-
const parsed = JSON.parse(result);
|
|
254
|
-
expect(parsed.error).toContain("500");
|
|
255
|
-
});
|
|
256
|
-
it("returns a network error when fetch throws", async () => {
|
|
257
|
-
global.fetch = vi.fn().mockRejectedValue(new Error("DNS lookup failed"));
|
|
258
|
-
const result = await executeThreshold({ state: "AZ", annual_wages: 5000 });
|
|
259
|
-
const parsed = JSON.parse(result);
|
|
260
|
-
expect(parsed.error).toContain("Network error");
|
|
261
|
-
expect(parsed.error).toContain("DNS lookup failed");
|
|
262
|
-
});
|
|
263
|
-
it("omits tax_year from query string when not provided", async () => {
|
|
264
|
-
global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(THRESHOLD_SUCCESS_RESPONSE, 200));
|
|
265
|
-
await executeThreshold({ state: "TX", annual_wages: 5000 });
|
|
266
|
-
const [url] = global.fetch.mock.calls[0];
|
|
267
|
-
expect(url).not.toContain("tax_year");
|
|
268
|
-
});
|
|
269
|
-
});
|