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

chore: Update .gitignore and .npmrc, delete unused vitest.config.js f… #22

Merged
merged 39 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ceffb88
chore: Update .gitignore and .npmrc, delete unused vitest.config.js f…
drazisil Jul 25, 2024
a908395
chore: rename files back to reflect that vitest is being used, not vite
drazisil Jul 25, 2024
c0ff18b
chore: Update nx.json to include "check-types" as a dependency for th…
drazisil Jul 25, 2024
c2ad2df
refactor: Move headerstoRecords function to separate file
drazisil Jul 25, 2024
5e6abe9
chore: Add linting task for src directory
drazisil Jul 25, 2024
f43634a
Update libs/web/src/services/AuthLogin.ts
drazisil Jul 25, 2024
cdbc7f0
refactor: Update error handling in AuthLogin service
drazisil Jul 25, 2024
52379a5
refactor: Update headerstoRecords import in test file
drazisil Jul 25, 2024
e663c63
refactor: Update headerstoRecords import in test file
drazisil Jul 25, 2024
e0d5a8d
refactor: Update headerstoRecords import in test file
drazisil Jul 25, 2024
96c944f
Update ci.yml
drazisil-codecov Jul 25, 2024
75f2d97
Update ci.yml
drazisil-codecov Jul 25, 2024
8944f94
Update ci.yml
drazisil-codecov Jul 25, 2024
7dcc3d9
Update ci.yml
drazisil-codecov Jul 25, 2024
a9034d1
Update ci.yml
drazisil-codecov Jul 25, 2024
3bd8a27
Update ci.yml
drazisil-codecov Jul 25, 2024
a419fcb
Merge branch 'drazisil-codecov-patch-1' of github.com:rustymotors/rus…
drazisil Jul 25, 2024
c85538e
refactor: Update headerstoRecords import in test file
drazisil Jul 25, 2024
a0840fc
refactor: Update nx.json to include "check-types" as a dependency for…
drazisil Jul 25, 2024
18562d6
Update ci.yml
drazisil-codecov Jul 25, 2024
0c832a6
Update ci.yml
drazisil-codecov Jul 25, 2024
bc65de7
Update ci.yml
drazisil-codecov Jul 25, 2024
1e99bb0
Merge branch 'drazisil-codecov-patch-1' of github.com:rustymotors/rus…
drazisil Jul 25, 2024
d2a2c0f
Introduce error
drazisil-codecov Jul 25, 2024
f32ce8f
revert error
drazisil-codecov Jul 25, 2024
ae670da
Merge pull request #23 from rustymotors/drazisil-codecov-patch-1
drazisil-codecov Jul 25, 2024
26c5334
chore: Add test target to Makefile
drazisil Jul 25, 2024
3845a26
refactor: Add unique constraint to username field in User model
drazisil Jul 26, 2024
cd62ccc
feat: Add ErrorUserNotFound to handle user not found error in AuthLog…
drazisil Jul 26, 2024
712c3f8
Apply suggestions from code review
drazisil Jul 26, 2024
f4fba4a
Update apps/server/src/headerstoRecords.ts
drazisil Jul 26, 2024
49638b6
refactor: Update AuthLogin service to use new error class
drazisil Jul 26, 2024
80d493c
refactor: Update headerstoRecords to headersToRecords for consistency
drazisil Jul 26, 2024
e88c437
feat: Update ErrorUserNotFound class to include a constructor
drazisil Jul 26, 2024
aaaedb1
chore: Update CI workflow to use 'make test' command
drazisil Jul 26, 2024
7b17516
chore: Update .gitignore to ignore nx.json file
drazisil Jul 26, 2024
b95aaa9
chore: Update npm scripts and CI workflow
drazisil Jul 26, 2024
74592a6
chore: Update runs-on to ubuntu-22.04 in CI workflow
drazisil Jul 26, 2024
0868475
refactor: Update deleteUser function to return the number of rows aff…
drazisil Jul 26, 2024
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
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ permissions:
actions: read
contents: read


jobs:
main:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -41,3 +42,12 @@ jobs:
- run: pnpm exec nx affected -t lint build test
env:
NX_CLOUD_AUTH_TOKEN: ${{ secrets.NX_CLOUD_AUTH_TOKEN }}
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules
.nx/workspace-data
*.sqlite
coverage
*.xml
5 changes: 0 additions & 5 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
use-node-version=22.5.1
strict-peer-dependencies=false
ublish-branch=main
save-prefix=""
link-workspace-packages=false
save-workspace-protocol=rolling
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test:
pnpm exec nx affected -t lint build test

