@apillon/sdk
Version:
▶◀ Apillon SDK for NodeJS ▶◀
90 lines • 4.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const cloud_functions_1 = require("../modules/cloud-functions/cloud-functions");
const cloud_function_1 = require("../modules/cloud-functions/cloud-function");
const cloud_function_job_1 = require("../modules/cloud-functions/cloud-function-job");
const helper_1 = require("./helpers/helper");
describe('Cloud Functions tests', () => {
let cloudFunctions;
let cloudFunctionUuid;
const name = 'SDK Cloud Function Test';
const description = 'SDK Cloud Function Test description';
beforeAll(() => {
cloudFunctions = new cloud_functions_1.CloudFunctions((0, helper_1.getConfig)());
});
test('Create new cloud function', async () => {
const cloudFunction = await cloudFunctions.createCloudFunction({
name,
description,
});
expect(cloudFunction).toBeInstanceOf(cloud_function_1.CloudFunction);
expect(cloudFunction.name).toEqual(name);
expect(cloudFunction.description).toEqual(description);
expect(cloudFunction.uuid).toBeTruthy();
cloudFunctionUuid = cloudFunction.uuid;
});
test('List cloud functions', async () => {
const { items } = await cloudFunctions.listCloudFunctions();
expect(items.length).toBeGreaterThanOrEqual(0);
items.forEach((cloudFunction) => {
expect(cloudFunction instanceof cloud_function_1.CloudFunction).toBeTruthy();
expect(cloudFunction.name).toBeTruthy();
});
expect(items.find((cloudFunction) => cloudFunction.uuid === cloudFunctionUuid)).toBeTruthy();
});
test('Get specific cloud function', async () => {
const cloudFunction = await cloudFunctions
.cloudFunction(cloudFunctionUuid)
.get();
expect(cloudFunction).toBeInstanceOf(cloud_function_1.CloudFunction);
expect(cloudFunction.name).toEqual(name);
expect(cloudFunction.description).toEqual(description);
expect(cloudFunction.uuid).toEqual(cloudFunctionUuid);
});
test('Create a job for a cloud function', async () => {
const job = await cloudFunctions
.cloudFunction(cloudFunctionUuid)
.createJob({
name: 'Job 1',
scriptCid: 'QmYtHkLrtGEybxXg53swTHuKPYMXQCbHGeBqpYjYbaVyFV',
});
expect(job).toBeInstanceOf(cloud_function_job_1.CloudFunctionJob);
expect(job.name).toEqual('Job 1');
expect(job.scriptCid).toEqual('QmYtHkLrtGEybxXg53swTHuKPYMXQCbHGeBqpYjYbaVyFV');
});
test('Set environment variables for a cloud function', async () => {
const environmentVariables = [
{ key: 'VAR1', value: 'value1' },
{ key: 'VAR2', value: 'value2' },
];
await cloudFunctions
.cloudFunction(cloudFunctionUuid)
.setEnvironment(environmentVariables);
const cloudFunction = await cloudFunctions
.cloudFunction(cloudFunctionUuid)
.get();
expect(cloudFunction).toBeInstanceOf(cloud_function_1.CloudFunction);
expect(cloudFunction.uuid).toEqual(cloudFunctionUuid);
});
test('List jobs for a cloud function', async () => {
const { jobs } = await cloudFunctions
.cloudFunction(cloudFunctionUuid)
.get();
expect(jobs.length).toBeGreaterThanOrEqual(0);
jobs.forEach((job) => {
expect(job instanceof cloud_function_job_1.CloudFunctionJob).toBeTruthy();
expect(job.name).toBeTruthy();
});
});
test('Delete a job for a cloud function', async () => {
const { jobs } = await cloudFunctions
.cloudFunction(cloudFunctionUuid)
.get();
await jobs[0].delete();
const { jobs: updatedJobs } = await cloudFunctions
.cloudFunction(cloudFunctionUuid)
.get();
expect(updatedJobs.find((j) => j.uuid === jobs[0].uuid)).toBeUndefined();
});
});
//# sourceMappingURL=cloud-functions.test.js.map