Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/54 integration test #8

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions event-catalog/events/PersonSignedInContract/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: PersonSignedInContract
version: 1
summary: |
A summary
producers:
- Producer
consumers:
- Consumer
owners:
- Name
---

<Admonition>Some information</Admonition>

### Details

Some details...

<Schema />
46 changes: 46 additions & 0 deletions event-catalog/events/PersonSignedInContract/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"detail-type": {
"type": "string",
"const": "PersonSignedInContract"
},
"detail": {
"type": "object",
"properties": {
"detail-version": {
"type": "number",
"const": 1
},
"data": {
"type": "object",
"properties": {
"userName": {
"type": "string"
},
"password": {
"type": "string"
}
},
"required": [
"userName",
"password"
],
"additionalProperties": false
}
},
"required": [
"detail-version",
"data"
],
"additionalProperties": false
}
},
"required": [
"detail",
"detail-type"
],
"additionalProperties": false,
"definitions": {}
}
12 changes: 12 additions & 0 deletions example-architecture/events/contracts/personSignedInContractV1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Contract } from "../../types";

export interface PersonSignedInContract extends Contract {
"detail-type": "PersonSignedInContract";
detail: {
"detail-version": 1;
data: {
userName: string;
password: string;
};
};
}
11 changes: 11 additions & 0 deletions src/__tests__/fixtures/contracts/testContract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Contract } from "../types.js";
export interface PersonRegisteredContract extends Contract {
"detail-type": "PersonRegisteredContract";
detail: {
"detail-version": 1;
data: {
firstName: string;
lastName: string;
};
};
}
10 changes: 10 additions & 0 deletions src/__tests__/fixtures/contracts/testContract2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Contract } from "../types.js";
export interface PersonRegisteredContract extends Contract {
"detail-type": "PersonRegisteredContract";
detail: {
"detail-version": 2;
data: {
firstName: string;
};
};
}
9 changes: 9 additions & 0 deletions src/__tests__/fixtures/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface Contract {
readonly "detail-type": string;
readonly detail: Detail;
}

export interface Detail {
readonly "detail-version": number;
readonly data: Record<string, unknown>;
}
59 changes: 59 additions & 0 deletions src/__tests__/generateDocs.integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { existsSync, readFileSync } from "fs";
import { readdir } from "fs/promises";
import path from "path";

import { rimraf } from "rimraf";
import { afterEach, describe, expect, it } from "vitest";

import { generateDocumentation } from "../generateDocs.js";

const testContractsPath = path.join(
process.cwd(),
"/src/__tests__/fixtures/contracts",
);
const testDocsPath = path.join(process.cwd(), "/src/__tests__/fixtures/docs");

describe("Create documentation for contract types, standardised for use with event catalog", () => {
afterEach(async () => {
const files = await readdir(testDocsPath);
for (const file of files) {
await rimraf(path.join(testDocsPath, file));
}
});

it("Creates documentation without error when passed valid contract types", async () => {
await generateDocumentation(testContractsPath, testDocsPath);
const savedVersionedDocs = readFileSync(
path.join(
testDocsPath,
"/PersonRegisteredContract/versioned/1/schema.json",
),
{
encoding: "utf8",
},
);
expect(savedVersionedDocs).toMatch(/("const": "PersonRegisteredContract")/);
expect(savedVersionedDocs).toMatch(/("const": 1)/);
expect(
existsSync(
path.join(
testDocsPath,
"/PersonRegisteredContract/versioned/1/index.md",
),
),
).toStrictEqual(true);
const savedUnversionedDocs = readFileSync(
path.join(testDocsPath, "/PersonRegisteredContract/schema.json"),
{
encoding: "utf8",
},
);
expect(savedUnversionedDocs).toMatch(
/("const": "PersonRegisteredContract")/i,
);
expect(savedUnversionedDocs).toMatch(/("const": 2)/i);
expect(
existsSync(path.join(testDocsPath, "/PersonRegisteredContract/index.md")),
).toStrictEqual(true);
});
});
1 change: 1 addition & 0 deletions src/helpers/generateSchemaDetails.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "path";

import { createGenerator } from "ts-json-schema-generator";

//TODO: We have to use relative paths here as apparently ts-node doesn't support esm :(
Expand Down