@PHONY: test
2 changes: 1 addition & 1 deletion apps/server/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export default tseslint.config(
...tseslint.configs.disableTypeChecked,
},
{
ignores: ["**/dist/*"],
ignores: ["**/coverage/*", "**/dist/*"],
}
);
17 changes: 11 additions & 6 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
"type": "module",
"scripts": {
"clean": "rm -rf dist",
"build": "tsc",
"build": "tsc --build --verbose",
"check-types": "tsc --noEmit",
"start": "node dist/index.js",
"lint": "eslint src",
"start": "node dist/src/index.js",
"test": "vitest",
"dev": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' --watch src/index.ts"
},
"keywords": [],
"author": "",
"license": "GPL-3.0-only",
"devDependencies": {
"@types/node": "^20.14.11",
"@types/node": "20.14.12",
"@types/pino": "7.0.5",
"@vitest/coverage-v8": "^2.0.3",
"eslint": "8",
"@vitest/coverage-v8": "^2.0.4",
"@vitest/ui": "^2.0.4",
"eslint": "^8.57.0",
"nx": "19.5.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
"vitest": "^1.3.1"
"vite": "2.0.4",
"vitest": "^2.0.4"
},
"dependencies": {
"@rusty/util": "workspace:*",
Expand Down
11 changes: 1 addition & 10 deletions apps/server/project.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
{
"targets": {
"test": {
"executor": "@nx/vite:test",
"options": {
"command": "vitest run",
"coverage": true,
"reporter": "verbose"
}
}
}
"projectType": "application"
}
17 changes: 1 addition & 16 deletions apps/server/src/ServerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,7 @@
import { exit } from "node:process";
import { log } from "@rusty/util";
import { handleWebRequests } from "@rusty/web";

function headerstoRecords(
headers: import("node:http").IncomingHttpHeaders
): Record<string, string> {
const result: Record<string, string> = {};
for (const [key, value] of Object.entries(headers)) {
if (Array.isArray(value)) {
result[key] = value.join(", ");
} else {
if (typeof key === "string" && typeof value === "string") {
result[key] = value;
}
}
}
return result;
}
import { headerstoRecords } from "./headerstoRecords.js";

Check warning on line 8 in apps/server/src/ServerController.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/ServerController.ts#L8

Added line #L8 was not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved

/**
*
Expand Down
13 changes: 13 additions & 0 deletions apps/server/src/headerstoRecords.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function headerstoRecords(
headers: import("node:http").IncomingHttpHeaders
drazisil marked this conversation as resolved.
Show resolved Hide resolved
): Record<string, string> {
drazisil marked this conversation as resolved.
Show resolved Hide resolved
const result: Record<string, string> = {};
for (const [key, value] of Object.entries(headers)) {
if (Array.isArray(value)) {
result[key] = value.join(", ");

Check warning on line 7 in apps/server/src/headerstoRecords.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/headerstoRecords.ts#L7

Added line #L7 was not covered by tests
} else if (typeof key === "string" && typeof value === "string") {
result[key] = value;
}
}
drazisil marked this conversation as resolved.
Show resolved Hide resolved
return result;
}
33 changes: 33 additions & 0 deletions apps/server/test/headerstoRecords.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, test } from "vitest";
import { headerstoRecords } from "../src/headerstoRecords.js";
import type { IncomingHttpHeaders } from "node:http";

describe("headerstoRecords", () => {
test("should convert headers to records", () => {
const headers: IncomingHttpHeaders = {
"content-type": "application/json",
"x-auth-token": "abc123",
accept: "application/json, text/html",
};

const expected = {
"content-type": "application/json",
"x-auth-token": "abc123",
accept: "application/json, text/html",
};

const result = headerstoRecords(headers);

expect(result).toEqual(expected);
});

test("should handle empty headers", () => {
const headers = {};

const expected = {};

const result = headerstoRecords(headers);

expect(result).toEqual(expected);
});
});
6 changes: 3 additions & 3 deletions apps/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"declarationDir": "./dist"
"declarationDir": "./dist",
"composite": true
},
"include": ["src/**/*.ts", "test/**/*.ts"],
"exclude": ["node_modules", "dist"],
"references": [{ "path": "../../libs/util" }, { "path": "../../libs/web" }]
"exclude": ["node_modules", "dist"]
}
13 changes: 12 additions & 1 deletion apps/server/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
coverage: {
provider: "v8",
enabled: true,
all: true,
exclude: [
"dist/**",
"eslint.config.js",
"vitest.config.js"
],
reporter: ["lcov", "text", "cobertura"],
},
reporters: ["junit", "default", "hanging-process"],
outputFile: "mcos.junit.xml",
pool: "forks",
watch: false,
},
});
2 changes: 1 addition & 1 deletion libs/util/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export default tseslint.config(
...tseslint.configs.disableTypeChecked,
},
{
ignores: ["**/dist/*"],
ignores: ["**/coverage/*", "**/dist/*"],
}
);
17 changes: 11 additions & 6 deletions libs/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@
"types": "./dist/index.d.ts",
"scripts": {
"clean": "rm -rf dist",
"build": "tsc",
"check-types": "tsc --noEmit"
"build": "tsc --build --verbose",
"test": "vitest",
"check-types": "tsc --noEmit",
"lint": "eslint src"
},
"keywords": [],
"author": "",
"license": "GPL-3.0-only",
"devDependencies": {
"@types/node": "^20.14.11",
"@types/node": "20.14.12",
"@types/pino": "7.0.5",
"@vitest/coverage-v8": "^2.0.3",
"eslint": "8",
"@vitest/coverage-v8": "^2.0.4",
"@vitest/ui": "^2.0.4",
"eslint": "^8.57.0",
"nx": "19.5.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
"vitest": "^1.3.1"
"vite": "2.0.4",
"vitest": "^2.0.4"
},
"dependencies": {
"pino": "9.3.1"
Expand Down
12 changes: 0 additions & 12 deletions libs/util/project.json

This file was deleted.

7 changes: 7 additions & 0 deletions libs/util/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, test, expect } from "vitest";

