-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(framework, node): Make the
payload
property optional during tri…
…gger (#6384)
- Loading branch information
Showing
13 changed files
with
345 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ logs | |
|
||
# Misc | ||
.DS_Store | ||
|
||
# Vitest | ||
tsconfig.vitest-temp.json |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ describe('workflow function', () => { | |
type: 'object', | ||
properties: { | ||
foo: { type: 'number' }, | ||
bar: { type: 'string' }, | ||
bar: { type: 'string', default: 'baz' }, | ||
}, | ||
required: ['foo', 'bar'], | ||
additionalProperties: false, | ||
|
@@ -171,6 +171,75 @@ describe('workflow function', () => { | |
}); | ||
}); | ||
|
||
it('should not compile when the payload is not specified and the payloadSchema declares required properties', async () => { | ||
const testWorkflow = workflow( | ||
'test-workflow', | ||
async ({ step, payload }) => { | ||
await step.custom('custom', async () => ({ | ||
foo: 'bar', | ||
})); | ||
}, | ||
{ | ||
payloadSchema: { | ||
type: 'object', | ||
properties: { | ||
foo: { type: 'string' }, | ||
}, | ||
required: ['foo'], | ||
additionalProperties: false, | ||
} as const, | ||
} | ||
); | ||
|
||
// Capture in a test function to avoid throwing execution errors | ||
const testFn = () => | ||
testWorkflow.trigger({ | ||
// @ts-expect-error - payload is missing from the trigger | ||
payload: undefined, | ||
to: '[email protected]', | ||
}); | ||
}); | ||
|
||
it('should compile when the payload is not specified and the payloadSchema does not declare required properties', async () => { | ||
const testWorkflow = workflow( | ||
'test-workflow', | ||
async ({ step, payload }) => { | ||
await step.custom('custom', async () => ({ | ||
foo: 'bar', | ||
})); | ||
}, | ||
{ | ||
payloadSchema: { | ||
type: 'object', | ||
properties: { | ||
foo: { type: 'string' }, | ||
}, | ||
additionalProperties: false, | ||
} as const, | ||
} | ||
); | ||
|
||
// Capture in a test function to avoid throwing execution errors | ||
const testFn = () => | ||
testWorkflow.trigger({ | ||
to: '[email protected]', | ||
}); | ||
}); | ||
|
||
it('should compile when the payload is not specified and the payloadSchema is not specified', async () => { | ||
const testWorkflow = workflow('test-workflow', async ({ step, payload }) => { | ||
await step.custom('custom', async () => ({ | ||
foo: 'bar', | ||
})); | ||
}); | ||
|
||
// Capture in a test function to avoid throwing execution errors | ||
const testFn = () => | ||
testWorkflow.trigger({ | ||
to: '[email protected]', | ||
}); | ||
}); | ||
|
||
it('should throw an error when the NOVU_SECRET_KEY is not set', async () => { | ||
const originalEnv = process.env.NOVU_SECRET_KEY; | ||
delete process.env.NOVU_SECRET_KEY; | ||
|
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
Oops, something went wrong.