Skip to content

Commit a89bd4c

Browse files
authored
test(HRIS): add test suite for "create employee" flow (#18)
1 parent 980d1cc commit a89bd4c

File tree

2 files changed

+179
-0
lines changed

2 files changed

+179
-0
lines changed

mise.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
[tasks."dev"]
55
description = "Build the SDK without publishing"
66
run = 'OPENAPI_DOC_AUTH_TOKEN="$(doppler secrets get SDK_SPEC_ENDPOINT_TOKEN --project kombo-engine --config dev --plain)" speakeasy run --minimal --skip-upload-spec --skip-versioning --skip-compile --target kombo-typescript'
7+
8+
[tasks."test"]
9+
description = "Run the test suite"
10+
run = "npm test"

tests/employee-form-flow.spec.ts

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
import { it, expect } from "vitest";
2+
import { TestContext, describeSdkSuite } from "./helpers/test-context";
3+
4+
describeSdkSuite("Employee Form Flow", () => {
5+
it("should get employee form and return form response", async () => {
6+
const ctx = new TestContext();
7+
8+
ctx.mockEndpoint({
9+
method: "GET",
10+
path: "/v1/hris/employees/form",
11+
response: {
12+
body: {
13+
status: "success",
14+
data: {
15+
properties: {
16+
firstName: {
17+
type: "text",
18+
label: "First Name",
19+
required: true,
20+
description: "Employee's first name",
21+
unified_key: "first_name",
22+
min_length: 1,
23+
max_length: 100,
24+
},
25+
lastName: {
26+
type: "text",
27+
label: "Last Name",
28+
required: true,
29+
description: "Employee's last name",
30+
unified_key: "last_name",
31+
min_length: 1,
32+
max_length: 100,
33+
},
34+
startDate: {
35+
type: "date",
36+
label: "Start Date",
37+
required: true,
38+
description: "Employee's start date",
39+
unified_key: "start_date",
40+
},
41+
keyNumbers: {
42+
type: "array",
43+
label: "Key Numbers",
44+
required: false,
45+
description: "Employee's key numbers",
46+
unified_key: null,
47+
min_items: 2,
48+
max_items: 5,
49+
item_type: {
50+
type: "number",
51+
label: "Key Number",
52+
required: false,
53+
description: "The number of the keys which belong to the employee",
54+
unified_key: null,
55+
min: 0,
56+
max: 99,
57+
},
58+
},
59+
workLocation: {
60+
type: "object",
61+
label: "Work Location",
62+
required: false,
63+
description: "Employee's work location",
64+
unified_key: null,
65+
properties: {
66+
site: {
67+
type: "single_select",
68+
label: "Site",
69+
required: true,
70+
description: "Employee's site",
71+
unified_key: null,
72+
options: {
73+
type: "inline",
74+
entries: [
75+
{
76+
label: "Site 1",
77+
id: "FXrER44xubBqA9DLgZ3PFNNx",
78+
unified_value: "1",
79+
remote_id: "site_1",
80+
},
81+
{
82+
label: "Site 2",
83+
id: "2rv75UKT2XBoQXsUb9agiTUm",
84+
unified_value: "2",
85+
remote_id: "site_2",
86+
},
87+
],
88+
},
89+
},
90+
},
91+
},
92+
},
93+
},
94+
warnings: [],
95+
},
96+
},
97+
});
98+
99+
// Make the API call
100+
const form = await ctx.kombo.hris.getEmployeeForm();
101+
102+
// Verify the response structure
103+
expect(form).toBeDefined();
104+
expect(form.status).toBe("success");
105+
expect(form.data).toBeDefined();
106+
expect(form.data.properties.firstName).toBeDefined();
107+
expect(form.data.properties.keyNumbers).toBeDefined();
108+
expect(form.warnings).toEqual([]);
109+
});
110+
111+
it("should create employee with form using realistic employee data", async () => {
112+
const ctx = new TestContext();
113+
114+
ctx.mockEndpoint({
115+
method: "POST",
116+
path: "/v1/hris/employees/form",
117+
response: {
118+
body: {
119+
status: "success",
120+
data: {
121+
id: "emp-123",
122+
remote_id: "remote-emp-123",
123+
prehire: {
124+
remote_id: null,
125+
},
126+
},
127+
warnings: [],
128+
},
129+
},
130+
});
131+
132+
// Make the API call with realistic employee properties
133+
const result = await ctx.kombo.hris.createEmployeeWithForm({
134+
properties: {
135+
firstName: "John",
136+
lastName: "Doe",
137+
startDate: "2025-01-15",
138+
keyNumbers: [142, 525, 63],
139+
workLocation: {
140+
site: "FXrER44xubBqA9DLgZ3PFNNx",
141+
},
142+
},
143+
});
144+
145+
// Verify the response structure
146+
expect(result).toBeDefined();
147+
expect(result.status).toBe("success");
148+
expect(result.data).toBeDefined();
149+
expect(result.data.id).toBe("emp-123");
150+
expect(result.data.remote_id).toBe("remote-emp-123");
151+
expect(result.warnings).toEqual([]);
152+
153+
// Verify request body is correctly serialized
154+
const request = ctx.getLastRequest();
155+
expect(request.method).toBe("POST");
156+
expect(request.body).toMatchInlineSnapshot(`
157+
{
158+
"properties": {
159+
"firstName": "John",
160+
"keyNumbers": [
161+
142,
162+
525,
163+
63,
164+
],
165+
"lastName": "Doe",
166+
"startDate": "2025-01-15",
167+
"workLocation": {
168+
"site": "FXrER44xubBqA9DLgZ3PFNNx",
169+
},
170+
},
171+
}
172+
`);
173+
});
174+
});
175+

0 commit comments

Comments
 (0)