describe("example", () => {
test("example", () => {
expect(1).toBe(1);
});
});
15 changes: 13 additions & 2 deletions libs/util/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
coverage: {
provider: "v8",
enabled: true,
all: true,
exclude: [
"dist/**",
"eslint.config.js",
"vitest.config.js"
],
reporter: ["lcov", "text", "cobertura"],
},
reporters: ["junit", "default", "hanging-process"],
outputFile: "mcos.junit.xml",
pool: "forks",
watch: false,
},
});
});
2 changes: 1 addition & 1 deletion libs/web/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export default tseslint.config(
...tseslint.configs.disableTypeChecked,
},
{
ignores: ["**/dist/*"],
ignores: ["**/coverage/*", "**/dist/*"],
}
);
17 changes: 11 additions & 6 deletions libs/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@
"types": "./dist/index.d.ts",
"scripts": {
"clean": "rm -rf dist",
"build": "tsc",
"check-types": "tsc --noEmit"
"build": "tsc --build --verbose",
"test": "vitest",
"check-types": "tsc --noEmit",
"lint": "eslint src"
},
"keywords": [],
"author": "",
"license": "GPL-3.0-only",
"devDependencies": {
"@types/node": "^20.14.11",
"@types/node": "20.14.12",
"@types/pino": "7.0.5",
"@vitest/coverage-v8": "^2.0.3",
"eslint": "8",
"@vitest/coverage-v8": "^2.0.4",
"@vitest/ui": "^2.0.4",
"eslint": "^8.57.0",
"nx": "19.5.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
"vitest": "^1.3.1"
"vite": "2.0.4",
"vitest": "^2.0.4"
},
"dependencies": {
"@rusty/util": "workspace:*",
Expand Down
12 changes: 0 additions & 12 deletions libs/web/project.json

This file was deleted.

6 changes: 4 additions & 2 deletions libs/web/src/db.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Sequelize } from "sequelize";

const DATABASE_URL = process.env.DATABASE_URL || ":memory:";

export const db = new Sequelize({
dialect: "sqlite",
storage: "db.sqlite",
storage: DATABASE_URL,
logging: console.log, // Enable logging
});

db.authenticate()
.then(() => console.log("Database connected..."))
.then(() => db.sync())
.catch((err) => console.error("Error connecting to the database:", err));
7 changes: 4 additions & 3 deletions libs/web/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export class User
extends Model<UserAttributes, UserCreationAttributes>
implements UserAttributes
{
public id!: number;
public username!: string;
public password!: string;
declare id: number;
declare username: string;
declare password: string;
}

User.init(
Expand All @@ -29,6 +29,7 @@ User.init(
username: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
password: {
type: DataTypes.STRING,
Expand Down
Loading
Loading