s1seven / schema-tools

Tools to create, validate and render certificates using Material Identity JSON schemas
https://materialidentity.org/
Apache License 2.0
1 stars 1 forks source link

test: refactor fixtures to allow multiple certs per version #212

Closed eamon0989 closed 1 year ago

eamon0989 commented 1 year ago

Description

This PR is a major refactor of both the generate-html and generate-pdf test suites. Our test suites had a limitation that meant only one valid_cert.json could be tested per version. This PR allows for multiple certificate fixtures to be used and tested. The approach I have used allows for the first certificate to be named valid_cert.json and for any subsequent certificates to be numbered, e.g. valid_cert_1.json, valid_cert_1.pdf, etc.

I have also renamed template_hbs.html to valid_cert.html to keep it inline with the json and pdf files.

I noticed that a huge portion of the test files was just passing in filepaths, and because we have a pattern that never changes, this allows the filepaths to be generated dynamically, cutting out a lot of boilerplate. To accomplish this, the html partials have been moved to their own file in the relevant fixture versions.

I have also added tests for the rendering of the Chinese fonts in PDF, the font files are stored in fixtures/fonts. Installing them as a devDependency is also a possibility, but I chose to add the files directly as only 3 are needed, and a lot more are installed when installing a package. They should not affect package size as fixtures are not included.

I also added a new script called utils/generate-fixtures-from-json.ts. Currently adding fixtures is a very cumbersome process, involving running a command with a lot of arguments. I do it regularly and still mess up the arguments sometimes. This script is an optional way to automate that process using sensible defaults. If something more robust is needed, the individual fixture can always be created using the generate-pdf/html scripts using custom arguments.

Fixes #213

Type of change

Checklist:

nx-cloud[bot] commented 1 year ago

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 376c1518e26ed047a6bd379ebea347cb0daa859d. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

πŸ“‚ See all runs for this branch


βœ… Successfully ran 4 targets - [`nx affected --target=build`](https://cloud.nx.app/runs/Zvq0TnSe4Q) - [`nx run-many --target=lint --all`](https://cloud.nx.app/runs/gyCwcMFTwk) - [`nx affected --target=test:cov`](https://cloud.nx.app/runs/5GColFOZOL) - [`nx affected --target=test:browser`](https://cloud.nx.app/runs/GnKxx1T0rH)

Sent with πŸ’Œ from NxCloud.

github-actions[bot] commented 1 year ago
Messages
:book: :thumbsup: You ticked most of the checkboxes!

Generated by :no_entry_sign: dangerJS against 376c1518e26ed047a6bd379ebea347cb0daa859d

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication