@prismatic-io/spectral 8.1.0-preview2 → 8.1.0-preview4
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/dist/testing.d.ts +7 -1
- package/dist/testing.js +14 -4
- package/package.json +1 -1
package/dist/testing.d.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, ActionContext, ActionPerformReturn, DataSourceResult, DataSourceContext } from "./serverTypes";
|
|
8
8
|
import { ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceResult as InvokeDataSourceResult, TriggerEventFunctionReturn, Flow, ConfigVarResultCollection, ConfigPages, ComponentSelector } from "./types";
|
|
9
9
|
export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>, tokenValues?: Record<string, unknown> | undefined) => ConnectionValue;
|
|
10
|
+
export declare const defaultConnectionValueEnvironmentVariable = "PRISMATIC_CONNECTION_VALUE";
|
|
11
|
+
export declare const connectionValue: (envVarKey?: string) => ConnectionValue;
|
|
10
12
|
/**
|
|
11
13
|
* Pre-built mock of ActionLogger. Suitable for asserting logs are created as expected.
|
|
12
14
|
* See https://prismatic.io/docs/custom-components/writing-custom-components/#verifying-correct-logging-in-action-tests for information on testing correct logging behavior in your custom component.
|
|
@@ -63,7 +65,11 @@ declare type ToTestValues<TConfigVars extends ConfigVarResultCollection> = {
|
|
|
63
65
|
* Invokes specified Flow of a Code Native Integration using supplied params.
|
|
64
66
|
* Runs the Trigger and then the Action function and returns the result of the Action.
|
|
65
67
|
*/
|
|
66
|
-
export declare const invokeFlow: <TConfigPages extends ConfigPages<any>, TConfigVars extends ConfigVarResultCollection = import("./types/utils").Prettify<{ [Key in keyof import("./types").GetElements<TConfigPages> as Key extends string ? Key : never]: import("./types").ElementToRuntimeType<import("./types").GetElements<TConfigPages>[Key]>; }>, TConfigVarValues extends TestConfigVarValues = ToTestValues<TConfigVars>>(flow: Flow<TConfigPages, ComponentSelector<any>, import("./types").TriggerPayload>, configVars
|
|
68
|
+
export declare const invokeFlow: <TConfigPages extends ConfigPages<any>, TConfigVars extends ConfigVarResultCollection = import("./types/utils").Prettify<{ [Key in keyof import("./types").GetElements<TConfigPages> as Key extends string ? Key : never]: import("./types").ElementToRuntimeType<import("./types").GetElements<TConfigPages>[Key]>; }>, TConfigVarValues extends TestConfigVarValues = ToTestValues<TConfigVars>>(flow: Flow<TConfigPages, ComponentSelector<any>, import("./types").TriggerPayload>, { configVars, context, payload, }?: {
|
|
69
|
+
configVars?: TConfigVarValues | undefined;
|
|
70
|
+
context?: Partial<ActionContext<TConfigVars>> | undefined;
|
|
71
|
+
payload?: Partial<TriggerPayload> | undefined;
|
|
72
|
+
}) => Promise<InvokeReturn<InvokeActionPerformReturn<false, unknown>>>;
|
|
67
73
|
export declare class ComponentTestHarness<TComponent extends Component> {
|
|
68
74
|
component: TComponent;
|
|
69
75
|
constructor(component: TComponent);
|
package/dist/testing.js
CHANGED
|
@@ -15,7 +15,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.createHarness = exports.ComponentTestHarness = exports.invokeFlow = exports.invokeDataSource = exports.invokeTrigger = exports.defaultTriggerPayload = exports.invoke = exports.loggerMock = exports.createConnection = void 0;
|
|
18
|
+
exports.createHarness = exports.ComponentTestHarness = exports.invokeFlow = exports.invokeDataSource = exports.invokeTrigger = exports.defaultTriggerPayload = exports.invoke = exports.loggerMock = exports.connectionValue = exports.defaultConnectionValueEnvironmentVariable = exports.createConnection = void 0;
|
|
19
19
|
const jest_mock_1 = require("jest-mock");
|
|
20
20
|
const createConnection = ({ key }, values, tokenValues) => ({
|
|
21
21
|
configVarKey: "",
|
|
@@ -24,6 +24,16 @@ const createConnection = ({ key }, values, tokenValues) => ({
|
|
|
24
24
|
token: tokenValues,
|
|
25
25
|
});
|
|
26
26
|
exports.createConnection = createConnection;
|
|
27
|
+
exports.defaultConnectionValueEnvironmentVariable = "PRISMATIC_CONNECTION_VALUE";
|
|
28
|
+
const connectionValue = (envVarKey = exports.defaultConnectionValueEnvironmentVariable) => {
|
|
29
|
+
const value = process.env[envVarKey];
|
|
30
|
+
if (!value) {
|
|
31
|
+
throw new Error("Unable to find connection value.");
|
|
32
|
+
}
|
|
33
|
+
const result = Object.assign(Object.assign({}, JSON.parse(value)), { key: "" });
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
exports.connectionValue = connectionValue;
|
|
27
37
|
/**
|
|
28
38
|
* Pre-built mock of ActionLogger. Suitable for asserting logs are created as expected.
|
|
29
39
|
* See https://prismatic.io/docs/custom-components/writing-custom-components/#verifying-correct-logging-in-action-tests for information on testing correct logging behavior in your custom component.
|
|
@@ -178,7 +188,7 @@ const invokeDataSource = ({ perform }, params, context) => __awaiter(void 0, voi
|
|
|
178
188
|
});
|
|
179
189
|
exports.invokeDataSource = invokeDataSource;
|
|
180
190
|
const createConfigVars = (values) => {
|
|
181
|
-
return Object.entries(values).reduce((result, [key, value]) => {
|
|
191
|
+
return Object.entries(values !== null && values !== void 0 ? values : {}).reduce((result, [key, value]) => {
|
|
182
192
|
// Connection
|
|
183
193
|
if (typeof value === "object" && "fields" in value) {
|
|
184
194
|
return Object.assign(Object.assign({}, result), { [key]: Object.assign(Object.assign({}, value), { key, configVarKey: "" }) });
|
|
@@ -190,12 +200,12 @@ const createConfigVars = (values) => {
|
|
|
190
200
|
* Invokes specified Flow of a Code Native Integration using supplied params.
|
|
191
201
|
* Runs the Trigger and then the Action function and returns the result of the Action.
|
|
192
202
|
*/
|
|
193
|
-
const invokeFlow = (flow, configVars, context, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
203
|
+
const invokeFlow = (flow, { configVars, context, payload, } = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
194
204
|
const realizedConfigVars = createConfigVars(configVars);
|
|
195
205
|
const realizedContext = createActionContext(Object.assign(Object.assign({}, context), { configVars: realizedConfigVars }));
|
|
196
206
|
const realizedPayload = Object.assign(Object.assign({}, (0, exports.defaultTriggerPayload)()), payload);
|
|
197
207
|
const params = {
|
|
198
|
-
onTrigger: { results:
|
|
208
|
+
onTrigger: { results: realizedPayload },
|
|
199
209
|
};
|
|
200
210
|
if ("onTrigger" in flow && typeof flow.onTrigger === "function") {
|
|
201
211
|
const triggerResult = yield flow.onTrigger(realizedContext, realizedPayload, params);
|