-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Mermaid-Chart/feat/add-getDiagram-to-sdk
Add the `getDiagram(diagramID)` API function to the SDK
- Loading branch information
Showing
6 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { MermaidChart } from './index.js'; | |
import { beforeAll, describe, expect, it } from 'vitest'; | ||
|
||
import process from 'node:process'; | ||
import { AxiosError } from 'axios'; | ||
|
||
let client: MermaidChart; | ||
|
||
|
@@ -32,3 +33,43 @@ describe('getUser', () => { | |
expect(user).toHaveProperty('emailAddress'); | ||
}); | ||
}); | ||
|
||
const documentMatcher = expect.objectContaining({ | ||
documentID: expect.any(String), | ||
major: expect.any(Number), | ||
minor: expect.any(Number), | ||
}); | ||
|
||
describe("getDocument", () => { | ||
it("should get publicly shared diagram", async() => { | ||
const latestDocument = await client.getDocument({ | ||
// owned by [email protected] | ||
documentID: '8bce727b-69b7-4f6e-a434-d578e2b363ff', | ||
}); | ||
|
||
expect(latestDocument).toStrictEqual(documentMatcher); | ||
|
||
const earliestDocument = await client.getDocument({ | ||
// owned by [email protected] | ||
documentID: '8bce727b-69b7-4f6e-a434-d578e2b363ff', | ||
major: 0, | ||
minor: 1, | ||
}); | ||
|
||
expect(earliestDocument).toStrictEqual(documentMatcher); | ||
}); | ||
|
||
it("should throw 404 on unknown document", async() => { | ||
let error: AxiosError | undefined = undefined; | ||
try { | ||
await client.getDocument({ | ||
documentID: '00000000-0000-0000-0000-0000deaddead', | ||
}); | ||
} catch (err) { | ||
error = err as AxiosError; | ||
} | ||
|
||
expect(error).toBeInstanceOf(AxiosError); | ||
expect(error?.response?.status).toBe(404); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters