Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions cli/src/commands/calendar.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { holdReservationOptions } from "./event.mjs";
import { apiFor } from "../session.mjs";
import { UsageError } from "../errors.mjs";
import { berlinToday } from "../format.mjs";

const client = apiFor;

Expand Down Expand Up @@ -174,12 +175,7 @@ function busyIntervalsForDay(ownerItems, window) {
}

function todayBerlin() {
return new Intl.DateTimeFormat("en-CA", {
timeZone: "Europe/Berlin",
year: "numeric",
month: "2-digit",
day: "2-digit",
}).format(new Date());
return berlinToday();
}

function currentMonthBounds() {
Expand Down
20 changes: 16 additions & 4 deletions cli/src/commands/newsletter.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync } from "node:fs";
import { existsSync, readFileSync } from "node:fs";
import { basename } from "node:path";
import { UsageError } from "../errors.mjs";
import { berlinToday, enc, fields, integer, isoDate, optionalString, positional, table } from "../format.mjs";
Expand Down Expand Up @@ -280,6 +280,18 @@ export async function show(args, io) {
if (issue.previewShareUrl || issue.previewUrl) {
io.print(`preview link: ${rewriteVerificationUri(issue.previewShareUrl || issue.previewUrl, apiFor(args).base)}`);
}
const finalRender = issue.finalRender;
if (finalRender && typeof finalRender === "object") {
io.print("final render:");
if (finalRender.webViewUrl) io.print(` web view: ${finalRender.webViewUrl}`);
if (finalRender.relayIssueKey) io.print(` relay key: ${finalRender.relayIssueKey}`);
if (finalRender.subject) io.print(` subject: ${finalRender.subject}`);
if (finalRender.previewText) io.print(` preview: ${finalRender.previewText}`);
io.print(` html snapshot: ${finalRender.html ? `${finalRender.html.length} chars` : "none"}`);
if (finalRender.updatedAt) {
io.print(` updated: ${finalRender.updatedAt}${finalRender.updatedByName ? ` by ${finalRender.updatedByName}` : ""}`);
}
}
return issue;
}

