426e9eeabd
Voice Workbench / headless workbench (mocked backends) (push) Has been cancelled
Voice Workbench / real acoustic lane (nightly, provisioned only) (push) Has been cancelled
ci / test (push) Has been cancelled
ci / lint-and-format (push) Has been cancelled
ci / build (push) Has been cancelled
ci / dev-startup (push) Has been cancelled
gitleaks / gitleaks (push) Has been cancelled
Markdown Links / Relative Markdown Links (push) Has been cancelled
Quality (Extended) / Homepage Build (PR smoke) (push) Has been cancelled
Quality (Extended) / Comment-only diff guard (push) Has been cancelled
Quality (Extended) / Format + Type Safety Ratchet (push) Has been cancelled
Quality (Extended) / Develop Gate (secret scan + UI determinism) (push) Has been cancelled
Quality (Extended) / Develop Gate (lint) (push) Has been cancelled
Chat shell gestures / Chat shell gesture + parity e2e (push) Has been cancelled
Cloud Gateway Discord / Test (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx @biomejs/biome check packages/lifeops-bench/src, benchmark-lint) (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx vitest run --config packages/lifeops-bench/vitest.config.ts --root packages/lifeops-bench --passWithNoTests, benchmark-tests) (push) Has been cancelled
Build Agent Image / build-and-push (push) Has been cancelled
Dev Smoke / bun run dev onboarding chat (push) Has been cancelled
Dev Smoke / Vite HMR dependency-level smoke (push) Has been cancelled
Electrobun Submodule Guard / electrobun gitlink is fetchable (push) Has been cancelled
Publish @elizaos/example-code / check_npm (push) Has been cancelled
Publish @elizaos/example-code / publish_npm (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / verify_version (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / publish_npm (push) Has been cancelled
Sandbox Live Smoke / Sandbox live smoke (push) Has been cancelled
Snap Build & Test / Build Snap (amd64) (push) Has been cancelled
Snap Build & Test / Build Snap (arm64) (push) Has been cancelled
Test Packaging / elizaos CLI global-install smoke (node + bun) (push) Has been cancelled
Cloud Gateway Webhook / Test (push) Has been cancelled
Cloud Tests / lint-and-types (push) Has been cancelled
Cloud Tests / unit-tests (push) Has been cancelled
Cloud Tests / integration-tests (push) Has been cancelled
Cloud Tests / e2e-tests (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Apps Worker (Product 2) / Determine environment (push) Has been cancelled
Deploy Apps Worker (Product 2) / Deploy apps worker to apps-control host (${{ needs.determine-env.outputs.environment }}) (push) Has been cancelled
Deploy Eliza Provisioning Worker / Determine environment (push) Has been cancelled
Deploy Eliza Provisioning Worker / Deploy worker to Hetzner host (${{ needs.determine-env.outputs.environment }} @ ${{ needs.determine-env.outputs.deployment_sha }}) (push) Has been cancelled
Dev Smoke / Classify changed paths (push) Has been cancelled
supply-chain / sbom (push) Has been cancelled
supply-chain / vulnerability-scan (push) Has been cancelled
Build, Push & Deploy to Phala Cloud / build-and-push (push) Has been cancelled
Test Packaging / Validate Packaging Configs (push) Has been cancelled
Test Packaging / Build & Test PyPI Package (push) Has been cancelled
Test Packaging / PyPI on Python ${{ matrix.python }} (push) Has been cancelled
Test Packaging / Pack & Test JS Tarballs (push) Has been cancelled
UI Fixture E2E / ui-fixture-e2e (push) Has been cancelled
UI Fixture E2E / fixture-e2e (push) Has been cancelled
UI Story Gate / story-gate (push) Has been cancelled
vault-ci / test (macos-latest) (push) Has been cancelled
vault-ci / test (ubuntu-latest) (push) Has been cancelled
vault-ci / test (windows-latest) (push) Has been cancelled
vault-ci / app-core wiring tests (push) Has been cancelled
verify-patches / verify patches/CHECKSUMS.sha256 (push) Has been cancelled
Voice Benchmark Smoke / voice-emotion fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voiceagentbench fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench-quality unit smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench TypeScript unit (no audio) (push) Has been cancelled
Voice Benchmark Smoke / voice bench smoke summary (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/app-core test bun run --cwd packages/elizaos test bun run --cwd packages/cloud/shared test], app-and-cli) (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/scenario-runner test bun run --cwd packages/vault test bun run --cwd packages/security test bun run --cwd plugins/plugin-coding-tools test], framework-packages) (push) Has been cancelled
Windows CI / windows ([bun run --cwd plugins/plugin-elizacloud test bun run --cwd plugins/plugin-discord test bun run --cwd plugins/plugin-anthropic test bun run --cwd plugins/plugin-openai test bun run --cwd plugins/plugin-app-control test bun run --cwd plugins/pl… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run build --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/agent --concurrency=4 node packages/scripts/run-bash-linux-only.mjs scripts/verify-riscv64-buildpaths.sh node packages/scripts/run… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run typecheck --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/cloud-shared --concurrency=4 bun run --cwd packages/core test bun run --cwd packages/shared test], core-runtime, 75) (push) Has been cancelled
276 lines
7.9 KiB
TypeScript
276 lines
7.9 KiB
TypeScript
/**
|
|
* Ad-campaign management action tests (SET_AD_CAMPAIGN_DAYPARTING, performance reports). The @elizaos/cloud-sdk client is faked (helpers.ts, SDK boundary only); the action runs for real.
|
|
*/
|
|
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
import type {
|
|
DuplicateAdCampaignInput,
|
|
UpdateCampaignDaypartingInput,
|
|
} from "@elizaos/cloud-sdk";
|
|
import {
|
|
captureCallback,
|
|
FakeElizaCloudClient,
|
|
keyedRuntime,
|
|
makeMessage,
|
|
resetSdk,
|
|
setCreateAdCampaignReportShare,
|
|
setDuplicateAdCampaign,
|
|
setGetAdCampaignPerformanceReport,
|
|
setUpdateAdCampaignDayparting,
|
|
unkeyedRuntime,
|
|
} from "./helpers";
|
|
|
|
mock.module("@elizaos/cloud-sdk", () => ({
|
|
ElizaCloudClient: FakeElizaCloudClient,
|
|
}));
|
|
|
|
const {
|
|
duplicateAdCampaignAction,
|
|
exportAdCampaignReportAction,
|
|
setAdCampaignDaypartingAction,
|
|
} = await import("../src/actions/ad-campaigns.ts");
|
|
|
|
const SCHEDULE = {
|
|
timezone: "America/Los_Angeles",
|
|
windows: [
|
|
{ daysOfWeek: [1, 2, 3, 4, 5], startTime: "09:00", endTime: "17:00" },
|
|
],
|
|
};
|
|
|
|
describe("SET_AD_CAMPAIGN_DAYPARTING", () => {
|
|
beforeEach(() => resetSdk());
|
|
|
|
it("validate: true with key, false without", async () => {
|
|
expect(
|
|
await setAdCampaignDaypartingAction.validate(
|
|
keyedRuntime(),
|
|
makeMessage("x"),
|
|
),
|
|
).toBe(true);
|
|
expect(
|
|
await setAdCampaignDaypartingAction.validate(
|
|
unkeyedRuntime(),
|
|
makeMessage("x"),
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("no key -> no_key", async () => {
|
|
const cb = captureCallback();
|
|
const res = await setAdCampaignDaypartingAction.handler(
|
|
unkeyedRuntime(),
|
|
makeMessage("schedule campaign"),
|
|
undefined,
|
|
{},
|
|
cb.callback,
|
|
);
|
|
expect(res.success).toBe(false);
|
|
expect(res.data).toMatchObject({ reason: "no_key" });
|
|
});
|
|
|
|
it("updates dayparting through the SDK boundary", async () => {
|
|
let captured: {
|
|
campaignId: string;
|
|
input: UpdateCampaignDaypartingInput;
|
|
} | null = null;
|
|
setUpdateAdCampaignDayparting((campaignId, input) => {
|
|
captured = { campaignId, input };
|
|
return Promise.resolve({
|
|
success: true,
|
|
campaignId,
|
|
status: "draft",
|
|
dayparting: input.dayparting,
|
|
updatedAt: "2026-07-02T00:00:00.000Z",
|
|
});
|
|
});
|
|
const cb = captureCallback();
|
|
const res = await setAdCampaignDaypartingAction.handler(
|
|
keyedRuntime(),
|
|
makeMessage("schedule campaign"),
|
|
undefined,
|
|
{ campaignId: "campaign_1", dayparting: SCHEDULE },
|
|
cb.callback,
|
|
);
|
|
expect(res.success).toBe(true);
|
|
expect(captured).toEqual({
|
|
campaignId: "campaign_1",
|
|
input: { dayparting: SCHEDULE },
|
|
});
|
|
expect(res.userFacingText).toContain("1 dayparting window");
|
|
});
|
|
});
|
|
|
|
describe("DUPLICATE_AD_CAMPAIGN", () => {
|
|
beforeEach(() => resetSdk());
|
|
|
|
it("requires a campaign id", async () => {
|
|
const cb = captureCallback();
|
|
const res = await duplicateAdCampaignAction.handler(
|
|
keyedRuntime(),
|
|
makeMessage("duplicate campaign"),
|
|
undefined,
|
|
{},
|
|
cb.callback,
|
|
);
|
|
expect(res.success).toBe(false);
|
|
expect(res.data).toMatchObject({ reason: "missing_campaign_id" });
|
|
});
|
|
|
|
it("duplicates through the SDK boundary", async () => {
|
|
let captured: {
|
|
campaignId: string;
|
|
input?: DuplicateAdCampaignInput;
|
|
} | null = null;
|
|
setDuplicateAdCampaign((campaignId, input) => {
|
|
captured = { campaignId, input };
|
|
return Promise.resolve({
|
|
success: true,
|
|
campaign: {
|
|
id: "copy_1",
|
|
name: input?.name ?? "Copy",
|
|
platform: "meta",
|
|
objective: "traffic",
|
|
status: "draft",
|
|
budgetType: "daily",
|
|
budgetAmount: "50.00",
|
|
budgetCurrency: "USD",
|
|
creditsAllocated: "0.00",
|
|
externalCampaignId: null,
|
|
sourceCampaignId: campaignId,
|
|
createdAt: "2026-07-02T00:00:00.000Z",
|
|
},
|
|
creativesCopied: 2,
|
|
});
|
|
});
|
|
const cb = captureCallback();
|
|
const res = await duplicateAdCampaignAction.handler(
|
|
keyedRuntime(),
|
|
makeMessage("duplicate campaign"),
|
|
undefined,
|
|
{ campaignId: "campaign_1", name: "Summer Campaign Copy" },
|
|
cb.callback,
|
|
);
|
|
expect(res.success).toBe(true);
|
|
expect(captured).toEqual({
|
|
campaignId: "campaign_1",
|
|
input: { name: "Summer Campaign Copy" },
|
|
});
|
|
expect(res.userFacingText).toContain("2 creative");
|
|
});
|
|
});
|
|
|
|
describe("EXPORT_AD_CAMPAIGN_REPORT", () => {
|
|
beforeEach(() => resetSdk());
|
|
|
|
it("requires a campaign id", async () => {
|
|
const cb = captureCallback();
|
|
const res = await exportAdCampaignReportAction.handler(
|
|
keyedRuntime(),
|
|
makeMessage("export campaign report"),
|
|
undefined,
|
|
{},
|
|
cb.callback,
|
|
);
|
|
expect(res.success).toBe(false);
|
|
expect(res.data).toMatchObject({ reason: "missing_campaign_id" });
|
|
});
|
|
|
|
it("exports server-computed campaign metrics through the SDK boundary", async () => {
|
|
let captured: string | null = null;
|
|
setGetAdCampaignPerformanceReport((campaignId) => {
|
|
captured = campaignId;
|
|
return Promise.resolve({
|
|
success: true,
|
|
report: {
|
|
generatedAt: "2026-07-03T00:00:00.000Z",
|
|
campaign: {
|
|
id: campaignId,
|
|
name: "Launch Push",
|
|
platform: "meta",
|
|
objective: "traffic",
|
|
status: "active",
|
|
externalCampaignId: "ext_1",
|
|
appId: null,
|
|
budgetType: "daily",
|
|
budgetAmount: 200,
|
|
budgetCurrency: "USD",
|
|
creditsAllocated: 220,
|
|
creditsSpent: 44,
|
|
startDate: null,
|
|
endDate: null,
|
|
createdAt: "2026-07-01T00:00:00.000Z",
|
|
updatedAt: "2026-07-03T00:00:00.000Z",
|
|
},
|
|
dateRange: null,
|
|
summary: {
|
|
spend: 40,
|
|
impressions: 2000,
|
|
clicks: 100,
|
|
conversions: 10,
|
|
ctr: 5,
|
|
cpc: 0.4,
|
|
cpm: 20,
|
|
conversionRate: 10,
|
|
costPerConversion: 4,
|
|
budgetUtilization: 20,
|
|
conversionValue: 0,
|
|
},
|
|
provider: {
|
|
platform: "meta",
|
|
accountId: "acct_1",
|
|
externalAccountId: "external_acct",
|
|
externalCampaignId: "ext_1",
|
|
},
|
|
},
|
|
});
|
|
});
|
|
const cb = captureCallback();
|
|
const res = await exportAdCampaignReportAction.handler(
|
|
keyedRuntime(),
|
|
makeMessage("export report"),
|
|
undefined,
|
|
{ campaignId: "campaign_1" },
|
|
cb.callback,
|
|
);
|
|
expect(res.success).toBe(true);
|
|
expect(captured).toBe("campaign_1");
|
|
expect(res.userFacingText).toContain("Launch Push");
|
|
expect(res.userFacingText).toContain("CTR: 5.00%");
|
|
});
|
|
|
|
it("creates an expiring share link when requested", async () => {
|
|
let shareInput: { campaignId: string; expiresInHours?: number } | null =
|
|
null;
|
|
setCreateAdCampaignReportShare((campaignId, input) => {
|
|
shareInput = { campaignId, expiresInHours: input?.expiresInHours };
|
|
return Promise.resolve({
|
|
success: true,
|
|
share: {
|
|
id: "share_1",
|
|
campaignId,
|
|
token: "token_1",
|
|
publicPath: "/api/v1/advertising/reports/token_1",
|
|
publicUrl: "https://elizacloud.ai/api/v1/advertising/reports/token_1",
|
|
expiresAt: "2026-07-10T00:00:00.000Z",
|
|
},
|
|
});
|
|
});
|
|
const cb = captureCallback();
|
|
const res = await exportAdCampaignReportAction.handler(
|
|
keyedRuntime(),
|
|
makeMessage("share report"),
|
|
undefined,
|
|
{ campaignId: "campaign_1", share: true, expiresInHours: 48 },
|
|
cb.callback,
|
|
);
|
|
expect(res.success).toBe(true);
|
|
expect(shareInput).toEqual({
|
|
campaignId: "campaign_1",
|
|
expiresInHours: 48,
|
|
});
|
|
expect(res.userFacingText).toContain("Share link:");
|
|
expect(res.userFacingText).toContain(
|
|
"https://elizacloud.ai/api/v1/advertising/reports/token_1",
|
|
);
|
|
});
|
|
});
|