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
4 changes: 3 additions & 1 deletion src/artifacts/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ describe('loadArtifacts', () => {
['GET', '/orders', 'listOrders'],
['POST', '/orders', 'createOrder'],
])
expect(db.diagrams[0].entity.id).toBe('checkout')
expect(db.diagrams[0].entity.id).toBe(
'uigraph-diagrams-checkout-checkout-mmd'
)
expect(db.diagrams[0].flow.nodes.length).toBeGreaterThan(0)
expect(db.databases[0].serviceDb.tables).toEqual([
expect.objectContaining({
Expand Down
6 changes: 4 additions & 2 deletions src/artifacts/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,11 @@ export async function loadArtifacts(root: string, configFile = ROOT_CONFIG) {
: serviceIdByName.get(config.service.name)
for (const [index, entry] of config.architectureDiagrams.entries()) {
const where = `${file}: architectureDiagrams[${entry.name}]`
const id = slugify(path.posix.basename(path.posix.dirname(entry.path)))
const id = slugify(entry.path)
if (diagramIds.has(id)) {
errors.push(`${where}: another diagram already uses the folder "${id}"`)
errors.push(
`${where}: another diagram already uses the path "${entry.path}"`
)
continue
}
let mermaid: string
Expand Down
40 changes: 27 additions & 13 deletions src/artifacts/write.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('diagrams', () => {
})
expect(
await createDiagram(root, '.uigraph.yaml', '.uigraph.yaml', 'Payments')
).toBe('payments-2')
).toBe('uigraph-diagrams-payments-2-payments-2-mmd')
expect(await readRepoFile(root, '.uigraph.yaml'))
.toContain(` - name: Checkout flow # main flow
path: .uigraph/diagrams/checkout/checkout.mmd
Expand All @@ -82,8 +82,8 @@ describe('diagrams', () => {
const { db, errors } = await loadArtifacts(root)
expect(errors).toEqual([])
expect(db.diagrams.map((d) => d.entity.id)).toEqual([
'checkout',
'payments-2',
'uigraph-diagrams-checkout-checkout-mmd',
'uigraph-diagrams-payments-2-payments-2-mmd',
])
})

Expand All @@ -99,9 +99,14 @@ describe('diagrams', () => {
it('renames a diagram without touching the rest of the file', async () => {
const root = await createRepo(ORDERS_FILES)
const before = await readRepoFile(root, '.uigraph.yaml')
const saved = await saveDiagram(root, '.uigraph.yaml', 'checkout', {
name: ' Checkout v2 ',
})
const saved = await saveDiagram(
root,
'.uigraph.yaml',
'uigraph-diagrams-checkout-checkout-mmd',
{
name: ' Checkout v2 ',
}
)
expect(saved.name).toBe('Checkout v2')
expect(await readRepoFile(root, '.uigraph.yaml')).toBe(
before.replace('name: Checkout flow # main', 'name: Checkout v2 # main')
Expand All @@ -112,12 +117,17 @@ describe('diagrams', () => {
const root = await createRepo(ORDERS_FILES)
const { db } = await loadArtifacts(root)
const flow = db.diagrams[0].flow
await saveDiagram(root, '.uigraph.yaml', 'checkout', {
content: JSON.stringify({
nodes: flow.nodes.filter((node) => node.id !== 'Db'),
edges: flow.edges.filter((edge) => edge.target !== 'Db'),
}),
})
await saveDiagram(
root,
'.uigraph.yaml',
'uigraph-diagrams-checkout-checkout-mmd',
{
content: JSON.stringify({
nodes: flow.nodes.filter((node) => node.id !== 'Db'),
edges: flow.edges.filter((edge) => edge.target !== 'Db'),
}),
}
)
const mermaid = await readRepoFile(
root,
'.uigraph/diagrams/checkout/checkout.mmd'
Expand All @@ -137,7 +147,11 @@ describe('diagrams', () => {
...ORDERS_FILES,
'.uigraph/diagrams/checkout/images/shot.png': 'png',
})
await deleteDiagram(root, '.uigraph.yaml', 'checkout')
await deleteDiagram(
root,
'.uigraph.yaml',
'uigraph-diagrams-checkout-checkout-mmd'
)
expect(await readRepoFile(root, '.uigraph.yaml')).toContain(
'architectureDiagrams: []\n'
)
Expand Down
7 changes: 3 additions & 4 deletions src/artifacts/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,15 @@ export async function createDiagram(
let folder = base
for (
let suffix = 2;
db.diagrams.some((d) => d.entity.id === folder) ||
(await fs.lstat(path.join(root, '.uigraph/diagrams', folder)).then(
await fs.lstat(path.join(root, '.uigraph/diagrams', folder)).then(
() => true,
(error: NodeJS.ErrnoException) => {
if (error.code === 'ENOENT') {
return false
}
throw error
}
));
);
suffix++
) {
folder = `${base}-${suffix}`
Expand All @@ -296,7 +295,7 @@ export async function createDiagram(
appendItem(source, document, ['architectureDiagrams'], entry),
])
)
return folder
return slugify(entry.path)
}

export async function deleteDiagram(
Expand Down
7 changes: 6 additions & 1 deletion src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ describe('GraphQL', () => {
},
diagrams: {
items: [
{ id: expect.stringMatching(/--checkout$/), name: 'Checkout flow' },
{
id: expect.stringMatching(
/--uigraph-diagrams-checkout-checkout-mmd$/
),
name: 'Checkout flow',
},
],
},
apiEndpoints: [
Expand Down
Loading