Skip to content

Commit

Permalink
Add test harness functions to test trigger onInstanceDeploy and onIns…
Browse files Browse the repository at this point in the history
…tanceDelete functions (#150)
  • Loading branch information
taylorreece authored Oct 24, 2023
1 parent 6619da0 commit 661630e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/spectral/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prismatic-io/spectral",
"version": "7.8.1",
"version": "7.8.2",
"description": "Utility library for building Prismatic components",
"keywords": [
"prismatic"
Expand Down
31 changes: 31 additions & 0 deletions packages/spectral/src/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
TriggerResult as InvokeTriggerResult,
DataSourceType,
DataSourceResult as InvokeDataSourceResult,
TriggerEventFunctionReturn,
} from "./types";
import { spyOn } from "jest-mock";

Expand Down Expand Up @@ -311,6 +312,36 @@ export class ComponentTestHarness<TComponent extends Component> {
);
}

public async triggerOnInstanceDeploy(
key: string,
params?: Record<string, unknown>,
context?: Partial<ActionContext>
): Promise<void | TriggerEventFunctionReturn> {
const trigger = this.component.triggers[key];
if (!trigger.onInstanceDeploy) {
throw new Error("Trigger does not support onInstanceDeploy");
}
return trigger.onInstanceDeploy(
this.buildContext<ActionContext>(baseActionContext, context),
this.buildParams(trigger.inputs, params)
);
}

public async triggerOnInstanceDelete(
key: string,
params?: Record<string, unknown>,
context?: Partial<ActionContext>
): Promise<void | TriggerEventFunctionReturn> {
const trigger = this.component.triggers[key];
if (!trigger.onInstanceDelete) {
throw new Error("Trigger does not support onInstanceDelete");
}
return trigger.onInstanceDelete(
this.buildContext<ActionContext>(baseActionContext, context),
this.buildParams(trigger.inputs, params)
);
}

public async action(
key: string,
params?: Record<string, unknown>,
Expand Down

0 comments on commit 661630e

Please sign in to comment.