forked from novuhq/novu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(framework): Stop requiring default properties to be specified in …
…outputs (novuhq#6373)
- Loading branch information
Showing
12 changed files
with
227 additions
and
68 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 |
---|---|---|
|
@@ -633,6 +633,8 @@ | |
"unpublish", | ||
"unsub", | ||
"untracked", | ||
"unvalidated", | ||
"Unvalidated", | ||
"upsert", | ||
"upserted", | ||
"upstash", | ||
|
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 |
---|---|---|
|
@@ -62,6 +62,41 @@ describe('workflow function', () => { | |
result?.foo === 'custom'; | ||
}); | ||
}); | ||
|
||
it('should compile when returning undefined for a built-in step property that has a default value', async () => { | ||
const delayType = undefined; | ||
workflow('built-in-default-test', async ({ step }) => { | ||
await step.delay('custom', async () => ({ | ||
type: delayType, | ||
amount: 1, | ||
unit: 'seconds', | ||
})); | ||
}); | ||
}); | ||
|
||
it('should compile when returning undefined for a custom step property that has a default value', async () => { | ||
const delayType = undefined; | ||
workflow('custom-default-test', async ({ step }) => { | ||
const data = await step.custom( | ||
'custom', | ||
async () => ({ | ||
withDefault: undefined, | ||
withoutDefault: 'bar', | ||
}), | ||
{ | ||
outputSchema: { | ||
type: 'object', | ||
properties: { | ||
withDefault: { type: 'string', default: 'bar' }, | ||
withoutDefault: { type: 'string' }, | ||
}, | ||
required: ['withoutDefault'], | ||
additionalProperties: false, | ||
} as const, | ||
} | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('trigger', () => { | ||
|
@@ -104,6 +139,38 @@ describe('workflow function', () => { | |
}); | ||
}); | ||
|
||
it('should compile when returning undefined for a payload property that has a default value', async () => { | ||
const testWorkflow = workflow( | ||
'test-workflow', | ||
async ({ step }) => { | ||
await step.custom('custom', async () => ({ | ||
foo: 'bar', | ||
})); | ||
}, | ||
{ | ||
payloadSchema: { | ||
type: 'object', | ||
properties: { | ||
withDefault: { type: 'string', default: 'bar' }, | ||
withoutDefault: { type: 'string' }, | ||
}, | ||
required: ['withoutDefault'], | ||
additionalProperties: false, | ||
} as const, | ||
} | ||
); | ||
|
||
// Capture in a test function to avoid throwing execution errors | ||
const testFn = () => | ||
testWorkflow.trigger({ | ||
payload: { | ||
withDefault: undefined, | ||
withoutDefault: 'bar', | ||
}, | ||
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
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.