@tailor-platform/create-sdk 1.4.1 → 1.5.0
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/CHANGELOG.md +17 -0
- package/package.json +1 -1
- package/templates/hello-world/package.json +1 -1
- package/templates/hello-world/tsconfig.json +1 -1
- package/templates/inventory-management/package.json +1 -1
- package/templates/multi-application/package.json +1 -1
- package/templates/multi-application/tsconfig.json +1 -1
- package/templates/testing/package.json +1 -1
- package/templates/testing/src/workflow/trigger.test.ts +67 -0
- package/templates/testing/tailor.config.ts +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @tailor-platform/create-sdk
|
|
2
2
|
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#478](https://github.com/tailor-platform/sdk/pull/478) [`dce0040`](https://github.com/tailor-platform/sdk/commit/dce0040f0477c2603b604ab3aac17383ec03f3e7) Thanks [@toiroakr](https://github.com/toiroakr)! - Add local testing support for workflows
|
|
8
|
+
|
|
9
|
+
- `createWorkflowJob`: `.trigger()` now executes body directly for local testing
|
|
10
|
+
- `createWorkflow`: `.trigger()` now calls `mainJob.trigger()` for local testing
|
|
11
|
+
- Export `WORKFLOW_TEST_ENV_KEY` from `@tailor-platform/sdk/test` for env configuration
|
|
12
|
+
- Add workflow trigger test examples to testing template
|
|
13
|
+
|
|
14
|
+
## 1.4.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [#475](https://github.com/tailor-platform/sdk/pull/475) [`d8b0ab0`](https://github.com/tailor-platform/sdk/commit/d8b0ab07c417eb932f58a58e2a5cb59e6cee2fa0) Thanks [@haru0017](https://github.com/haru0017)! - Remove unused @tailor-platform/function-types from hello-world and multi-application template
|
|
19
|
+
|
|
3
20
|
## 1.4.1
|
|
4
21
|
|
|
5
22
|
## 1.4.0
|
package/package.json
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This test file demonstrates how to test workflows using the .trigger() method.
|
|
3
|
+
*
|
|
4
|
+
* Key features:
|
|
5
|
+
* - Use vi.stubEnv() with WORKFLOW_TEST_ENV_KEY to set environment variables
|
|
6
|
+
* - Use vi.spyOn() to mock dependent jobs
|
|
7
|
+
* - Call .trigger() on jobs/workflows directly
|
|
8
|
+
*/
|
|
9
|
+
import { WORKFLOW_TEST_ENV_KEY } from "@tailor-platform/sdk/test";
|
|
10
|
+
import { afterEach, describe, expect, test, vi } from "vitest";
|
|
11
|
+
import workflow, { addNumbers, calculate, multiplyNumbers } from "./simple";
|
|
12
|
+
|
|
13
|
+
describe("workflow trigger tests", () => {
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
vi.unstubAllEnvs();
|
|
16
|
+
vi.restoreAllMocks();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("unit tests with .body()", () => {
|
|
20
|
+
test("addNumbers.body() adds two numbers", () => {
|
|
21
|
+
const result = addNumbers.body({ a: 2, b: 3 }, { env: {} });
|
|
22
|
+
expect(result).toBe(5);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("multiplyNumbers.body() multiplies two numbers", () => {
|
|
26
|
+
const result = multiplyNumbers.body({ x: 4, y: 5 }, { env: {} });
|
|
27
|
+
expect(result).toBe(20);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("calculate.body() with mocked dependent jobs", async () => {
|
|
31
|
+
// Mock the trigger methods for dependent jobs
|
|
32
|
+
vi.spyOn(addNumbers, "trigger").mockResolvedValue(5);
|
|
33
|
+
vi.spyOn(multiplyNumbers, "trigger").mockResolvedValue(10);
|
|
34
|
+
|
|
35
|
+
const result = await calculate.body({ a: 2, b: 3 }, { env: {} });
|
|
36
|
+
|
|
37
|
+
expect(addNumbers.trigger).toHaveBeenCalledWith({ a: 2, b: 3 });
|
|
38
|
+
expect(multiplyNumbers.trigger).toHaveBeenCalledWith({ x: 5, y: 2 });
|
|
39
|
+
expect(result).toBe(10);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("workflow tests", () => {
|
|
44
|
+
test("workflow.mainJob.body() with mocked dependent jobs", async () => {
|
|
45
|
+
// Mock the trigger methods for dependent jobs
|
|
46
|
+
vi.spyOn(addNumbers, "trigger").mockResolvedValue(7);
|
|
47
|
+
vi.spyOn(multiplyNumbers, "trigger").mockResolvedValue(21);
|
|
48
|
+
|
|
49
|
+
const result = await workflow.mainJob.body({ a: 3, b: 4 }, { env: {} });
|
|
50
|
+
|
|
51
|
+
expect(addNumbers.trigger).toHaveBeenCalledWith({ a: 3, b: 4 });
|
|
52
|
+
expect(multiplyNumbers.trigger).toHaveBeenCalledWith({ x: 7, y: 3 });
|
|
53
|
+
expect(result).toBe(21);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("workflow.trigger() executes all jobs (integration)", async () => {
|
|
57
|
+
// stubEnv ensures all dependent jobs' .trigger() calls use the same env
|
|
58
|
+
vi.stubEnv(WORKFLOW_TEST_ENV_KEY, JSON.stringify({ NODE_ENV: "test" }));
|
|
59
|
+
|
|
60
|
+
// No mocking - all jobs execute their actual body functions
|
|
61
|
+
const result = await workflow.mainJob.trigger({ a: 3, b: 4 });
|
|
62
|
+
|
|
63
|
+
// (3 + 4) * 3 = 21
|
|
64
|
+
expect(result).toBe(21);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import { defineAuth, defineConfig, defineGenerators } from "@tailor-platform/sdk";
|
|
1
|
+
import { defineAuth, defineConfig, defineGenerators, t } from "@tailor-platform/sdk";
|
|
2
2
|
|
|
3
3
|
export default defineConfig({
|
|
4
4
|
name: "testing",
|
|
5
5
|
auth: defineAuth("main-auth", {
|
|
6
|
+
machineUserAttributes: {
|
|
7
|
+
role: t.string(),
|
|
8
|
+
},
|
|
6
9
|
machineUsers: {
|
|
7
10
|
admin: {
|
|
8
|
-
attributes: {
|
|
11
|
+
attributes: {
|
|
12
|
+
role: "admin",
|
|
13
|
+
},
|
|
9
14
|
},
|
|
10
15
|
},
|
|
11
16
|
}),
|