Skip to content

Commit f5e2da3

Browse files
feat: resolving merge conflicts
2 parents e99b435 + b537fa5 commit f5e2da3

22 files changed

+132
-3917
lines changed
File renamed without changes.

example-architecture/events/contracts/personRegisteredContractV1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Contract } from "../../types";
1+
import { Contract } from "../../types.js";
22
export interface PersonRegisteredContract extends Contract {
33
"detail-type": "PersonRegisteredContract";
44
detail: {

example-architecture/events/contracts/personRegisteredContractV2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Contract } from "../../types";
1+
import { Contract } from "../../types.js";
22
export interface PersonRegisteredContract extends Contract {
33
"detail-type": "PersonRegisteredContract";
44
detail: {

example-architecture/events/contracts/testContractV1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Contract } from "../../types";
1+
import { Contract } from "../../types.js";
22
export interface Test extends Contract {
33
"detail-type": "Test";
44
detail: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@
4747
"mock-fs": "^5.2.0",
4848
"vite-tsconfig-paths": "^4.2.0"
4949
}
50-
}
50+
}
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { describe, expect, it, afterEach } from "vitest";
2-
import { generateDocumentation } from "../generateDocs";
1+
import { existsSync, readFileSync } from "fs";
2+
import { readdir } from "fs/promises";
33
import path from "path";
4+
45
import { rimraf } from "rimraf";
5-
import { readdir } from "fs/promises";
6-
import { existsSync, readFileSync } from "fs";
6+
import { afterEach, describe, expect, it } from "vitest";
7+
8+
import { generateDocumentation } from "../generateDocs.js";
79

810
const testContractsPath = path.join(
911
process.cwd(),
10-
"/src/__tests__/fixtures/contracts"
12+
"/src/__tests__/fixtures/contracts",
1113
);
1214
const testDocsPath = path.join(process.cwd(), "/src/__tests__/fixtures/docs");
1315

@@ -21,37 +23,37 @@ describe("Create documentation for contract types, standardised for use with eve
2123

2224
it("Creates documentation without error when passed valid contract types", async () => {
2325
await generateDocumentation(testContractsPath, testDocsPath);
24-
var savedVersionedDocs = readFileSync(
26+
const savedVersionedDocs = readFileSync(
2527
path.join(
2628
testDocsPath,
27-
"/PersonRegisteredContract/versioned/1/schema.json"
29+
"/PersonRegisteredContract/versioned/1/schema.json",
2830
),
2931
{
3032
encoding: "utf8",
31-
}
33+
},
3234
);
3335
expect(savedVersionedDocs).toMatch(/("const": "PersonRegisteredContract")/);
3436
expect(savedVersionedDocs).toMatch(/("const": 1)/);
3537
expect(
3638
existsSync(
3739
path.join(
3840
testDocsPath,
39-
"/PersonRegisteredContract/versioned/1/index.md"
40-
)
41-
)
41+
"/PersonRegisteredContract/versioned/1/index.md",
42+
),
43+
),
4244
).toStrictEqual(true);
43-
var savedUnversionedDocs = readFileSync(
45+
const savedUnversionedDocs = readFileSync(
4446
path.join(testDocsPath, "/PersonRegisteredContract/schema.json"),
4547
{
4648
encoding: "utf8",
47-
}
49+
},
4850
);
4951
expect(savedUnversionedDocs).toMatch(
50-
/("const": "PersonRegisteredContract")/i
52+
/("const": "PersonRegisteredContract")/i,
5153
);
5254
expect(savedUnversionedDocs).toMatch(/("const": 2)/i);
5355
expect(
54-
existsSync(path.join(testDocsPath, "/PersonRegisteredContract/index.md"))
56+
existsSync(path.join(testDocsPath, "/PersonRegisteredContract/index.md")),
5557
).toStrictEqual(true);
5658
});
5759
});

src/__tests__/generateDocs.test.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
1-
import { MockedFunction, describe, expect, it, vi } from "vitest";
1+
import { describe, expect, it, type MockedFunction, vi } from "vitest";
2+
23
import {
3-
generateDocumentation, getUnversionedDocumentationFilePath, getVersionedDocumentationFilePath,
4-
} from "../generateDocs";
5-
import { generateAllContractInformation } from "../helpers/generateAllContractInformation";
6-
import { writeDocumentation } from "../helpers/writeDocumentation";
4+
generateDocumentation,
5+
getUnversionedDocumentationFilePath,
6+
getVersionedDocumentationFilePath,
7+
} from "../generateDocs.js";
8+
import { generateAllContractInformation } from "../helpers/generateAllContractInformation.js";
9+
import { writeDocumentation } from "../helpers/writeDocumentation.js";
710

811
describe("Given a generate docs script", () => {
912
describe("With function getUnversionedDocumentationFilePath to generate filepaths", () => {
10-
it("Returns a filepath based on its input", async () => {
13+
it("Returns a filepath based on its input", () => {
1114
expect(
1215
getUnversionedDocumentationFilePath(
1316
"mockPathToDocumentationFolder",
14-
"mockDetailType"
15-
)
17+
"mockDetailType",
18+
),
1619
).toStrictEqual("mockPathToDocumentationFolder/mockDetailType");
1720
});
1821
});
1922

2023
describe("With function getVersionedDocumentationFilePath to generate filepaths", () => {
21-
it("Returns a filepath based on input", async () => {
24+
it("Returns a filepath based on input", () => {
2225
expect(
2326
getVersionedDocumentationFilePath(
2427
"mockPathToDocumentationFolder",
2528
"mockDetailType",
26-
100
27-
)
29+
100,
30+
),
2831
).toStrictEqual(
29-
"mockPathToDocumentationFolder/mockDetailType/versioned/100"
32+
"mockPathToDocumentationFolder/mockDetailType/versioned/100",
3033
);
3134
});
3235
});
@@ -68,11 +71,11 @@ describe("Given a generate docs script", () => {
6871
});
6972
await generateDocumentation(
7073
"mockPathToContractsFolder",
71-
"mockPathToDocumentationFolder"
74+
"mockPathToDocumentationFolder",
7275
);
7376
expect(mockWriteDocumentation).toBeCalledWith(
7477
mockSchemaDetails,
75-
`mockPathToDocumentationFolder/mockDetailTypeConst/versioned/10`
78+
`mockPathToDocumentationFolder/mockDetailTypeConst/versioned/10`,
7679
);
7780
});
7881

@@ -83,11 +86,11 @@ describe("Given a generate docs script", () => {
8386
});
8487
await generateDocumentation(
8588
"mockPathToContractsFolder",
86-
"mockPathToDocumentationFolder"
89+
"mockPathToDocumentationFolder",
8790
);
8891
expect(mockWriteDocumentation).toBeCalledWith(
8992
mockSchemaDetails,
90-
`mockPathToDocumentationFolder/mockDetailTypeConst`
93+
`mockPathToDocumentationFolder/mockDetailTypeConst`,
9194
);
9295
});
9396
});

src/__tests__/helpers/generateAllContractInformation.test.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { MockedFunction, describe, expect, it, vi } from "vitest";
1+
import { describe, expect, it, type MockedFunction, vi } from "vitest";
2+
23
import {
34
generateAllContractInformation,
45
getContractFileNames,
56
getUpdatedNewestVersionRecord,
6-
} from "../../helpers/generateAllContractInformation";
7-
import { generateSchemaDetails } from "../../helpers/generateSchemaDetails";
7+
} from "../../helpers/generateAllContractInformation.js";
8+
import { generateSchemaDetails } from "../../helpers/generateSchemaDetails.js";
89

910
const { mockReaddir } = vi.hoisted(() => ({
1011
mockReaddir: vi.fn(),
1112
}));
1213

13-
vi.mock("fs/promises", async () => {
14+
vi.mock("fs/promises", () => {
1415
return {
1516
readdir: mockReaddir,
1617
};
@@ -70,20 +71,24 @@ describe("Given a generate docs script", () => {
7071
getUpdatedNewestVersionRecord(
7172
{ testContract: 10 },
7273
"testContract2",
73-
100
74-
)
74+
100,
75+
),
7576
).toStrictEqual({ testContract: 10, testContract2: 100 });
7677
});
7778

7879
it("Returns an updated record if we have a newer version of the contract", () => {
7980
expect(
80-
getUpdatedNewestVersionRecord({ testContract: 10 }, "testContract", 100)
81+
getUpdatedNewestVersionRecord(
82+
{ testContract: 10 },
83+
"testContract",
84+
100,
85+
),
8186
).toStrictEqual({ testContract: 100 });
8287
});
8388

8489
it("Returns the same record if we do not have a newer contract or a new contract type", () => {
8590
expect(
86-
getUpdatedNewestVersionRecord({ testContract: 10 }, "testContract", 1)
91+
getUpdatedNewestVersionRecord({ testContract: 10 }, "testContract", 1),
8792
).toStrictEqual({ testContract: 10 });
8893
});
8994
});
@@ -92,7 +97,7 @@ describe("Given a generate docs script", () => {
9297
it("Returns an array of all schemas and the record of the newest version if input is valid", async () => {
9398
mockReaddir.mockResolvedValueOnce(["singleMockContractFileName"]);
9499
expect(
95-
await generateAllContractInformation("mockPathToContractsFolder")
100+
await generateAllContractInformation("mockPathToContractsFolder"),
96101
).toStrictEqual({
97102
allSchemaDetails: [mockSchemaDetails],
98103
newestVersionsRecord: { mockDetailTypeConst: 100 },
@@ -104,10 +109,10 @@ describe("Given a generate docs script", () => {
104109
"mockContractFileNameOne",
105110
"mockContractFileNameTwo",
106111
]);
107-
expect(
108-
async () => await generateAllContractInformation("mockPathToContractsFolder")
112+
await expect(
113+
generateAllContractInformation("mockPathToContractsFolder"),
109114
).rejects.toThrow(
110-
"Contracts types error. Multiple mockDetailTypeConst contracts have been assigned the same version."
115+
"Contracts types error. Multiple mockDetailTypeConst contracts have been assigned the same version.",
111116
);
112117
});
113118
});

src/__tests__/helpers/utils.test.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { describe, expect, it } from "vitest";
22

3-
import { isInvalidDirectoryName, isValidJsonSchemaContract } from "../../helpers/utils";
3+
import {
4+
isInvalidDirectoryName,
5+
isValidJsonSchemaContract,
6+
} from "../../helpers/utils.js";
47

58
const invalidDetailTypeSchema: object = {
69
"detail-type": {
@@ -58,8 +61,8 @@ describe("Given a set of utils functions", () => {
5861
createJsonObject({
5962
...validDetailVersionSchema,
6063
...validDetailTypeSchema,
61-
})
62-
)
64+
}),
65+
),
6366
).toStrictEqual(true);
6467
});
6568

@@ -68,8 +71,8 @@ describe("Given a set of utils functions", () => {
6871
isValidJsonSchemaContract(
6972
createJsonObject({
7073
...validDetailTypeSchema,
71-
})
72-
)
74+
}),
75+
),
7376
).toStrictEqual(false);
7477
});
7578

@@ -78,8 +81,8 @@ describe("Given a set of utils functions", () => {
7881
isValidJsonSchemaContract(
7982
createJsonObject({
8083
...validDetailVersionSchema,
81-
})
82-
)
84+
}),
85+
),
8386
).toStrictEqual(false);
8487
});
8588

@@ -89,8 +92,8 @@ describe("Given a set of utils functions", () => {
8992
createJsonObject({
9093
...validDetailVersionSchema,
9194
...invalidDetailTypeSchema,
92-
})
93-
)
95+
}),
96+
),
9497
).toStrictEqual(false);
9598
});
9699

@@ -100,8 +103,8 @@ describe("Given a set of utils functions", () => {
100103
createJsonObject({
101104
...invalidDetailVersionSchema,
102105
...validDetailTypeSchema,
103-
})
104-
)
106+
}),
107+
),
105108
).toStrictEqual(false);
106109
});
107110

@@ -112,26 +115,26 @@ describe("Given a set of utils functions", () => {
112115
createJsonObject({
113116
...validDetailVersionSchema,
114117
...validDetailTypeSchema,
115-
})
116-
)
117-
)
118+
}),
119+
),
120+
),
118121
).toStrictEqual(false);
119122
});
120123
});
121124

122125
describe("With function isInvalidDirectoryName to get check if a string is a valid directory name", () => {
123126
it.each(["test", "testName", "TESTNAME123", "test-name", "test_name"])(
124127
"Function returns true if we have passed it a valid directory name without spaces",
125-
async (directoryName) => {
128+
(directoryName) => {
126129
expect(isInvalidDirectoryName(directoryName)).toStrictEqual(false);
127-
}
130+
},
128131
);
129132

130133
it.each(["test name", "test?name", "test*name", ".", ".."])(
131134
"Function returns false if we have passed it a invalid directory name",
132-
async (directoryName) => {
135+
(directoryName) => {
133136
expect(isInvalidDirectoryName(directoryName)).toStrictEqual(true);
134-
}
137+
},
135138
);
136139
});
137140
});

src/__tests__/helpers/writeIndexFile.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { describe, expect, it, vi } from "vitest";
2-
import { writeIndexFile } from "../../helpers/writeIndexFile";
2+
3+
import { writeIndexFile } from "../../helpers/writeIndexFile.js";
34

45
const { mockWriteFile } = vi.hoisted(() => ({
56
mockWriteFile: vi.fn(),
67
}));
78

8-
vi.mock("fs/promises", async () => {
9+
vi.mock("fs/promises", () => {
910
return {
1011
writeFile: mockWriteFile,
1112
};
@@ -32,14 +33,10 @@ const mockEventMarkdown =
3233
describe("Given a write index file helper", () => {
3334
describe("Which creates an index markdown file from a template", () => {
3435
it("The writeFile function is called with the expected input", async () => {
35-
const result = await writeIndexFile(
36-
"mockDocsPath",
37-
"mockDetailType",
38-
100
39-
);
36+
await writeIndexFile("mockDocsPath", "mockDetailType", 100);
4037
expect(mockWriteFile).toBeCalledWith(
4138
"mockDocsPath/index.md",
42-
mockEventMarkdown
39+
mockEventMarkdown,
4340
);
4441
});
4542
});

0 commit comments

Comments
 (0)