Skip to content

Commit 7784d35

Browse files
committed
style(sdk): format with prettier --write src/
1 parent 1e5ff67 commit 7784d35

File tree

3 files changed

+60
-44
lines changed

3 files changed

+60
-44
lines changed

packages/sdk/src/index.e2e.test.ts

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,25 @@ let baseURL = new URL('https://test.mermaidchart.com');
1313

1414
let client: MermaidChart;
1515

16-
beforeAll(async() => {
16+
beforeAll(async () => {
1717
if (process.env.TEST_MERMAIDCHART_BASE_URL) {
1818
try {
1919
baseURL = new URL(process.env.TEST_MERMAIDCHART_BASE_URL);
2020
} catch (err) {
21-
throw new Error("Invalid URL in environment variable TEST_MERMAIDCHART_BASE_URL", { cause: err});
21+
throw new Error('Invalid URL in environment variable TEST_MERMAIDCHART_BASE_URL', {
22+
cause: err,
23+
});
2224
}
2325
} else {
24-
process.emitWarning(`Missing environment variable TEST_MERMAIDCHART_BASE_URL. Defaulting to ${baseURL.href}.`);
26+
process.emitWarning(
27+
`Missing environment variable TEST_MERMAIDCHART_BASE_URL. Defaulting to ${baseURL.href}.`,
28+
);
2529
}
2630

2731
if (!process.env.TEST_MERMAIDCHART_API_TOKEN) {
2832
throw new Error(
29-
"Missing required environment variable TEST_MERMAIDCHART_API_TOKEN. "
30-
+ `Please go to ${new URL('/app/user/settings', baseURL)} and create one.`
33+
'Missing required environment variable TEST_MERMAIDCHART_API_TOKEN. ' +
34+
`Please go to ${new URL('/app/user/settings', baseURL)} and create one.`,
3135
);
3236
}
3337

@@ -46,23 +50,28 @@ beforeAll(async() => {
4650
testProjectId = process.env.TEST_MERMAIDCHART_PROJECT_ID;
4751
if (!projects.some((project) => project.id === testProjectId)) {
4852
throw new Error(
49-
`Invalid environment variable TEST_MERMAIDCHART_PROJECT_ID. `
50-
+ `Please go to ${new URL('/app/projects', baseURL)} and create one that you have access to.`
53+
`Invalid environment variable TEST_MERMAIDCHART_PROJECT_ID. ` +
54+
`Please go to ${new URL(
55+
'/app/projects',
56+
baseURL,
57+
)} and create one that you have access to.`,
5158
);
5259
}
5360
} else {
5461
if (!projects.some((project) => project.id === testProjectId)) {
5562
throw new Error(
56-
`Missing environment variable TEST_MERMAIDCHART_PROJECT_ID. `
57-
+ `Please go to ${new URL('/app/projects', baseURL)} and create one.`
63+
`Missing environment variable TEST_MERMAIDCHART_PROJECT_ID. ` +
64+
`Please go to ${new URL('/app/projects', baseURL)} and create one.`,
5865
);
5966
}
60-
process.emitWarning(`Missing optional environment variable TEST_MERMAIDCHART_PROJECT_ID. Defaulting to ${testProjectId}`);
67+
process.emitWarning(
68+
`Missing optional environment variable TEST_MERMAIDCHART_PROJECT_ID. Defaulting to ${testProjectId}`,
69+
);
6170
}
6271
});
6372

6473
describe('getUser', () => {
65-
it("should get user", async() => {
74+
it('should get user', async () => {
6675
const user = await client.getUser();
6776

6877
expect(user).toHaveProperty('emailAddress');
@@ -78,17 +87,19 @@ const documentMatcher = expect.objectContaining({
7887
/**
7988
* Cleanup created documents at the end of this test.
8089
*/
81-
const documentsToDelete = new Set<MCDocument["documentID"]>();
82-
afterAll(async() => {
83-
await Promise.all([...documentsToDelete].map(async(document) => {
84-
if (documentsToDelete.delete(document)) {
85-
await client.deleteDocument(document);
86-
}
87-
}));
90+
const documentsToDelete = new Set<MCDocument['documentID']>();
91+
afterAll(async () => {
92+
await Promise.all(
93+
[...documentsToDelete].map(async (document) => {
94+
if (documentsToDelete.delete(document)) {
95+
await client.deleteDocument(document);
96+
}
97+
}),
98+
);
8899
});
89100

90101
describe('createDocument', () => {
91-
it('should create document in project', async() => {
102+
it('should create document in project', async () => {
92103
const existingDocuments = await client.getDocuments(testProjectId);
93104

94105
const newDocument = await client.createDocument(testProjectId);
@@ -105,7 +116,7 @@ describe('createDocument', () => {
105116
});
106117

107118
describe('setDocument', () => {
108-
it('should set document', async() => {
119+
it('should set document', async () => {
109120
const newDocument = await client.createDocument(testProjectId);
110121
documentsToDelete.add(newDocument.documentID);
111122

@@ -115,33 +126,35 @@ describe('setDocument', () => {
115126
await client.setDocument({
116127
documentID: newDocument.documentID,
117128
projectID: newDocument.projectID,
118-
title: "@mermaidchart/sdk E2E test diagram",
129+
title: '@mermaidchart/sdk E2E test diagram',
119130
code,
120131
});
121132

122133
const updatedDoc = await client.getDocument({
123134
documentID: newDocument.documentID,
124135
});
125136
expect(updatedDoc).toMatchObject({
126-
title: "@mermaidchart/sdk E2E test diagram",
137+
title: '@mermaidchart/sdk E2E test diagram',
127138
code,
128139
});
129140
});
130141

131-
it('should throw an error on invalid data', async() => {
142+
it('should throw an error on invalid data', async () => {
132143
const newDocument = await client.createDocument(testProjectId);
133144
documentsToDelete.add(newDocument.documentID);
134145

135-
await expect(client.setDocument({
136-
documentID: newDocument.documentID,
137-
// @ts-expect-error not setting diagram `projectID` should throw an error
138-
projectID: null,
139-
})).rejects.toThrowError("400"); // should throw HTTP 400 error
146+
await expect(
147+
client.setDocument({
148+
documentID: newDocument.documentID,
149+
// @ts-expect-error not setting diagram `projectID` should throw an error
150+
projectID: null,
151+
}),
152+
).rejects.toThrowError('400'); // should throw HTTP 400 error
140153
});
141154
});
142155

143156
describe('deleteDocument', () => {
144-
it('should delete document', async() => {
157+
it('should delete document', async () => {
145158
const newDocument = await client.createDocument(testProjectId);
146159

147160
expect(await client.getDocuments(testProjectId)).toContainEqual(newDocument);
@@ -154,8 +167,8 @@ describe('deleteDocument', () => {
154167
});
155168
});
156169

157-
describe("getDocument", () => {
158-
it("should get diagram", async() => {
170+
describe('getDocument', () => {
171+
it('should get diagram', async () => {
159172
const newDocument = await client.createDocument(testProjectId);
160173

161174
documentsToDelete.add(newDocument.documentID);
@@ -176,7 +189,7 @@ describe("getDocument", () => {
176189
expect(earliestDocument).toStrictEqual(documentMatcher);
177190
});
178191

179-
it("should throw 404 on unknown document", async() => {
192+
it('should throw 404 on unknown document', async () => {
180193
let error: AxiosError | undefined = undefined;
181194
try {
182195
await client.getDocument({
@@ -190,4 +203,3 @@ describe("getDocument", () => {
190203
expect(error?.response?.status).toBe(404);
191204
});
192205
});
193-

packages/sdk/src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class MermaidChart {
205205
public async getDocument(
206206
document: Pick<MCDocument, 'documentID'> | Pick<MCDocument, 'documentID' | 'major' | 'minor'>,
207207
) {
208-
const {data} = await this.axios.get<MCDocument>(URLS.rest.documents.pick(document).self);
208+
const { data } = await this.axios.get<MCDocument>(URLS.rest.documents.pick(document).self);
209209
return data;
210210
}
211211

@@ -217,14 +217,16 @@ export class MermaidChart {
217217
public async setDocument(
218218
document: Pick<MCDocument, 'documentID' | 'projectID'> & Partial<MCDocument>,
219219
) {
220-
const {data} = await this.axios.put<{result: "ok"} | {result: "failed", error: unknown}>(
220+
const { data } = await this.axios.put<{ result: 'ok' } | { result: 'failed'; error: unknown }>(
221221
URLS.rest.documents.pick(document).self,
222222
document,
223223
);
224224

225-
if (data.result === "failed") {
225+
if (data.result === 'failed') {
226226
throw new Error(
227-
`setDocument(${JSON.stringify({documentID: document.documentID})} failed due to ${JSON.stringify(data.error)}`
227+
`setDocument(${JSON.stringify({
228+
documentID: document.documentID,
229+
})} failed due to ${JSON.stringify(data.error)}`,
228230
);
229231
}
230232
}
@@ -236,7 +238,7 @@ export class MermaidChart {
236238
*/
237239
public async deleteDocument(documentID: MCDocument['documentID']) {
238240
const deletedDocument = await this.axios.delete<Document>(
239-
URLS.rest.documents.pick({documentID}).self,
241+
URLS.rest.documents.pick({ documentID }).self,
240242
{}, // force sending empty JSON to avoid triggering CSRF check
241243
);
242244
return deletedDocument.data;

packages/sdk/src/urls.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ export const URLS = {
77
},
88
rest: {
99
documents: {
10-
pick: (opts: Pick<MCDocument, 'documentID'> | Pick<MCDocument, 'documentID' | 'major' | 'minor'>) => {
11-
const {documentID} = opts;
12-
let queryParams = "";
10+
pick: (
11+
opts: Pick<MCDocument, 'documentID'> | Pick<MCDocument, 'documentID' | 'major' | 'minor'>,
12+
) => {
13+
const { documentID } = opts;
14+
let queryParams = '';
1315

1416
if ('major' in opts) {
15-
const {major, minor} = opts;
17+
const { major, minor } = opts;
1618

1719
queryParams = `v${major ?? 0}.${minor ?? 1}`;
1820
}
@@ -21,9 +23,9 @@ export const URLS = {
2123
return {
2224
presentations: `${baseURL}/presentations`,
2325
self: baseURL,
24-
withVersion: `${baseURL}${queryParams}`
26+
withVersion: `${baseURL}${queryParams}`,
2527
};
26-
}
28+
},
2729
},
2830
users: {
2931
self: `/rest-api/users/me`,

0 commit comments

Comments
 (0)