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 1 commit
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
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
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/*"],
}
);
14 changes: 9 additions & 5 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@
"type": "module",
"scripts": {
"clean": "rm -rf dist",
"build": "tsc",
"build": "tsc --build --verbose",
"check-types": "tsc --noEmit",
"start": "node dist/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
12 changes: 0 additions & 12 deletions apps/server/project.json

This file was deleted.

7 changes: 7 additions & 0 deletions apps/server/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);
});
});
drazisil marked this conversation as resolved.
Show resolved Hide resolved
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"]
}
23 changes: 23 additions & 0 deletions apps/server/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
coverage: {
enabled: true,
all: true,
exclude: [
"src/**/*.spec.ts",
"src/**/*.test.ts",
"bin/**/*.ts",
"ecosystem.config.js",
"migrate.ts",
"packages/**/*.d.ts",
],
reporter: ["lcov", "text", "cobertura"],
},
reporters: ["junit", "default", "hanging-process"],
outputFile: "mcos.junit.xml",
pool: "forks",
watch: false,
},
});
9 changes: 0 additions & 9 deletions apps/server/vitest.config.js

This file was deleted.

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/*"],
}
);
14 changes: 9 additions & 5 deletions libs/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@
"types": "./dist/index.d.ts",
"scripts": {
"clean": "rm -rf dist",
"build": "tsc",
"build": "tsc --build --verbose",
"test": "vitest",
"check-types": "tsc --noEmit"
},
"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);
});
});
23 changes: 23 additions & 0 deletions libs/util/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
coverage: {
enabled: true,
all: true,
exclude: [
"src/**/*.spec.ts",
"src/**/*.test.ts",
"bin/**/*.ts",
"ecosystem.config.js",
"migrate.ts",
"packages/**/*.d.ts",
],
reporter: ["lcov", "text", "cobertura"],
},
reporters: ["junit", "default", "hanging-process"],
outputFile: "mcos.junit.xml",
pool: "forks",
watch: false,
},
});
9 changes: 0 additions & 9 deletions libs/util/vitest.config.js

This file was deleted.

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/*"],
}
);
14 changes: 9 additions & 5 deletions libs/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@
"types": "./dist/index.d.ts",
"scripts": {
"clean": "rm -rf dist",
"build": "tsc",
"build": "tsc --build --verbose",
"test": "vitest",
"check-types": "tsc --noEmit"
},
"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));
6 changes: 3 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 Down
20 changes: 18 additions & 2 deletions libs/web/src/services/AuthLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ export class AuthLogin {
this.sequelize = sequelize;
}

async create(username: string, password: string): Promise<void> {
log.debug("AuthLogin.create");
log.debug(`Creating user: ${username}`);
const user = await User.create({
username,
password,
});

log.debug(`User created: ${user ? user.username : "null"}`);
}
drazisil marked this conversation as resolved.
Show resolved Hide resolved

async login(
username: string,
password: string
Expand Down Expand Up @@ -65,7 +76,12 @@ export async function handleAuthLogin(

return {
statusCode: 200,
body: JSON.stringify(user),
headers: { "Content-Type": "application/json" },
body: `Valid=TRUE\nTicket=`,
headers: { "Content-Type": "text/plain" },
};
}

export async function createUser(username: string, password: string): Promise<void> {
const authLogin = new AuthLogin(db);
await authLogin.create(username, password);
}
drazisil marked this conversation as resolved.
Show resolved Hide resolved
38 changes: 18 additions & 20 deletions libs/web/test/AuthLogin.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { describe, expect, it } from "vitest";
import { handleAuthLogin } from "../src/services/AuthLogin.js";

import { handleAuthLogin, createUser } from "../src/services/AuthLogin.js";

describe("handleAuthLogin", () => {
it("should return 400 if username or password is empty", async () => {
const searchParams = new URLSearchParams();
searchParams.set("username", "validuser");
searchParams.set("password", "");
const info = {
headers: {},
remoteAddress: "",
method: "",
pathname: "",
headers: {},
remoteAddress: "",
method: "",
pathname: "",
searchParams,
};

Expand All @@ -26,10 +27,10 @@ describe("handleAuthLogin", () => {
searchParams.set("username", "nonexistent");
searchParams.set("password", "password");
const info = {
headers: {},
remoteAddress: "",
method: "",
pathname: "",
headers: {},
remoteAddress: "",
method: "",
pathname: "",
searchParams,
};

Expand All @@ -45,22 +46,19 @@ describe("handleAuthLogin", () => {
searchParams.set("username", "validuser");
searchParams.set("password", "password");
const info = {
headers: {},
remoteAddress: "",
method: "",
pathname: "",
headers: {},
remoteAddress: "",
method: "",
pathname: "",
searchParams,
};

await createUser("validuser", "password");

const response = await handleAuthLogin(info);

expect(response.statusCode).toBe(200);
expect(response.body).toBe(
JSON.stringify({
username: "validuser",
password: "password",
})
);
expect(response.headers).toEqual({ "Content-Type": "application/json" });
expect(response.body).toContain(`Valid=TRUE\nTicket=`);
expect(response.headers).toEqual({ "Content-Type": "text/plain" });
});
});
Loading
Loading