liveperson-functions-client
Version:
JavaScript client for LivePerson Functions.
76 lines • 2.95 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const client_1 = require("../../src/client/client");
const helper_1 = require("./helper");
const accountId = process.env['ACCOUNT_ID'] || 'does-not-exist';
const username = process.env['USER_NAME'] || 'does-not-exist';
const password = process.env['PASSWORD'] || 'does-not-exist';
const userId = process.env['USER_ID'] || 'does-not-exist';
let bearer = '';
describe('Get Functions V2', () => {
beforeAll(async () => {
bearer = await (0, helper_1.getBearer)(accountId, username, password);
});
it('should get V2 functions', async () => {
// custom auth implementation start
const getAuthorizationHeader = async ({ url, method, }) => {
return new Promise((resolve, reject) => {
resolve(`Bearer ${bearer}`);
});
};
const client = new client_1.Client({
accountId,
authStrategy: getAuthorizationHeader,
failOnErrorStatusCode: true,
});
const response = await client.getFunctions({
lpEventSource: 'tests',
userId,
});
expect(response.ok).toEqual(true);
expect(Array.isArray(response.body)).toEqual(true);
});
it('should get V2 functions using deprecated getLambdas method', async () => {
// custom auth implementation start
const getAuthorizationHeader = async ({ url, method, }) => {
return new Promise((resolve, reject) => {
resolve(`Bearer ${bearer}`);
});
};
const client = new client_1.Client({
accountId,
authStrategy: getAuthorizationHeader,
failOnErrorStatusCode: true,
});
const response = await client.getLambdas({
externalSystem: 'tests',
userId,
});
expect(response.ok).toEqual(true);
expect(Array.isArray(response.body)).toEqual(true);
});
it('should get V2 functions unauthorized', async () => {
// custom auth implementation start
const getAuthorizationHeader = async ({ url, method, }) => {
return new Promise((resolve, reject) => {
resolve(`Bearer wrong-bearer`);
});
};
const client = new client_1.Client({
accountId,
authStrategy: getAuthorizationHeader,
failOnErrorStatusCode: true,
});
try {
const response = await client.getFunctions({
lpEventSource: 'tests',
userId,
});
}
catch (error) {
expect(error === null || error === void 0 ? void 0 : error.name).toEqual('FaaSGetFunctionsError');
expect(error === null || error === void 0 ? void 0 : error.message).toContain(`403 - Forbidden`);
}
});
});
//# sourceMappingURL=getFunctions.v2.test.js.map
;