Skip to content

Commit

Permalink
Fix bug and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-lobanov committed Feb 22, 2023
1 parent c792738 commit 8307d5b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class GraphBuilder {
graphNode = { value: issue, predecessors: [], successors: [] };
this.nodes.set(nodeKey, graphNode);
}
else if (issue) {
graphNode.value = issue;
}
return graphNode;
}
addIssue(issueReference, issue) {
Expand Down
2 changes: 2 additions & 0 deletions src/graph-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export class GraphBuilder {
if (!graphNode) {
graphNode = { value: issue, predecessors: [], successors: [] };
this.nodes.set(nodeKey, graphNode);
} else if (issue) {
graphNode.value = issue;
}

return graphNode;
Expand Down
25 changes: 25 additions & 0 deletions tests/graph-builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,29 @@ describe("GraphBuilder", () => {
{ from: "issue3", to: "finish" },
]);
});

it("Add dependency before adding node", () => {
const graphBuilder = new GraphBuilder(true);

graphBuilder.addIssue(
{ repoOwner: "A", repoName: "B", issueNumber: 1 },
new MermaidNode("issue1", "Test issue 1", "notstarted")
);
graphBuilder.addDependency(
{ repoOwner: "A", repoName: "B", issueNumber: 1 },
{ repoOwner: "A", repoName: "B", issueNumber: 2 }
);
graphBuilder.addIssue(
{ repoOwner: "A", repoName: "B", issueNumber: 2 },
new MermaidNode("issue2", "Test issue 2", "started")
);

const actual = extractNodeIdFromGraph(graphBuilder.getGraph());
expect(actual.vertices).toEqual(["start", "issue1", "issue2", "finish"]);
expect(actual.edges).toEqual([
{ from: "start", to: "issue1" },
{ from: "issue1", to: "issue2" },
{ from: "issue2", to: "finish" },
]);
});
});

0 comments on commit 8307d5b

Please sign in to comment.