From ea0392b3f7464b90601581eb7c8e51b1a5329295 Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Wed, 27 Nov 2024 05:45:08 +0000 Subject: [PATCH] test: assert all cdn files are included in app (#50) ### Explanation _No response_ ### Issue _No response_ ### Attestations - [ ] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/) - [ ] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/). - [ ] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/). ### Dependencies - [ ] I have pinned the dependencies to a specific patch version. ### Style - [ ] I have run the linter and resolved any errors. - [ ] My pull request uses an appropriate title, matching the conventional commit standards. - [ ] My scope of feat/fix/chore/etc. correctly matches the nature of changes in my pull request. ### Tests - [ ] My contribution adds new code, and I have added tests to cover it. - [ ] My contribution modifies existing code, and I have updated the tests to reflect these changes. - [ ] All new and existing tests pass locally with my changes. - [ ] Code coverage remains at or above the configured threshold. ### Documentation _No response_ ### Versioning _No response_ Reviewed-on: https://codeberg.org/nhcarrigan/portfolio/pulls/50 Co-authored-by: Naomi Carrigan Co-committed-by: Naomi Carrigan --- package.json | 2 +- test/cdn.spec.ts | 105 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 test/cdn.spec.ts diff --git a/package.json b/package.json index 66a142d..d1520e3 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "next build", "start": "next start", "lint": "eslint src test --max-warnings 0", - "test": "vitest run --coverage", + "test": "op run --env-file=do.env --no-masking -- vitest run --coverage", "koikatsu": "op run --env-file=do.env --no-masking -- tsx koikatsu.ts" }, "dependencies": { diff --git a/test/cdn.spec.ts b/test/cdn.spec.ts new file mode 100644 index 0000000..4a11563 --- /dev/null +++ b/test/cdn.spec.ts @@ -0,0 +1,105 @@ +/** + * @copyright nhcarrigan + * @license Naomi's Public License + * @author Naomi Carrigan + */ + +import { ListObjectsV2Command, S3Client } from "@aws-sdk/client-s3"; +import { describe, it, expect } from "vitest"; +import { Art } from "../src/config/Art"; +import { Certifications } from "../src/config/Certifications"; +import { Games } from "../src/config/Games"; +import { Koikatsu } from "../src/config/Koikatsu"; + +const s3 = new S3Client({ + credentials: { + accessKeyId: process.env.DO_ACCESS_KEY as string, + secretAccessKey: process.env.DO_SECRET_KEY as string, + }, + endpoint: "https://sfo3.digitaloceanspaces.com", + region: "sfo3", +}); + +describe("cdn files", () => { + describe("for games", async() => { + const command = new ListObjectsV2Command({ + Bucket: "nhcarrigan-cdn", + Prefix: "games", + }); + + const { Contents } = await s3.send(command); + + const names = Contents?.map((content) => { + return content.Key?.replace("games/", ""); + }).filter(Boolean) || []; + + it.each(names)("should have %s in the Games config", (name) => { + expect.assertions(1); + const isGameInConfig = Games.some((game) => { + return game.img === name; + }); + expect(isGameInConfig, "is not in config").toBeTruthy(); + }); + }); + + describe("for koikatsu", async() => { + const command = new ListObjectsV2Command({ + Bucket: "nhcarrigan-cdn", + Prefix: "koikatsu", + }); + + const { Contents } = await s3.send(command); + + const names = Contents?.map((content) => { + return content.Key?.replace("koikatsu/", ""); + }).filter(Boolean) || []; + + it.each(names)("should have %s in the Koikatsu config", (name) => { + expect.assertions(1); + const isKoikatsuInConfig = Koikatsu.includes(name); + expect(isKoikatsuInConfig, "is not in config").toBeTruthy(); + }); + }); + + describe("for art", async() => { + const command = new ListObjectsV2Command({ + Bucket: "nhcarrigan-cdn", + Prefix: "art", + }); + + const { Contents } = await s3.send(command); + + const names = Contents?.map((content) => { + return content.Key?.replace("art/", ""); + }).filter(Boolean) || []; + + it.each(names)("should have %s in the Art config", (name) => { + expect.assertions(1); + const isArtInConfig = Art.some((art) => { + return art.img === name; + }); + expect(isArtInConfig, "is not in config").toBeTruthy(); + }); + }); + + describe("for certifications", async() => { + const command = new ListObjectsV2Command({ + Bucket: "nhcarrigan-cdn", + Prefix: "certifications", + }); + + const { Contents } = await s3.send(command); + + const names = Contents?.map((content) => { + return content.Key?.replace("certifications/", ""); + }).filter(Boolean) || []; + + it.each(names)("should have %s in the Certifications config", (name) => { + expect.assertions(1); + const isCertInConfig = Certifications.some((cert) => { + return cert.fileName === name; + }); + expect(isCertInConfig, "is not in config").toBeTruthy(); + }); + }); +});