-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add handling of execution versions + step schemas when fetching via API
- Loading branch information
1 parent
4f8776a
commit be4971c
Showing
5 changed files
with
168 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,121 @@ | ||
import { stepsSchema } from "./schema"; | ||
|
||
describe("stepsSchema", () => { | ||
test("handles v1 { data } objects", () => { | ||
const expected = { | ||
id: { | ||
type: "data", | ||
data: "something", | ||
}, | ||
}; | ||
|
||
const actual = stepsSchema.safeParse({ | ||
id: { | ||
data: "something", | ||
}, | ||
import { stepsSchemas } from "@local/api/schema"; | ||
import { ExecutionVersion } from "@local/components/execution/InngestExecution"; | ||
|
||
describe("stepsSchemas", () => { | ||
describe("v0", () => { | ||
const schema = stepsSchemas[ExecutionVersion.V0]; | ||
|
||
test("handles any data", () => { | ||
const expected = { | ||
id: "something", | ||
id2: "something else", | ||
id3: true, | ||
id4: { data: false }, | ||
}; | ||
|
||
const actual = schema.safeParse({ | ||
id: "something", | ||
id2: "something else", | ||
id3: true, | ||
id4: { data: false }, | ||
}); | ||
|
||
expect(actual.success).toBe(true); | ||
expect(actual.success && actual.data).toEqual(expected); | ||
}); | ||
|
||
expect(actual.success).toBe(true); | ||
expect(actual.success && actual.data).toEqual(expected); | ||
test("throws if finding undefined value", () => { | ||
const result = schema.safeParse({ | ||
id: "something", | ||
id2: undefined, | ||
}); | ||
|
||
expect(result.success).toBe(false); | ||
}); | ||
}); | ||
|
||
test("handles v1 { error } objects", () => { | ||
const expected = { | ||
id: { | ||
type: "error", | ||
error: { | ||
name: "Error", | ||
message: "something", | ||
describe("v1", () => { | ||
const schema = stepsSchemas[ExecutionVersion.V1]; | ||
|
||
test("handles v1 { data } objects", () => { | ||
const expected = { | ||
id: { | ||
type: "data", | ||
data: "something", | ||
}, | ||
}, | ||
}; | ||
|
||
const actual = stepsSchema.safeParse({ | ||
id: { | ||
error: { | ||
name: "Error", | ||
message: "something", | ||
}; | ||
|
||
const actual = schema.safeParse({ | ||
id: { | ||
data: "something", | ||
}, | ||
}, | ||
}); | ||
|
||
expect(actual.success).toBe(true); | ||
expect(actual.success && actual.data).toEqual(expected); | ||
}); | ||
|
||
expect(actual.success).toBe(true); | ||
expect(actual.success && actual.data).toEqual(expected); | ||
}); | ||
test("handles null from a v0 or v1 sleep or waitForEvent", () => { | ||
const expected = { | ||
id: { | ||
type: "data", | ||
data: null, | ||
}, | ||
}; | ||
|
||
const actual = stepsSchema.safeParse({ | ||
id: null, | ||
test("handles v1 { error } objects", () => { | ||
const expected = { | ||
id: { | ||
type: "error", | ||
error: { | ||
name: "Error", | ||
message: "something", | ||
}, | ||
}, | ||
}; | ||
|
||
const actual = schema.safeParse({ | ||
id: { | ||
error: { | ||
name: "Error", | ||
message: "something", | ||
}, | ||
}, | ||
}); | ||
|
||
expect(actual.success).toBe(true); | ||
expect(actual.success && actual.data).toEqual(expected); | ||
}); | ||
test("handles null from a v0 or v1 sleep or waitForEvent", () => { | ||
const expected = { | ||
id: { | ||
type: "data", | ||
data: null, | ||
}, | ||
}; | ||
|
||
expect(actual.success).toBe(true); | ||
expect(actual.success && actual.data).toEqual(expected); | ||
}); | ||
const actual = schema.safeParse({ | ||
id: null, | ||
}); | ||
|
||
test("handles event from v0 or v1 waitForEvent", () => { | ||
const expected = { | ||
id: { | ||
type: "data", | ||
data: { | ||
expect(actual.success).toBe(true); | ||
expect(actual.success && actual.data).toEqual(expected); | ||
}); | ||
|
||
test("handles event from v0 or v1 waitForEvent", () => { | ||
const expected = { | ||
id: { | ||
type: "data", | ||
data: { | ||
name: "event", | ||
data: { some: "data" }, | ||
ts: 123, | ||
}, | ||
}, | ||
}; | ||
|
||
const actual = schema.safeParse({ | ||
id: { | ||
name: "event", | ||
data: { some: "data" }, | ||
ts: 123, | ||
}, | ||
}, | ||
}; | ||
|
||
const actual = stepsSchema.safeParse({ | ||
id: { | ||
name: "event", | ||
data: { some: "data" }, | ||
ts: 123, | ||
}, | ||
}); | ||
}); | ||
|
||
expect(actual.success).toBe(true); | ||
expect(actual.success && actual.data).toEqual(expected); | ||
expect(actual.success).toBe(true); | ||
expect(actual.success && actual.data).toEqual(expected); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters