From 0b3bcb3370c281e4e131e7a25c45110ad74cb046 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 15 Sep 2024 02:15:15 -0400 Subject: [PATCH 01/20] Add Jest config file. --- jest.config.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 jest.config.ts diff --git a/jest.config.ts b/jest.config.ts new file mode 100644 index 0000000..edf6551 --- /dev/null +++ b/jest.config.ts @@ -0,0 +1,11 @@ +import type { Config } from "jest"; + +const config: Config = { + verbose: true, + testEnvironment: "node", + coveragePathIgnorePatterns: [ + "/node_modules/", + ] +}; + +export default config; From 93e9ce6f9d2971f5f3e2dc421f7317b4708c7beb Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 15 Sep 2024 02:15:47 -0400 Subject: [PATCH 02/20] Remove Jest config from package.json. --- package.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/package.json b/package.json index 71af991..92f83e6 100644 --- a/package.json +++ b/package.json @@ -49,11 +49,5 @@ }, "engines": { "node": "18.18.0" - }, - "jest": { - "testEnvironment": "node", - "coveragePathIgnorePatterns": [ - "/node_modules/" - ] } } From 47fd0220d62a3a85deda2d012d0a61e878fe505c Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Mon, 16 Sep 2024 10:22:09 -0400 Subject: [PATCH 03/20] More work on test setup. --- jest.config.ts | 1 + package-lock.json | 441 +++++++++++++++++++++++++++++- package.json | 2 + src/database.ts | 14 +- src/tests/utils.ts | 36 --- {src/tests => tests}/root.test.ts | 6 +- tests/utils.ts | 69 +++++ 7 files changed, 515 insertions(+), 54 deletions(-) delete mode 100644 src/tests/utils.ts rename {src/tests => tests}/root.test.ts (70%) create mode 100644 tests/utils.ts diff --git a/jest.config.ts b/jest.config.ts index edf6551..678a7bc 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -2,6 +2,7 @@ import type { Config } from "jest"; const config: Config = { verbose: true, + preset: "ts-jest", testEnvironment: "node", coveragePathIgnorePatterns: [ "/node_modules/", diff --git a/package-lock.json b/package-lock.json index 4330bbe..8de19ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,6 +35,8 @@ "sequelize": "^6.37.1", "sha3": "^2.1.4", "supertest": "^7.0.0", + "ts-jest": "^29.2.5", + "ts-node": "^10.9.2", "typescript": "^5.4.2", "uuid": "^8.3.2", "winston": "^3.10.0" @@ -622,6 +624,26 @@ "node": ">=0.1.90" } }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@dabh/diagnostics": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@dabh/diagnostics/-/diagnostics-2.0.3.tgz", @@ -1221,6 +1243,26 @@ "@sinonjs/commons": "^3.0.0" } }, + "node_modules/@tsconfig/node10": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", + "integrity": "sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==" + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==" + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==" + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==" + }, "node_modules/@types/babel__core": { "version": "7.20.5", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", @@ -1928,6 +1970,17 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/acorn-walk": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.4.tgz", + "integrity": "sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==", + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -2011,6 +2064,11 @@ "node": ">= 8" } }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==" + }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -2291,6 +2349,17 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dependencies": { + "fast-json-stable-stringify": "2.x" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -2698,6 +2767,11 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==" + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -2836,6 +2910,14 @@ "wrappy": "1" } }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/diff-sequences": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", @@ -2898,6 +2980,20 @@ "integrity": "sha512-YsoMB/EGCohGKFyTPYqaFe2B7UCU2MM303dkoowF8DNOdks/4q/00cyhTbBUmM/0FMDoUPmUi/AJ0Aj3E7vO1A==", "peer": true }, + "node_modules/ejs": { + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", + "integrity": "sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==", + "dependencies": { + "jake": "^10.8.5" + }, + "bin": { + "ejs": "bin/cli.js" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/electron-to-chromium": { "version": "1.5.18", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.18.tgz", @@ -3757,6 +3853,33 @@ "node": "^10.12.0 || >=12.0.0" } }, + "node_modules/filelist": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz", + "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==", + "dependencies": { + "minimatch": "^5.0.1" + } + }, + "node_modules/filelist/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/filelist/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -4416,6 +4539,23 @@ "node": ">=8" } }, + "node_modules/jake": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/jake/-/jake-10.9.2.tgz", + "integrity": "sha512-2P4SQ0HrLQ+fw6llpLnOaGAvN2Zu6778SJMrCUwns4fOoG9ayrTiZk3VV8sCPkVZF8ab0zksVpS8FDY5pRCNBA==", + "dependencies": { + "async": "^3.2.3", + "chalk": "^4.0.2", + "filelist": "^1.0.4", + "minimatch": "^3.1.2" + }, + "bin": { + "jake": "bin/cli.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz", @@ -5232,6 +5372,11 @@ "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==" }, + "node_modules/lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -5285,6 +5430,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" + }, "node_modules/makeerror": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz", @@ -6252,12 +6402,9 @@ } }, "node_modules/semver": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", - "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", - "dependencies": { - "lru-cache": "^6.0.0" - }, + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", "bin": { "semver": "bin/semver.js" }, @@ -6854,6 +7001,95 @@ "typescript": ">=4.2.0" } }, + "node_modules/ts-jest": { + "version": "29.2.5", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.2.5.tgz", + "integrity": "sha512-KD8zB2aAZrcKIdGk4OwpJggeLcH1FgrICqDSROWqlnJXGCXK4Mn6FcdK2B6670Xr73lHMG1kHw8R87A0ecZ+vA==", + "dependencies": { + "bs-logger": "^0.2.6", + "ejs": "^3.1.10", + "fast-json-stable-stringify": "^2.1.0", + "jest-util": "^29.0.0", + "json5": "^2.2.3", + "lodash.memoize": "^4.1.2", + "make-error": "^1.3.6", + "semver": "^7.6.3", + "yargs-parser": "^21.1.1" + }, + "bin": { + "ts-jest": "cli.js" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || ^18.0.0 || >=20.0.0" + }, + "peerDependencies": { + "@babel/core": ">=7.0.0-beta.0 <8", + "@jest/transform": "^29.0.0", + "@jest/types": "^29.0.0", + "babel-jest": "^29.0.0", + "jest": "^29.0.0", + "typescript": ">=4.3 <6" + }, + "peerDependenciesMeta": { + "@babel/core": { + "optional": true + }, + "@jest/transform": { + "optional": true + }, + "@jest/types": { + "optional": true + }, + "babel-jest": { + "optional": true + }, + "esbuild": { + "optional": true + } + } + }, + "node_modules/ts-node": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -6998,6 +7234,11 @@ "uuid": "dist/bin/uuid" } }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==" + }, "node_modules/v8-to-istanbul": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz", @@ -7280,6 +7521,14 @@ "node": ">=12" } }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "engines": { + "node": ">=6" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", @@ -7708,6 +7957,25 @@ "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==" }, + "@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "requires": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "dependencies": { + "@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "requires": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + } + } + }, "@dabh/diagnostics": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@dabh/diagnostics/-/diagnostics-2.0.3.tgz", @@ -8168,6 +8436,26 @@ "@sinonjs/commons": "^3.0.0" } }, + "@tsconfig/node10": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", + "integrity": "sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==" + }, + "@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==" + }, + "@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==" + }, + "@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==" + }, "@types/babel__core": { "version": "7.20.5", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", @@ -8769,6 +9057,14 @@ "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", "requires": {} }, + "acorn-walk": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.4.tgz", + "integrity": "sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==", + "requires": { + "acorn": "^8.11.0" + } + }, "ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -8824,6 +9120,11 @@ "picomatch": "^2.0.4" } }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==" + }, "argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -9031,6 +9332,14 @@ "update-browserslist-db": "^1.1.0" } }, + "bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "requires": { + "fast-json-stable-stringify": "2.x" + } + }, "bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -9321,6 +9630,11 @@ "prompts": "^2.0.1" } }, + "create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==" + }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -9410,6 +9724,11 @@ "wrappy": "1" } }, + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==" + }, "diff-sequences": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", @@ -9460,6 +9779,14 @@ "integrity": "sha512-YsoMB/EGCohGKFyTPYqaFe2B7UCU2MM303dkoowF8DNOdks/4q/00cyhTbBUmM/0FMDoUPmUi/AJ0Aj3E7vO1A==", "peer": true }, + "ejs": { + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", + "integrity": "sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==", + "requires": { + "jake": "^10.8.5" + } + }, "electron-to-chromium": { "version": "1.5.18", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.18.tgz", @@ -10139,6 +10466,32 @@ "flat-cache": "^3.0.4" } }, + "filelist": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz", + "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==", + "requires": { + "minimatch": "^5.0.1" + }, + "dependencies": { + "brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "requires": { + "balanced-match": "^1.0.0" + } + }, + "minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "requires": { + "brace-expansion": "^2.0.1" + } + } + } + }, "fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -10596,6 +10949,17 @@ "istanbul-lib-report": "^3.0.0" } }, + "jake": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/jake/-/jake-10.9.2.tgz", + "integrity": "sha512-2P4SQ0HrLQ+fw6llpLnOaGAvN2Zu6778SJMrCUwns4fOoG9ayrTiZk3VV8sCPkVZF8ab0zksVpS8FDY5pRCNBA==", + "requires": { + "async": "^3.2.3", + "chalk": "^4.0.2", + "filelist": "^1.0.4", + "minimatch": "^3.1.2" + } + }, "jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz", @@ -11225,6 +11589,11 @@ "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==" }, + "lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==" + }, "lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -11269,6 +11638,11 @@ "semver": "^7.5.3" } }, + "make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" + }, "makeerror": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz", @@ -11922,12 +12296,9 @@ } }, "semver": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", - "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", - "requires": { - "lru-cache": "^6.0.0" - } + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==" }, "send": { "version": "0.18.0", @@ -12345,6 +12716,42 @@ "integrity": "sha512-RIYA36cJn2WiH9Hy77hdF9r7oEwxAtB/TS9/S4Qd90Ap4z5FSiin5zEiTL44OII1Y3IIlEvxwxFUVgrHSZ/UpA==", "requires": {} }, + "ts-jest": { + "version": "29.2.5", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.2.5.tgz", + "integrity": "sha512-KD8zB2aAZrcKIdGk4OwpJggeLcH1FgrICqDSROWqlnJXGCXK4Mn6FcdK2B6670Xr73lHMG1kHw8R87A0ecZ+vA==", + "requires": { + "bs-logger": "^0.2.6", + "ejs": "^3.1.10", + "fast-json-stable-stringify": "^2.1.0", + "jest-util": "^29.0.0", + "json5": "^2.2.3", + "lodash.memoize": "^4.1.2", + "make-error": "^1.3.6", + "semver": "^7.6.3", + "yargs-parser": "^21.1.1" + } + }, + "ts-node": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "requires": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + } + }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -12437,6 +12844,11 @@ "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" }, + "v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==" + }, "v8-to-istanbul": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz", @@ -12646,6 +13058,11 @@ "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==" }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==" + }, "yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index 92f83e6..62c03c7 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,8 @@ "sequelize": "^6.37.1", "sha3": "^2.1.4", "supertest": "^7.0.0", + "ts-jest": "^29.2.5", + "ts-node": "^10.9.2", "typescript": "^5.4.2", "uuid": "^8.3.2", "winston": "^3.10.0" diff --git a/src/database.ts b/src/database.ts index 6a05045..068d792 100644 --- a/src/database.ts +++ b/src/database.ts @@ -62,13 +62,19 @@ export enum UserType { Admin } -export function getDatabaseConnection() { +export interface DBConnectionOptions { + dbName: string; + username: string; + password: string; +} + +export function getDatabaseConnection(options?: DBConnectionOptions) { // Grab any environment variables dotenv.config(); - const dbName = process.env.DB_NAME as string; - const username = process.env.DB_USERNAME as string; - const password = process.env.DB_PASSWORD; + const dbName = options?.dbName ?? process.env.DB_NAME as string; + const username = options?.username ?? process.env.DB_USERNAME as string; + const password = options?.password ?? process.env.DB_PASSWORD as string; const database = new Sequelize(dbName, username, password, { host: process.env.DB_HOSTNAME as string, dialect: "mysql", diff --git a/src/tests/utils.ts b/src/tests/utils.ts deleted file mode 100644 index 0444f1a..0000000 --- a/src/tests/utils.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Express } from "express"; -import request from "supertest"; -import { Sequelize } from "sequelize"; - -import { setUpAssociations } from "../associations"; -import { initializeModels } from "../models"; -import { createApp } from "../server"; - -export function authorizedRequest(app: Express) { - return request(app) - .set("Authorization", process.env.CDS_API_KEY); -} - -// Just a pass-through for now -// Maybe we'll add more in the future -export function unauthorizedRequest(app: Express) { - return request(app); -} - -function createTestDatabase(): Sequelize { - const db = new Sequelize({ dialect: "mysql" }); - db.query("CREATE DATABASE IF NOT EXISTS test") - .catch(error => { - console.log(error); - throw new Error(`Error creating test database: ${error}`); - }); - return db; -} - -const testDB = createTestDatabase(); -setUpAssociations(); -initializeModels(testDB); - -const app = createApp(testDB); - -export default app; diff --git a/src/tests/root.test.ts b/tests/root.test.ts similarity index 70% rename from src/tests/root.test.ts rename to tests/root.test.ts index 3dc6148..f2ef1e2 100644 --- a/src/tests/root.test.ts +++ b/tests/root.test.ts @@ -1,8 +1,10 @@ import { describe, it } from "@jest/globals"; -import testApp, { authorizedRequest } from "./utils"; +import testApp, { authorizedRequest, runApp } from "./utils"; + +describe("Test root route", () => { + runApp(testApp); -describe("Test root route", async() => { it("Should show a welcome message", async () => { void authorizedRequest(testApp) .get("/") diff --git a/tests/utils.ts b/tests/utils.ts new file mode 100644 index 0000000..7c8f377 --- /dev/null +++ b/tests/utils.ts @@ -0,0 +1,69 @@ +import type { Express } from "express"; +import type { Server } from "http"; +import type { Test } from "supertest"; +import { Sequelize } from "sequelize"; + +import { setUpAssociations } from "../src/associations"; +import { initializeModels } from "../src/models"; +import { createApp } from "../src/server"; +import { APIKey } from "../src/models/api_key"; +import { config } from "dotenv"; +import { getDatabaseConnection } from "../src/database"; +import { createConnection, Connection } from "mysql2/promise"; + +export function authorize(request: Test): Test { + return request.set({ Authorization: process.env.CDS_API_KEY }); +} + +export async function createMySQLConnection(): Promise { + return createConnection({ + host: process.env.DB_HOSTNAME as string, + user: process.env.DB_USERNAME as string, + password: process.env.DB_PASSWORD as string, + }); +} + +export async function setupTestDatabase(): Promise { + config(); + const username = process.env.DB_USERNAME as string; + const password = process.env.DB_PASSWORD as string; + const connection = await createMySQLConnection(); + await connection.query("CREATE DATABASE IF NOT EXISTS test;"); + const db = getDatabaseConnection({ + dbName: "test", + username, + password, + }); + await db.query("USE test;"); + initializeModels(db); + setUpAssociations(); + + // We need to close when the connection terminates! + // See https://github.com/sequelize/sequelize/issues/7953 + // and https://stackoverflow.com/a/45114507 + // db.sync({ force: true, match: /test/ }).finally(() => db.close()); + await addTestData(); + + return db; +} + +export async function addAPIKey(): Promise { + // Set up some basic data that we're going to want + await APIKey.sync({ force: true }); + return APIKey.create({ + hashed_key: process.env.HASHED_API_KEY as string, + client: "Tests", + }); +} + +export async function addTestData() { + await addAPIKey(); +} + +export function createTestApp(db: Sequelize): Express { + return createApp(db); +} + +export function runApp(app: Express, port=8080, callback?: () => void): Server { + return app.listen(port, callback); +} From 79b6638ae9b36c4bebe1703f74379beedffde38e Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Mon, 16 Sep 2024 14:42:36 -0400 Subject: [PATCH 04/20] Specify engine in client rather than in each model. --- src/database.ts | 3 ++- src/models/api_key.ts | 1 - src/models/class.ts | 1 - src/models/dashboard_class_group.ts | 1 - src/models/dummy_class.ts | 3 +-- src/models/educator.ts | 1 - src/models/ignore_student.ts | 1 - src/models/question.ts | 1 - src/models/session.ts | 1 - src/models/stage.ts | 1 - src/models/stage_state.ts | 1 - src/models/story.ts | 1 - src/models/story_class.ts | 1 - src/models/story_state.ts | 1 - src/models/student.ts | 1 - src/models/student_options.ts | 1 - src/stories/hubbles_law/models/async_merged_student_classes.ts | 1 - src/stories/hubbles_law/models/galaxy.ts | 1 - src/stories/hubbles_law/models/hubble_class_data.ts | 1 - src/stories/hubbles_law/models/hubble_measurement.ts | 1 - src/stories/hubbles_law/models/hubble_student_data.ts | 1 - src/stories/hubbles_law/models/sample_measurement.ts | 1 - src/stories/hubbles_law/models/sync_merged_classes.ts | 1 - src/stories/minids/models/eclipse_response.ts | 1 - src/stories/solar-eclipse-2024/models/eclipse_data.ts | 1 - 25 files changed, 3 insertions(+), 26 deletions(-) diff --git a/src/database.ts b/src/database.ts index 068d792..f9e42c3 100644 --- a/src/database.ts +++ b/src/database.ts @@ -79,7 +79,8 @@ export function getDatabaseConnection(options?: DBConnectionOptions) { host: process.env.DB_HOSTNAME as string, dialect: "mysql", define: { - timestamps: false + timestamps: false, + engine: "InnoDB", } }); diff --git a/src/models/api_key.ts b/src/models/api_key.ts index 81cceed..a1f4f0d 100644 --- a/src/models/api_key.ts +++ b/src/models/api_key.ts @@ -35,6 +35,5 @@ export function initializeAPIKeyModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/models/class.ts b/src/models/class.ts index 0b6dd62..887058d 100644 --- a/src/models/class.ts +++ b/src/models/class.ts @@ -64,6 +64,5 @@ export function initializeClassModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/models/dashboard_class_group.ts b/src/models/dashboard_class_group.ts index 4e0e28d..e3f9221 100644 --- a/src/models/dashboard_class_group.ts +++ b/src/models/dashboard_class_group.ts @@ -31,6 +31,5 @@ export function initializeDashboardClassGroupModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/models/dummy_class.ts b/src/models/dummy_class.ts index 4309472..c395955 100644 --- a/src/models/dummy_class.ts +++ b/src/models/dummy_class.ts @@ -29,6 +29,5 @@ export function initializeDummyClassModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); -} \ No newline at end of file +} diff --git a/src/models/educator.ts b/src/models/educator.ts index 6c43f12..cdd226d 100644 --- a/src/models/educator.ts +++ b/src/models/educator.ts @@ -101,7 +101,6 @@ export function initializeEducatorModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB", indexes: [ { unique: true, diff --git a/src/models/ignore_student.ts b/src/models/ignore_student.ts index d5b067c..aa8412a 100644 --- a/src/models/ignore_student.ts +++ b/src/models/ignore_student.ts @@ -29,6 +29,5 @@ export function initializeIgnoreStudentModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/models/question.ts b/src/models/question.ts index 72a52ce..a28cbc3 100644 --- a/src/models/question.ts +++ b/src/models/question.ts @@ -67,7 +67,6 @@ export function initializeQuestionModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB", indexes: [ { fields: ["tag"] diff --git a/src/models/session.ts b/src/models/session.ts index 7d15920..275138a 100644 --- a/src/models/session.ts +++ b/src/models/session.ts @@ -29,7 +29,6 @@ export function initializeSessionModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB", tableName: "Sessions" }); } diff --git a/src/models/stage.ts b/src/models/stage.ts index 8bc5a82..b475c48 100644 --- a/src/models/stage.ts +++ b/src/models/stage.ts @@ -33,7 +33,6 @@ export function initializeStageModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB", indexes: [ { unique: true, diff --git a/src/models/stage_state.ts b/src/models/stage_state.ts index 8e224a6..2508a28 100644 --- a/src/models/stage_state.ts +++ b/src/models/stage_state.ts @@ -46,6 +46,5 @@ export function initializeStageStateModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/models/story.ts b/src/models/story.ts index 372ae42..041fbd9 100644 --- a/src/models/story.ts +++ b/src/models/story.ts @@ -26,6 +26,5 @@ export function initializeStoryModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/models/story_class.ts b/src/models/story_class.ts index 62425cb..cecf283 100644 --- a/src/models/story_class.ts +++ b/src/models/story_class.ts @@ -35,6 +35,5 @@ export function initializeClassStoryModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/models/story_state.ts b/src/models/story_state.ts index 1163f15..10d185f 100644 --- a/src/models/story_state.ts +++ b/src/models/story_state.ts @@ -40,6 +40,5 @@ export function initializeStoryStateModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/models/student.ts b/src/models/student.ts index c3a5ac4..880de77 100644 --- a/src/models/student.ts +++ b/src/models/student.ts @@ -110,7 +110,6 @@ export function initializeStudentModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB", indexes: [ { unique: true, diff --git a/src/models/student_options.ts b/src/models/student_options.ts index b7e4c50..25f2a1c 100644 --- a/src/models/student_options.ts +++ b/src/models/student_options.ts @@ -49,6 +49,5 @@ export function initializeStudentOptionsModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/stories/hubbles_law/models/async_merged_student_classes.ts b/src/stories/hubbles_law/models/async_merged_student_classes.ts index 2868e8a..79d9cb2 100644 --- a/src/stories/hubbles_law/models/async_merged_student_classes.ts +++ b/src/stories/hubbles_law/models/async_merged_student_classes.ts @@ -44,6 +44,5 @@ export function initializeAsyncMergedHubbleStudentClassesModel(sequelize: Sequel } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/stories/hubbles_law/models/galaxy.ts b/src/stories/hubbles_law/models/galaxy.ts index 10d4938..431afd6 100644 --- a/src/stories/hubbles_law/models/galaxy.ts +++ b/src/stories/hubbles_law/models/galaxy.ts @@ -86,6 +86,5 @@ export function initializeGalaxyModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/stories/hubbles_law/models/hubble_class_data.ts b/src/stories/hubbles_law/models/hubble_class_data.ts index d36a3fb..1529e36 100644 --- a/src/stories/hubbles_law/models/hubble_class_data.ts +++ b/src/stories/hubbles_law/models/hubble_class_data.ts @@ -43,7 +43,6 @@ export function initializeHubbleClassDataModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB", freezeTableName: true }); } diff --git a/src/stories/hubbles_law/models/hubble_measurement.ts b/src/stories/hubbles_law/models/hubble_measurement.ts index 5f6ade5..55d5c2f 100644 --- a/src/stories/hubbles_law/models/hubble_measurement.ts +++ b/src/stories/hubbles_law/models/hubble_measurement.ts @@ -82,6 +82,5 @@ export function initializeHubbleMeasurementModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/stories/hubbles_law/models/hubble_student_data.ts b/src/stories/hubbles_law/models/hubble_student_data.ts index 458c489..3b73e60 100644 --- a/src/stories/hubbles_law/models/hubble_student_data.ts +++ b/src/stories/hubbles_law/models/hubble_student_data.ts @@ -43,7 +43,6 @@ export function initializeHubbleStudentDataModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB", freezeTableName: true }); } diff --git a/src/stories/hubbles_law/models/sample_measurement.ts b/src/stories/hubbles_law/models/sample_measurement.ts index d106e73..f8088e3 100644 --- a/src/stories/hubbles_law/models/sample_measurement.ts +++ b/src/stories/hubbles_law/models/sample_measurement.ts @@ -89,6 +89,5 @@ export function initializeSampleHubbleMeasurementModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/stories/hubbles_law/models/sync_merged_classes.ts b/src/stories/hubbles_law/models/sync_merged_classes.ts index c35fbe7..ff1c04c 100644 --- a/src/stories/hubbles_law/models/sync_merged_classes.ts +++ b/src/stories/hubbles_law/models/sync_merged_classes.ts @@ -34,6 +34,5 @@ export function initializeSyncMergedHubbleClassesModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/stories/minids/models/eclipse_response.ts b/src/stories/minids/models/eclipse_response.ts index 64c4e02..712bb3f 100644 --- a/src/stories/minids/models/eclipse_response.ts +++ b/src/stories/minids/models/eclipse_response.ts @@ -51,6 +51,5 @@ export function initializeEclipseMiniResponseModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB" }); } diff --git a/src/stories/solar-eclipse-2024/models/eclipse_data.ts b/src/stories/solar-eclipse-2024/models/eclipse_data.ts index 067137c..bd5e00d 100644 --- a/src/stories/solar-eclipse-2024/models/eclipse_data.ts +++ b/src/stories/solar-eclipse-2024/models/eclipse_data.ts @@ -103,6 +103,5 @@ export function initializeSolarEclipse2024DataModel(sequelize: Sequelize) { } }, { sequelize, - engine: "InnoDB", }); } From 50231e25803c538f23525d908aec22a85618a4aa Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sat, 28 Sep 2024 11:41:17 -0400 Subject: [PATCH 05/20] Basic test setup seems to be working now. --- jest.config.ts | 2 ++ package.json | 4 ++-- src/app.ts | 2 +- src/database.ts | 6 +++--- src/main.ts | 13 +++++++++---- tests/root.test.ts | 36 ++++++++++++++++++++++++++++++------ 6 files changed, 47 insertions(+), 16 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index 678a7bc..3929f00 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -2,10 +2,12 @@ import type { Config } from "jest"; const config: Config = { verbose: true, + silent: false, preset: "ts-jest", testEnvironment: "node", coveragePathIgnorePatterns: [ "/node_modules/", + "/dist", ] }; diff --git a/package.json b/package.json index 62c03c7..4601642 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,9 @@ "scripts": { "build": "tsc", "lint": "node_modules/.bin/eslint src --ext .ts", - "serve": "node dist/main.js", + "serve": "node dist/src/main.js", "start": "npm run serve", - "test": "jest" + "test": "jest --config jest.config.ts --forceExit --verbose" }, "dependencies": { "@effect/schema": "^0.63.2", diff --git a/src/app.ts b/src/app.ts index fe5540e..fa5c4f4 100644 --- a/src/app.ts +++ b/src/app.ts @@ -60,7 +60,7 @@ export function setupApp(app: Express, db: Sequelize) { secure: PRODUCTION } })); - store.sync(); + // store.sync(); app.use(apiKeyMiddleware); diff --git a/src/database.ts b/src/database.ts index f9e42c3..d25a75d 100644 --- a/src/database.ts +++ b/src/database.ts @@ -63,9 +63,9 @@ export enum UserType { } export interface DBConnectionOptions { - dbName: string; - username: string; - password: string; + dbName?: string; + username?: string; + password?: string; } export function getDatabaseConnection(options?: DBConnectionOptions) { diff --git a/src/main.ts b/src/main.ts index 6dabb03..0946e7b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,8 +6,13 @@ import { getDatabaseConnection } from "./database"; const STORIES_DIR = join(__dirname, "stories"); const MAIN_FILE = "main.js"; -const db = getDatabaseConnection(); -const app = createApp(db); +// const db = getDatabaseConnection(); +// const app = createApp(db); + +import { createTestApp, runApp, setupTestDatabase } from "../tests/utils"; +const app = createTestApp(); +const db = setupTestDatabase(); + promises.readdir(STORIES_DIR, { withFileTypes: true }).then(entries => { entries.forEach(async (entry) => { if (entry.isDirectory()) { @@ -26,7 +31,7 @@ promises.readdir(STORIES_DIR, { withFileTypes: true }).then(entries => { }); // set port, listen for requests -const PORT = process.env.PORT || 8081; -app.listen(PORT, () => { +const PORT = Number(process.env.PORT) || 8081; +runApp(app, PORT, () => { console.log(`Server is running on port ${PORT}.`); }); diff --git a/tests/root.test.ts b/tests/root.test.ts index f2ef1e2..c6b360d 100644 --- a/tests/root.test.ts +++ b/tests/root.test.ts @@ -1,15 +1,39 @@ -import { describe, it } from "@jest/globals"; +/* eslint-disable @typescript-eslint/no-floating-promises */ -import testApp, { authorizedRequest, runApp } from "./utils"; +import { afterAll, beforeAll, describe, it } from "@jest/globals"; +import type { Express } from "express"; +import type { Sequelize } from "sequelize"; +import request from "supertest"; + +import { authorize, createMySQLConnection, createTestApp, setupTestDatabase } from "./utils"; +import { setupApp } from "../src/app"; + +let testDB: Sequelize; +let testApp: Express; +beforeAll(async () => { + testDB = await setupTestDatabase(); + testApp = createTestApp(testDB); + setupApp(testApp, testDB); +}, 100_000); + +afterAll(async () => { + const conn = await createMySQLConnection(); + await conn.query("DROP DATABASE test;"); +}); describe("Test root route", () => { - runApp(testApp); + + it("Should show a welcome message + warning", async () => { + authorize(request(testApp).get("/")) + .expect(200) + .expect("Content-Type", /json/) + .expect({ message: "Welcome to the CosmicDS server! You'll need to include a valid API key with your requests in order to access other endpoints." }); + }); it("Should show a welcome message", async () => { - void authorizedRequest(testApp) - .get("/") + authorize(request(testApp).get("/")) .expect(200) .expect("Content-Type", /json/) .expect({ message: "Welcome to the CosmicDS server!" }); - }); + }, 10_000); }); From 209fd16f4cc345a76bb8f7f041704db118782ffd Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sat, 28 Sep 2024 11:44:30 -0400 Subject: [PATCH 06/20] Remove some debugging stuff. --- src/main.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main.ts b/src/main.ts index 0946e7b..6dabb03 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,13 +6,8 @@ import { getDatabaseConnection } from "./database"; const STORIES_DIR = join(__dirname, "stories"); const MAIN_FILE = "main.js"; -// const db = getDatabaseConnection(); -// const app = createApp(db); - -import { createTestApp, runApp, setupTestDatabase } from "../tests/utils"; -const app = createTestApp(); -const db = setupTestDatabase(); - +const db = getDatabaseConnection(); +const app = createApp(db); promises.readdir(STORIES_DIR, { withFileTypes: true }).then(entries => { entries.forEach(async (entry) => { if (entry.isDirectory()) { @@ -31,7 +26,7 @@ promises.readdir(STORIES_DIR, { withFileTypes: true }).then(entries => { }); // set port, listen for requests -const PORT = Number(process.env.PORT) || 8081; -runApp(app, PORT, () => { +const PORT = process.env.PORT || 8081; +app.listen(PORT, () => { console.log(`Server is running on port ${PORT}.`); }); From ddb0f3bd30f4ce782e38ccaef3486327a03dd242 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sat, 28 Sep 2024 11:48:36 -0400 Subject: [PATCH 07/20] Add test step to main workflow. --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 96eebfc..a37bbff 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,3 +21,6 @@ jobs: - name: Build run: npm run build + + - name: Test + run: npm run test From 9430af6679564d80d5b5941739c078db3bf7f232 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sat, 28 Sep 2024 13:48:34 -0400 Subject: [PATCH 08/20] Use secrets as environment variables in workflow. --- .github/workflows/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a37bbff..c9a5915 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,4 +23,8 @@ jobs: run: npm run build - name: Test + env: + DB_HOSTNAME: ${{ secrets.DB_HOSTNAME }} + DB_USERNAME: ${{ secrets.DB_USERNAME }} + DB_PASSWORD: ${{ secrets.DB_PASSWORD }} run: npm run test From 147ae56c460530233837b60042070f321925dfda Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 29 Sep 2024 13:02:56 -0400 Subject: [PATCH 09/20] Use local database for testing. --- .github/workflows/main.yml | 9 ++++++--- tests/utils.ts | 10 +++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c9a5915..4348363 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,9 +22,12 @@ jobs: - name: Build run: npm run build + - name: Start MySQL service + run: sudo systemctl start mysql.service + - name: Test env: - DB_HOSTNAME: ${{ secrets.DB_HOSTNAME }} - DB_USERNAME: ${{ secrets.DB_USERNAME }} - DB_PASSWORD: ${{ secrets.DB_PASSWORD }} + TEST_DB_HOSTNAME: ${{ secrets.TEST_DB_HOSTNAME }} + TEST_DB_USERNAME: ${{ secrets.TEST_DB_USERNAME }} + TEST_DB_PASSWORD: ${{ secrets.TEST_DB_PASSWORD }} run: npm run test diff --git a/tests/utils.ts b/tests/utils.ts index 7c8f377..12a70d5 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -17,16 +17,16 @@ export function authorize(request: Test): Test { export async function createMySQLConnection(): Promise { return createConnection({ - host: process.env.DB_HOSTNAME as string, - user: process.env.DB_USERNAME as string, - password: process.env.DB_PASSWORD as string, + host: process.env.TEST_DB_HOSTNAME as string, + user: process.env.TEST_DB_USERNAME as string, + password: process.env.TEST_DB_PASSWORD as string, }); } export async function setupTestDatabase(): Promise { config(); - const username = process.env.DB_USERNAME as string; - const password = process.env.DB_PASSWORD as string; + const username = process.env.TEST_DB_USERNAME as string; + const password = process.env.TEST_DB_PASSWORD as string; const connection = await createMySQLConnection(); await connection.query("CREATE DATABASE IF NOT EXISTS test;"); const db = getDatabaseConnection({ From d763336856ad2879ddf4d656430102a3a2bd56c2 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 29 Sep 2024 13:13:06 -0400 Subject: [PATCH 10/20] Trying something else. --- tests/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils.ts b/tests/utils.ts index 12a70d5..c6d9e8f 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -17,7 +17,7 @@ export function authorize(request: Test): Test { export async function createMySQLConnection(): Promise { return createConnection({ - host: process.env.TEST_DB_HOSTNAME as string, + socketPath: "/tmp/mysql.sock", user: process.env.TEST_DB_USERNAME as string, password: process.env.TEST_DB_PASSWORD as string, }); From b1a2c72147a276576c2a67a4e2b60c835dafc846 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 29 Sep 2024 13:39:14 -0400 Subject: [PATCH 11/20] Can we create the database from the command line? --- .github/workflows/main.yml | 10 ++++++++++ tests/root.test.ts | 4 ++-- tests/utils.ts | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4348363..86b7b52 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,9 +25,19 @@ jobs: - name: Start MySQL service run: sudo systemctl start mysql.service + - name: Create database + run: | + echo "CREATE DATABASE IF NOT EXISTS test" > setup.sql + sudo mysql -h 127.0.0.1 -uroot -proot < setup.sql + - name: Test env: TEST_DB_HOSTNAME: ${{ secrets.TEST_DB_HOSTNAME }} TEST_DB_USERNAME: ${{ secrets.TEST_DB_USERNAME }} TEST_DB_PASSWORD: ${{ secrets.TEST_DB_PASSWORD }} run: npm run test + + - name: Destroy test database + run: | + echo "DROP DATABASE test" > teardown.sql + sudo mysql -h 127.0.0.1 -uroot -proot < teardown.sql diff --git a/tests/root.test.ts b/tests/root.test.ts index c6b360d..7fcb640 100644 --- a/tests/root.test.ts +++ b/tests/root.test.ts @@ -17,8 +17,8 @@ beforeAll(async () => { }, 100_000); afterAll(async () => { - const conn = await createMySQLConnection(); - await conn.query("DROP DATABASE test;"); + // const conn = await createMySQLConnection(); + // await conn.query("DROP DATABASE test;"); }); describe("Test root route", () => { diff --git a/tests/utils.ts b/tests/utils.ts index c6d9e8f..8c16c95 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -27,8 +27,8 @@ export async function setupTestDatabase(): Promise { config(); const username = process.env.TEST_DB_USERNAME as string; const password = process.env.TEST_DB_PASSWORD as string; - const connection = await createMySQLConnection(); - await connection.query("CREATE DATABASE IF NOT EXISTS test;"); + // const connection = await createMySQLConnection(); + // await connection.query("CREATE DATABASE IF NOT EXISTS test;"); const db = getDatabaseConnection({ dbName: "test", username, From a1adaf71ac842a31a293af25c0d1bf683a872210 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 29 Sep 2024 18:35:12 -0400 Subject: [PATCH 12/20] Update test database hostname. --- .github/workflows/main.yml | 16 ++++++++-------- src/database.ts | 4 +++- tests/root.test.ts | 5 ++--- tests/utils.ts | 15 +++++++++++---- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 86b7b52..8bc28c1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,10 +25,10 @@ jobs: - name: Start MySQL service run: sudo systemctl start mysql.service - - name: Create database - run: | - echo "CREATE DATABASE IF NOT EXISTS test" > setup.sql - sudo mysql -h 127.0.0.1 -uroot -proot < setup.sql + # - name: Create database + # run: | + # echo "CREATE DATABASE IF NOT EXISTS test" > setup.sql + # sudo mysql -h 127.0.0.1 -uroot -proot < setup.sql - name: Test env: @@ -37,7 +37,7 @@ jobs: TEST_DB_PASSWORD: ${{ secrets.TEST_DB_PASSWORD }} run: npm run test - - name: Destroy test database - run: | - echo "DROP DATABASE test" > teardown.sql - sudo mysql -h 127.0.0.1 -uroot -proot < teardown.sql + # - name: Destroy test database + # run: | + # echo "DROP DATABASE test" > teardown.sql + # sudo mysql -h 127.0.0.1 -uroot -proot < teardown.sql diff --git a/src/database.ts b/src/database.ts index d25a75d..b78b66e 100644 --- a/src/database.ts +++ b/src/database.ts @@ -66,6 +66,7 @@ export interface DBConnectionOptions { dbName?: string; username?: string; password?: string; + host?: string; } export function getDatabaseConnection(options?: DBConnectionOptions) { @@ -75,8 +76,9 @@ export function getDatabaseConnection(options?: DBConnectionOptions) { const dbName = options?.dbName ?? process.env.DB_NAME as string; const username = options?.username ?? process.env.DB_USERNAME as string; const password = options?.password ?? process.env.DB_PASSWORD as string; + const host = options?.host ?? process.env.DB_HOSTNAME as string; const database = new Sequelize(dbName, username, password, { - host: process.env.DB_HOSTNAME as string, + host, dialect: "mysql", define: { timestamps: false, diff --git a/tests/root.test.ts b/tests/root.test.ts index 7fcb640..826f411 100644 --- a/tests/root.test.ts +++ b/tests/root.test.ts @@ -5,7 +5,7 @@ import type { Express } from "express"; import type { Sequelize } from "sequelize"; import request from "supertest"; -import { authorize, createMySQLConnection, createTestApp, setupTestDatabase } from "./utils"; +import { authorize, createTestApp, setupTestDatabase, teardownTestDatabase } from "./utils"; import { setupApp } from "../src/app"; let testDB: Sequelize; @@ -17,8 +17,7 @@ beforeAll(async () => { }, 100_000); afterAll(async () => { - // const conn = await createMySQLConnection(); - // await conn.query("DROP DATABASE test;"); + await teardownTestDatabase(); }); describe("Test root route", () => { diff --git a/tests/utils.ts b/tests/utils.ts index 8c16c95..79a5106 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -17,7 +17,7 @@ export function authorize(request: Test): Test { export async function createMySQLConnection(): Promise { return createConnection({ - socketPath: "/tmp/mysql.sock", + host: process.env.TEST_DB_HOSTNAME as string, user: process.env.TEST_DB_USERNAME as string, password: process.env.TEST_DB_PASSWORD as string, }); @@ -27,12 +27,14 @@ export async function setupTestDatabase(): Promise { config(); const username = process.env.TEST_DB_USERNAME as string; const password = process.env.TEST_DB_PASSWORD as string; - // const connection = await createMySQLConnection(); - // await connection.query("CREATE DATABASE IF NOT EXISTS test;"); + const host = process.env.TEST_DB_HOSTNAME as string; + const connection = await createMySQLConnection(); + await connection.query("CREATE DATABASE IF NOT EXISTS test;"); const db = getDatabaseConnection({ dbName: "test", username, password, + host, }); await db.query("USE test;"); initializeModels(db); @@ -47,6 +49,11 @@ export async function setupTestDatabase(): Promise { return db; } +export async function teardownTestDatabase(): Promise { + const connection = await createMySQLConnection(); + await connection.query("DROP DATABASE test;"); +} + export async function addAPIKey(): Promise { // Set up some basic data that we're going to want await APIKey.sync({ force: true }); @@ -64,6 +71,6 @@ export function createTestApp(db: Sequelize): Express { return createApp(db); } -export function runApp(app: Express, port=8080, callback?: () => void): Server { +export function runApp(app: Express, port = 8080, callback?: () => void): Server { return app.listen(port, callback); } From 5bd485feb20847e6157cd41ae1e93decc706749f Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 29 Sep 2024 18:45:23 -0400 Subject: [PATCH 13/20] Bump Node.js version. --- .github/workflows/main.yml | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8bc28c1..bb65f7d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,6 +13,11 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20.10.0' + - name: Install modules run: npm install diff --git a/package.json b/package.json index 4601642..a92af0c 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,6 @@ "sass-loader": "^10.0.0" }, "engines": { - "node": "18.18.0" + "node": "20.10.0" } } From fef9ef9f3396432d7e6d01cf8e648eb5f168ee07 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 29 Sep 2024 18:52:22 -0400 Subject: [PATCH 14/20] Try command line again. --- .github/workflows/main.yml | 16 ++++++++-------- tests/utils.ts | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bb65f7d..9584c21 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,10 +30,10 @@ jobs: - name: Start MySQL service run: sudo systemctl start mysql.service - # - name: Create database - # run: | - # echo "CREATE DATABASE IF NOT EXISTS test" > setup.sql - # sudo mysql -h 127.0.0.1 -uroot -proot < setup.sql + - name: Create database + run: | + echo "CREATE DATABASE IF NOT EXISTS test" > setup.sql + sudo mysql -h 127.0.0.1 -uroot -proot < setup.sql - name: Test env: @@ -42,7 +42,7 @@ jobs: TEST_DB_PASSWORD: ${{ secrets.TEST_DB_PASSWORD }} run: npm run test - # - name: Destroy test database - # run: | - # echo "DROP DATABASE test" > teardown.sql - # sudo mysql -h 127.0.0.1 -uroot -proot < teardown.sql + - name: Destroy test database + run: | + echo "DROP DATABASE test" > teardown.sql + sudo mysql -h 127.0.0.1 -uroot -proot < teardown.sql diff --git a/tests/utils.ts b/tests/utils.ts index 79a5106..08f79a9 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -28,8 +28,8 @@ export async function setupTestDatabase(): Promise { const username = process.env.TEST_DB_USERNAME as string; const password = process.env.TEST_DB_PASSWORD as string; const host = process.env.TEST_DB_HOSTNAME as string; - const connection = await createMySQLConnection(); - await connection.query("CREATE DATABASE IF NOT EXISTS test;"); + // const connection = await createMySQLConnection(); + // await connection.query("CREATE DATABASE IF NOT EXISTS test;"); const db = getDatabaseConnection({ dbName: "test", username, @@ -50,8 +50,8 @@ export async function setupTestDatabase(): Promise { } export async function teardownTestDatabase(): Promise { - const connection = await createMySQLConnection(); - await connection.query("DROP DATABASE test;"); + // const connection = await createMySQLConnection(); + // await connection.query("DROP DATABASE test;"); } export async function addAPIKey(): Promise { From 1e64ba2d14ced229e96fae2154bf6cbb732123b7 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 29 Sep 2024 18:54:22 -0400 Subject: [PATCH 15/20] What options are we using? --- src/database.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/database.ts b/src/database.ts index b78b66e..2019c05 100644 --- a/src/database.ts +++ b/src/database.ts @@ -77,6 +77,7 @@ export function getDatabaseConnection(options?: DBConnectionOptions) { const username = options?.username ?? process.env.DB_USERNAME as string; const password = options?.password ?? process.env.DB_PASSWORD as string; const host = options?.host ?? process.env.DB_HOSTNAME as string; + console.log(options); const database = new Sequelize(dbName, username, password, { host, dialect: "mysql", From 3997a3bb4cb80eef5ce9c598aabb86450c03e2e9 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 29 Sep 2024 18:56:56 -0400 Subject: [PATCH 16/20] Check if hardcoded values works. --- tests/utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/utils.ts b/tests/utils.ts index 08f79a9..b7ab8da 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -25,9 +25,9 @@ export async function createMySQLConnection(): Promise { export async function setupTestDatabase(): Promise { config(); - const username = process.env.TEST_DB_USERNAME as string; - const password = process.env.TEST_DB_PASSWORD as string; - const host = process.env.TEST_DB_HOSTNAME as string; + const username = "root"; + const password = "root"; + const host = "127.0.0.1"; // const connection = await createMySQLConnection(); // await connection.query("CREATE DATABASE IF NOT EXISTS test;"); const db = getDatabaseConnection({ From d6d01043d52e8ac517ea86b0ed47cc679ee3beb0 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 29 Sep 2024 18:59:57 -0400 Subject: [PATCH 17/20] Pass hashed key into environment. --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9584c21..70e88a0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -40,6 +40,7 @@ jobs: TEST_DB_HOSTNAME: ${{ secrets.TEST_DB_HOSTNAME }} TEST_DB_USERNAME: ${{ secrets.TEST_DB_USERNAME }} TEST_DB_PASSWORD: ${{ secrets.TEST_DB_PASSWORD }} + HASHED_API_KEY: ${{ secrets.HASHED_API_KEY }} run: npm run test - name: Destroy test database From f7da84a39d409220bdbf7da225f68a8e83454a92 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 29 Sep 2024 19:22:58 -0400 Subject: [PATCH 18/20] Use environment variables again. --- .github/workflows/main.yml | 10 ++++++---- package.json | 2 +- tests/utils.ts | 12 ++++++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 70e88a0..fd36fd4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v3 with: - node-version: '20.10.0' + node-version: '18.18.0' - name: Install modules run: npm install @@ -36,10 +36,12 @@ jobs: sudo mysql -h 127.0.0.1 -uroot -proot < setup.sql - name: Test + # This is just the default settings for GH Actions MySQL + # Nothing secret here aside from the hashed API key env: - TEST_DB_HOSTNAME: ${{ secrets.TEST_DB_HOSTNAME }} - TEST_DB_USERNAME: ${{ secrets.TEST_DB_USERNAME }} - TEST_DB_PASSWORD: ${{ secrets.TEST_DB_PASSWORD }} + DB_TEST_HOSTNAME: 127.0.0.1 + DB_TEST_USERNAME: root + DB_TEST_PASSWORD: root HASHED_API_KEY: ${{ secrets.HASHED_API_KEY }} run: npm run test diff --git a/package.json b/package.json index a92af0c..4601642 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,6 @@ "sass-loader": "^10.0.0" }, "engines": { - "node": "20.10.0" + "node": "18.18.0" } } diff --git a/tests/utils.ts b/tests/utils.ts index b7ab8da..0545d52 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -17,17 +17,17 @@ export function authorize(request: Test): Test { export async function createMySQLConnection(): Promise { return createConnection({ - host: process.env.TEST_DB_HOSTNAME as string, - user: process.env.TEST_DB_USERNAME as string, - password: process.env.TEST_DB_PASSWORD as string, + host: process.env.DB_TEST_HOSTNAME as string, + user: process.env.DB_TEST_USERNAME as string, + password: process.env.DB_TEST_PASSWORD as string, }); } export async function setupTestDatabase(): Promise { config(); - const username = "root"; - const password = "root"; - const host = "127.0.0.1"; + const username = process.env.DB_TEST_HOSTNAME as string; + const password = process.env.DB_TEST_PASSWORD as string; + const host = process.env.DB_TEST_HOSTNAME as string; // const connection = await createMySQLConnection(); // await connection.query("CREATE DATABASE IF NOT EXISTS test;"); const db = getDatabaseConnection({ From 45ef5508f34d6ac9808bfaaff5e28ec5a21ab2f1 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 29 Sep 2024 19:24:27 -0400 Subject: [PATCH 19/20] Fix a typo. --- tests/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils.ts b/tests/utils.ts index 0545d52..25ad41b 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -25,7 +25,7 @@ export async function createMySQLConnection(): Promise { export async function setupTestDatabase(): Promise { config(); - const username = process.env.DB_TEST_HOSTNAME as string; + const username = process.env.DB_TEST_USERNAME as string; const password = process.env.DB_TEST_PASSWORD as string; const host = process.env.DB_TEST_HOSTNAME as string; // const connection = await createMySQLConnection(); From 5a5cba84255b3120d6fea7ca74b130f8611be376 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Sun, 29 Sep 2024 19:54:14 -0400 Subject: [PATCH 20/20] Create/destroy database in code rather than actions file. --- .github/workflows/main.yml | 10 ---------- src/database.ts | 1 - tests/utils.ts | 10 +++++----- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fd36fd4..66e15fe 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,11 +30,6 @@ jobs: - name: Start MySQL service run: sudo systemctl start mysql.service - - name: Create database - run: | - echo "CREATE DATABASE IF NOT EXISTS test" > setup.sql - sudo mysql -h 127.0.0.1 -uroot -proot < setup.sql - - name: Test # This is just the default settings for GH Actions MySQL # Nothing secret here aside from the hashed API key @@ -44,8 +39,3 @@ jobs: DB_TEST_PASSWORD: root HASHED_API_KEY: ${{ secrets.HASHED_API_KEY }} run: npm run test - - - name: Destroy test database - run: | - echo "DROP DATABASE test" > teardown.sql - sudo mysql -h 127.0.0.1 -uroot -proot < teardown.sql diff --git a/src/database.ts b/src/database.ts index 2019c05..b78b66e 100644 --- a/src/database.ts +++ b/src/database.ts @@ -77,7 +77,6 @@ export function getDatabaseConnection(options?: DBConnectionOptions) { const username = options?.username ?? process.env.DB_USERNAME as string; const password = options?.password ?? process.env.DB_PASSWORD as string; const host = options?.host ?? process.env.DB_HOSTNAME as string; - console.log(options); const database = new Sequelize(dbName, username, password, { host, dialect: "mysql", diff --git a/tests/utils.ts b/tests/utils.ts index 25ad41b..53b4712 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -15,7 +15,7 @@ export function authorize(request: Test): Test { return request.set({ Authorization: process.env.CDS_API_KEY }); } -export async function createMySQLConnection(): Promise { +export async function createTestMySQLConnection(): Promise { return createConnection({ host: process.env.DB_TEST_HOSTNAME as string, user: process.env.DB_TEST_USERNAME as string, @@ -28,8 +28,8 @@ export async function setupTestDatabase(): Promise { const username = process.env.DB_TEST_USERNAME as string; const password = process.env.DB_TEST_PASSWORD as string; const host = process.env.DB_TEST_HOSTNAME as string; - // const connection = await createMySQLConnection(); - // await connection.query("CREATE DATABASE IF NOT EXISTS test;"); + const connection = await createTestMySQLConnection(); + await connection.query("CREATE DATABASE IF NOT EXISTS test;"); const db = getDatabaseConnection({ dbName: "test", username, @@ -50,8 +50,8 @@ export async function setupTestDatabase(): Promise { } export async function teardownTestDatabase(): Promise { - // const connection = await createMySQLConnection(); - // await connection.query("DROP DATABASE test;"); + const connection = await createTestMySQLConnection(); + await connection.query("DROP DATABASE test;"); } export async function addAPIKey(): Promise {