@webda/aws
Version:
Webda AWS Services implementation
70 lines • 2.67 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { InvokeCommand, Lambda } from "@aws-sdk/client-lambda";
import { suite, test } from "@testdeck/mocha";
import { WebdaTest } from "@webda/core/lib/test.js";
import * as assert from "assert";
import { mockClient } from "aws-sdk-client-mock";
import * as sinon from "sinon";
import { LambdaCaller } from "./lambdacaller.js";
const jobInfo = {
JOB_ORCHESTRATOR: "async",
JOB_ID: "webdaAsync",
JOB_SECRET_KEY: "",
JOB_HOOK: "http"
};
let LambdaCallerTest = class LambdaCallerTest extends WebdaTest {
async call() {
// CodeCoverage test
const lambdaCaller = new LambdaCaller(this.webda, "plop", {
arn: "testor"
});
const mock = mockClient(Lambda)
.on(InvokeCommand)
.resolves({
Payload: Buffer.from(JSON.stringify({ plop: true }))
});
try {
lambdaCaller.resolve();
assert.deepStrictEqual(await lambdaCaller.execute(), { plop: true });
assert.deepStrictEqual(await lambdaCaller.execute({}, true, "myarn"), {
plop: true
});
}
finally {
mock.restore();
}
}
async launcher() {
const caller = new LambdaCaller(this.webda, "plop", {});
let stub = sinon.stub(caller, "execute").resolves();
caller.launchAction(undefined, jobInfo);
assert.ok(stub.callCount === 1);
assert.deepStrictEqual(stub.getCall(0).args, [
{
command: "launch",
service: jobInfo.JOB_ORCHESTRATOR,
method: "runWebdaAsyncAction",
args: [jobInfo],
action: undefined,
// We also put the value in JOB_INFO for other type of runner
JOB_INFO: jobInfo
},
true
]);
}
};
__decorate([
test
], LambdaCallerTest.prototype, "call", null);
__decorate([
test
], LambdaCallerTest.prototype, "launcher", null);
LambdaCallerTest = __decorate([
suite
], LambdaCallerTest);
//# sourceMappingURL=lambdacaller.spec.js.map