unit tests part 1
Some checks failed
ci / build (push) Failing after 1m3s

This commit is contained in:
Christopher Hase 2025-03-31 13:59:41 +02:00
parent fa246b2fa8
commit 08441494f1
6 changed files with 50 additions and 4 deletions

View file

@ -13,5 +13,17 @@ This app will send an I-Ching horoscope to the pre-configured mailhog instance i
This app uses the I-Ching library app https://github.com/Velfi/i-ching.git.
## Configuration
It is possible to configure the intervall of days between the sending of horoscopes and the time of sending.
It is possible to configure the mail host and port.
It is also possible to configure the intervall of days between the sending of horoscopes and the time of sending. The default is to send one email every seven days at 8 am.
## First Start
The app can be deployed by running:
kubectl apply -f deployment.yaml
When a pod with the app is initally started, one email will be sent to the configured receiver.
## Testing
The Jest unit tests can be run with
npm test

27
broker.test.ts Normal file
View file

@ -0,0 +1,27 @@
import { html } from "./broker";
beforeAll(() => {
jest.spyOn(console, "log").mockImplementation(() => {});
});
test("Generate HTML for hexagram", () => {
expect(html("Hexagram No. 45 ䷬\nGathering Together [Massing]\n萃 (cuì)"))
.toBe("<br><p><div style=\"border: 1px dotted gray; border-radius: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px; padding-bottom: 10px; width: auto; display: inline-block; box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2);\"><h1>Hexagram No. 45 ䷬</h1><div style=\"border: 1px solid gray; border-radius: 25px; padding-left: 30px; padding-right: 30px; padding-top: 20px; width: auto; display: inline-block; text-align: center; box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2);\"><h2>Gathering Together [Massing] - 萃 (cuì)<br></h2></div></p>");
});
test("Generate HTML for judgement", () => {
expect(html("Judgement:\nGathering Together. Success.\nThe king approaches his temple.\nIt furthers one to see the great man.\nThis brings success. Perseverance furthers.\nTo bring great offerings creates good fortune.\nIt furthers one to undertake something."))
.toBe("<p><h3>Judgement:</h3>Gathering Together. Success.<br>The king approaches his temple.<br>It furthers one to see the great man.<br>This brings success. Perseverance furthers.<br>To bring great offerings creates good fortune.<br>It furthers one to undertake something.<br></p>");
});
test("Generate HTML for images", () => {
expect(html("Images:\nOver the earth, the lake:\nThe image of Gathering Together.\nThus the superior man renews his weapons\nIn order to meet the unforseen."))
.toBe("<p><h3>Images:</h3>Over the earth, the lake:<br>The image of Gathering Together.<br>Thus the superior man renews his weapons<br>In order to meet the unforseen.<br></p></div>");
});
afterAll(() => {
(console.log as jest.Mock).mockRestore();
});

View file

@ -137,7 +137,7 @@ function scheduleNextRun(nextRunDate: Date) {
}
// Generate 1) Parse Tree and 2) HTML
function html(inputText: string): string {
export function html(inputText: string): string {
const parseTree = parse(inputText);
const htmlOutput = render(parseTree);
@ -229,5 +229,7 @@ function render(node: Node): string {
return outputHTML;
}
}

View file

@ -1,5 +1,5 @@
{
"daysInterval": 2,
"daysInterval": 7,
"timeOfDay": "8:00",
"emailReceiver": "test@mailhog.local",
"mailHost": "mailhog.mailhog.svc.cluster.local",

5
jest.config.ts Normal file
View file

@ -0,0 +1,5 @@
module.exports = {
transform: {
"^.+\\.tsx?$": "ts-jest"
}
};

View file

@ -3,7 +3,7 @@
"version": "1.0.0",
"main": "broker.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},
"keywords": [],
"author": "",