liveperson-functions-client
Version:
JavaScript client for LivePerson Functions.
132 lines • 4.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const client_1 = require("../../src/client/client");
const functionUUID = process.env['FUNCTION_UUID'] || 'does-not-exist';
const accountId = process.env['ACCOUNT_ID'] || 'does-not-exist';
const clientId = process.env['CLIENT_ID'] || 'does-not-exist';
const clientSecret = process.env['CLIENT_SECRET'] || 'does-not-exist';
const appJwtCredentials = {
clientId,
clientSecret,
};
describe('V2 Invoke by UUID', () => {
it('should invoke and get result via AppJwt', async () => {
const lpEventSource = 'integration-tests';
let onInvokeCalled = false;
let onIsImplementedCalled = false;
class MyMetricCollector {
onInvoke(invocationData) {
expect(invocationData.lpEventSource).toEqual(lpEventSource);
expect(invocationData.externalSystem).toBeUndefined();
onInvokeCalled = true;
return;
}
onGetLambdas(invocationData) {
return;
}
onIsImplemented(invocationData) {
onIsImplementedCalled = true;
return;
}
}
const client = new client_1.Client({
accountId,
authStrategy: appJwtCredentials,
failOnErrorStatusCode: true,
}, {
metricCollector: new MyMetricCollector(),
});
const payload = {
foo: 'bar',
};
const isImplemented = await client.isImplemented({
eventId: 'conversational_command',
lpEventSource: 'integration-tests',
});
const response = await client.invoke({
lambdaUuid: functionUUID,
lpEventSource: 'integration-tests',
body: {
headers: [],
payload,
},
});
expect(response.ok).toEqual(true);
expect(onInvokeCalled).toEqual(true);
expect(isImplemented).toEqual(true);
expect(onIsImplementedCalled).toEqual(true);
});
it('should fail if lambda returns 901 error', async () => {
const client = new client_1.Client({
accountId,
authStrategy: appJwtCredentials,
failOnErrorStatusCode: true,
});
const payload = {
foo: 'bar',
};
try {
await client.invoke({
lambdaUuid: functionUUID,
externalSystem: 'integration-tests',
body: {
headers: [{ key: "run", value: "error" }],
payload,
},
});
fail('should fail');
}
catch (error) {
expect(error === null || error === void 0 ? void 0 : error.name).toEqual('FaaSLambdaError');
expect(error === null || error === void 0 ? void 0 : error.message).toStartWith(`Failed to invoke lambda : ${functionUUID}`);
}
});
it('should fail if lambda does not exist', async () => {
const nonExistingLambda = 'c521cadf-d444-4519-ad11-1c1111114415';
const client = new client_1.Client({
accountId,
authStrategy: appJwtCredentials,
failOnErrorStatusCode: true,
});
const payload = {
foo: 'bar',
};
try {
await client.invoke({
lambdaUuid: nonExistingLambda,
externalSystem: 'integration-tests',
body: {
headers: [],
payload,
},
});
fail('should fail');
}
catch (error) {
expect(error === null || error === void 0 ? void 0 : error.name).toEqual('FaaSInvokeError');
expect(error === null || error === void 0 ? void 0 : error.message).toContain(`404`);
}
});
});
describe('V2 Invoke by event id', () => {
it('should invoke and get result', async () => {
const client = new client_1.Client({
accountId,
authStrategy: appJwtCredentials,
failOnErrorStatusCode: true,
});
const payload = {
foo: 'bar',
};
const response = await client.invoke({
eventId: 'conversational_command',
externalSystem: 'integration-tests',
body: {
headers: [],
payload,
},
});
expect(response.ok).toEqual(true);
});
});
//# sourceMappingURL=invoke.v2.test.js.map