import { QuirrelClient } from "..";
import { run } from "../../api/test/runQuirrel";
import { getAddress } from "./util";
import * as http from "http";
import delay from "delay";
test("cron payload with encryption", async () => {
    const server = await run("Mock");
    const encryptedBodies = [];
    const decryptedBodies = [];
    let quirrel;
    const endpoint = http
        .createServer((req) => {
        let body = "";
        req.on("data", (data) => {
            body += data;
        });
        req.on("end", () => {
            encryptedBodies.push(body);
            quirrel.respondTo(body, req.headers);
        });
    })
        .listen(0);
    quirrel = new QuirrelClient({
        route: "/",
        async handler(body) {
            decryptedBodies.push(body);
        },
        config: {
            quirrelBaseUrl: getAddress(server.server),
            encryptionSecret: "4ws8syoOgeQX6WFvXuUneGNwy7QvLxpk",
            applicationBaseUrl: getAddress(endpoint),
        },
    });
    await server.app.app.jobs.updateCron("anonymous", {
        baseUrl: getAddress(endpoint),
        crons: [{ route: "/", schedule: "@daily" }],
    });
    await quirrel.invoke("@cron");
    await delay(100);
    expect(encryptedBodies).toEqual(["null"]);
    expect(decryptedBodies).toEqual([null]);
    server.teardown();
});
//# sourceMappingURL=cron-payload-encryption.test.js.map