Expand Down Expand Up @@ -1104,8 +1116,8 @@ export async function finalRender(args, io) {
} else {
const htmlFile = optionalString(args, "htmlFile") ?? optionalString(args, "file");
if (htmlFile) {
if (!fs.existsSync(htmlFile)) throw new UsageError(`File not found: ${htmlFile}`);
body.html = fs.readFileSync(htmlFile, "utf8");
if (!existsSync(htmlFile)) throw new UsageError(`File not found: ${htmlFile}`);
body.html = readFileSync(htmlFile, "utf8");
}
const webViewUrl = optionalString(args, "webViewUrl");
if (webViewUrl !== undefined) body.webViewUrl = webViewUrl;
Expand All @@ -1121,7 +1133,7 @@ export async function finalRender(args, io) {
}

const rawResult = await api.put(`/api/newsletter-issues/${enc(id)}/final-render`, body);
const result = rewritePreviewUrls(rawResult, api.base);
const result = normalizeMarkdownPayloadUrls(rawResult, api.base);
if (!args.json) {
if (result.shareUrl) io.print(`shareUrl: ${result.shareUrl}`);
else if (result.previewUrl) io.print(`previewUrl: ${result.previewUrl}`);
Expand Down
2 changes: 2 additions & 0 deletions cli/test/calendar.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { describe, test } from "node:test";

const configDir = mkdtempSync(path.join(tmpdir(), "dataops-cli-cal-"));
process.env.DATAOPS_CONFIG_DIR = configDir;
// Fixtures use fixed November 2026 dates; pin "today" so past-date filtering stays stable.
process.env.DATAOPS_TODAY = "2026-11-16";

const { run } = await import("../src/cli.mjs");
const { saveProfile } = await import("../src/config.mjs");
Expand Down
74 changes: 74 additions & 0 deletions cli/test/newsletter-final-render.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import assert from "node:assert/strict";
import { mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { describe, test } from "node:test";

import { captureIo, fakePortal, isolateConfig } from "./helpers.mjs";

isolateConfig();
const { run } = await import("../src/cli.mjs");

const ISSUE = "12407b2e83f5fbda0ed906b74bb22dcee8d4a44fe0335963c809448de39ae9ce";
const WEB_VIEW = "https://relay.datatalks.club/newsletter/view/5:U_F3fXwxFN7FqsvzDDPxA7feGtnrXwNyr78D0S8aCtM";
const SUBJECT = "🛠️ Run AI pipelines with Snowflake and Airflow | DataTalks.Club Weekly";
const PREVIEW = "Live Dec 3 with Snowflake’s Principal Partner SE.";

const previewPayload = (rendered = {}) => ({
previewUrl: `https://portal.test/newsletter/preview/${ISSUE}`,
shareUrl: `https://portal.test/newsletter/preview/${ISSUE}?code=abc`,
rendered: { finalWebViewUrl: WEB_VIEW, finalSubject: SUBJECT, finalPreviewText: PREVIEW, finalHtml: "", ...rendered },
});

describe("newsletter final-render", () => {
test("stores web-view URL, subject and preview (Weekly #303 command)", async () => {
const calls = fakePortal({ [`PUT /api/newsletter-issues/${ISSUE}/final-render`]: () => previewPayload() });
const io = captureIo();
const code = await run([
"newsletter", "final-render", ISSUE, "--web-view-url", WEB_VIEW, "--subject", SUBJECT, "--preview", PREVIEW,
], io);
assert.equal(code, 0, io.errors.join("\n"));
assert.deepEqual(calls[0].body, { webViewUrl: WEB_VIEW, subject: SUBJECT, previewText: PREVIEW });
assert.match(io.text(), /shareUrl: https:\/\/portal\.test\/newsletter\/preview\/.*\?code=abc/);
assert.match(io.text(), new RegExp(`webViewUrl: ${WEB_VIEW.replace(/[.?]/g, "\\$&")}`));
assert.match(io.text(), /finalHtml: none/);
});

test("--html-file uploads the file contents", async () => {
const dir = mkdtempSync(path.join(tmpdir(), "final-render-"));
const file = path.join(dir, "email.html");
writeFileSync(file, "<html>final</html>");
const calls = fakePortal({
[`PUT /api/newsletter-issues/${ISSUE}/final-render`]: () => previewPayload({ finalHtml: "<html>final</html>" }),
});
const io = captureIo();
assert.equal(await run(["newsletter", "final-render", ISSUE, "--html-file", file], io), 0, io.errors.join("\n"));
assert.deepEqual(calls[0].body, { html: "<html>final</html>" });
assert.match(io.text(), /finalHtml: 18 chars/);
});

test("--clear sends clear and no flags is a usage error", async () => {
const calls = fakePortal({ [`PUT /api/newsletter-issues/${ISSUE}/final-render`]: () => previewPayload() });
const io = captureIo();
assert.equal(await run(["newsletter", "final-render", ISSUE, "--clear"], io), 0, io.errors.join("\n"));
assert.deepEqual(calls[0].body, { clear: true });
const bare = captureIo();
assert.notEqual(await run(["newsletter", "final-render", ISSUE], bare), 0);
assert.match(bare.errors.join("\n"), /Provide at least one flag/);
});

test("show prints the stored final render", async () => {
fakePortal({
[`GET /api/newsletter-issues/${ISSUE}`]: () => ({
id: ISSUE, label: "Weekly #303", publicationDate: "2026-11-16", status: "sent", slots: {},
finalRender: { webViewUrl: WEB_VIEW, subject: SUBJECT, previewText: PREVIEW, updatedAt: "2026-11-18T10:00:00Z", updatedByName: "Orin" },
}),
});
const io = captureIo();
assert.equal(await run(["newsletter", "show", ISSUE], io), 0, io.errors.join("\n"));
assert.ok(io.text().includes(`web view: ${WEB_VIEW}`));
assert.ok(io.text().includes(`subject: ${SUBJECT}`));
assert.ok(io.text().includes(`preview: ${PREVIEW}`));
assert.match(io.text(), /html snapshot: none/);
});
});