-
Notifications
You must be signed in to change notification settings - Fork 7
ENG-2158 Publish node type format with schemas #1316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import type { SupabaseContext } from "~/utils/supabaseContext"; | ||
| import type { DiscourseNode } from "~/utils/getDiscourseNodes"; | ||
| import { discourseNodeSchemaToLocalConcept } from "~/utils/conceptConversion"; | ||
|
|
||
| const context = { spaceId: 42 } as SupabaseContext; | ||
|
|
||
| const claimSchema: DiscourseNode = { | ||
| type: "schema-1", | ||
| text: "Claim", | ||
| shortcut: "C", | ||
| specification: [], | ||
| backedBy: "user", | ||
| canvasSettings: {}, | ||
| format: "[[CLM]] - {content}", | ||
| }; | ||
|
|
||
| const stubRoamQuery = () => { | ||
| (globalThis as { window: unknown }).window = { | ||
| roamAlphaAPI: { | ||
| q: vi.fn().mockReturnValue([["author-1", "page-1", 1000, 2000]]), | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| describe("discourseNodeSchemaToLocalConcept", () => { | ||
| it("writes label and format into literal_content", () => { | ||
| stubRoamQuery(); | ||
| const concept = discourseNodeSchemaToLocalConcept(context, claimSchema); | ||
| expect(concept.literal_content).toEqual({ | ||
| label: "Claim", | ||
| format: "[[CLM]] - {content}", | ||
| }); | ||
| }); | ||
|
|
||
| it("keeps label and format when the type has a template", () => { | ||
| stubRoamQuery(); | ||
| const concept = discourseNodeSchemaToLocalConcept(context, { | ||
| ...claimSchema, | ||
| template: [{ text: "Evidence" }], | ||
| }); | ||
| expect(concept.literal_content).toEqual({ | ||
| label: "Claim", | ||
| format: "[[CLM]] - {content}", | ||
| template: "* Evidence\n", | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,5 +200,6 @@ export const nodeSchemaToCrossApp = ( | |
| label: s.text, | ||
| authorId: userUid, | ||
| createdAt: new Date(relData[":create/time"] || Date.now()), | ||
| format: s.format, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a node type was synchronized before this deployment, Useful? React with 👍 / 👎. |
||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ export type CrossAppNodeSchema = CrossAppSchemaBase & { | |
| label: string; | ||
| template?: string; | ||
| templateTitle?: string; | ||
| format?: string; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Flat |
||
| }; | ||
|
|
||
| // A relation type schema | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { crossAppNodeSchemaToDbConcept } from "../crossAppConverters"; | ||
| import type { CrossAppNodeSchema } from "../../crossAppContracts"; | ||
|
|
||
| const baseSchema: CrossAppNodeSchema = { | ||
| localId: "schema-1", | ||
| label: "Claim", | ||
| authorId: "author-1", | ||
| createdAt: new Date("2026-01-01T00:00:00.000Z"), | ||
| }; | ||
|
|
||
| describe("crossAppNodeSchemaToDbConcept", () => { | ||
| it("maps format to literal_content.format", () => { | ||
| const concept = crossAppNodeSchemaToDbConcept({ | ||
| ...baseSchema, | ||
| format: "[[CLM]] - {content}", | ||
| }); | ||
| expect(concept.literal_content).toEqual({ | ||
| format: "[[CLM]] - {content}", | ||
| }); | ||
| }); | ||
|
|
||
| it("keeps the template keys alongside format", () => { | ||
| const concept = crossAppNodeSchemaToDbConcept({ | ||
| ...baseSchema, | ||
| format: "[[CLM]] - {content}", | ||
| template: "* Evidence\n", | ||
| templateTitle: "Claim template", | ||
| }); | ||
| expect(concept.literal_content).toEqual({ | ||
| format: "[[CLM]] - {content}", | ||
| template: "Claim template", | ||
| template_content: "* Evidence\n", | ||
| }); | ||
| }); | ||
|
|
||
| it("omits literal_content when no keys are set", () => { | ||
| const concept = crossAppNodeSchemaToDbConcept(baseSchema); | ||
| expect(concept.literal_content).toBeUndefined(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,7 @@ export const crossAppNodeSchemaToDbConcept = ( | |
| const literalInfo = filterUndefined({ | ||
| template: node.templateTitle, | ||
| template_content: node.template, | ||
| format: node.format, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The publish path writes only |
||
| }); | ||
| return filterUndefined<LocalConceptDataInput>({ | ||
| source_local_id: node.localId, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
literal_contentis now built once, then the template branch adds its key. The old shape replaced the whole object in that branch, so every new key had to be written in two places. No behavior change forlabelandtemplate.