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

refactor: better define the api bounderies of the module #32

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b973057
refactor: better define the api bounderies of the module
drazisil Jul 26, 2024
1d8ecbe
refactor: Add customerId property to User model and AuthLogin service
drazisil Jul 26, 2024
c592226
refactor: Add customerId property to User model and AuthLogin service
drazisil Jul 26, 2024
eb1d377
feat: add config lib
drazisil Jul 26, 2024
8ef3e2e
refactor: remove unneeded complexity
drazisil Jul 26, 2024
73809f8
refactor: Remove unused script for injecting token
drazisil Jul 26, 2024
2b5d438
test: add comment explaining why 200 is the expected response code fo…
drazisil Jul 26, 2024
fcbc2c2
refactor: Remove nx.json from .gitignore
drazisil Jul 26, 2024
135028b
refactor: Add unit tests for extractCredentials and validateCredentia…
drazisil Jul 27, 2024
015bf0f
refactor: Add .github/codecov.yml for component management
drazisil Jul 27, 2024
2967c17
refactor: Update CI workflow to distribute test runs and upload cover…
drazisil Jul 27, 2024
289d76d
refactor: Update .github/codecov.yml for comment layout and visibility
drazisil Jul 27, 2024
0c6443e
refactor: Update .github/codecov.yml to show project coverage
drazisil Jul 27, 2024
7c5b372
refactor: Update log.debug statement in processWebRequests
drazisil Jul 27, 2024
7622867
refactor: Simplify processWebRequests error handling
drazisil Jul 27, 2024
3a5f229
fix(ci): change with to env
drazisil Jul 31, 2024
f7acc94
Drazisil/issue39 (#40)
drazisil Aug 1, 2024
5117f9b
Create pipeline to run full tests on main and development branches (#43)
drazisil Aug 1, 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 @@ -15,3 +15,4 @@ coverage
#$ git update-index --no-assume-unchanged <file-to-ignore>
# Credit: https://web.archive.org/web/20240726013834/https://practicalgit.com/blog/make-git-ignore-local-changes-to-tracked-files.html
nx.json
.env
2 changes: 2 additions & 0 deletions apps/server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NX_CLOUD_AUTH_TOKEN=
SENTRY_DSN=
7 changes: 5 additions & 2 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build": "tsc --build --verbose",
"check-types": "tsc --noEmit",
"lint": "eslint src",
"start": "node dist/src/index.js",
"prestart": "nx run @rusty/server:build",
"start": "node --env-file .env dist/src/index.js",
drazisil marked this conversation as resolved.
Show resolved Hide resolved
"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"
},
Expand All @@ -30,6 +31,8 @@
},
"dependencies": {
"@rusty/util": "workspace:*",
"@rusty/web": "workspace:*"
"@rusty/web": "workspace:*",
"@sentry/node": "^8.20.0",
"@sentry/profiling-node": "^8.20.0"
}
}
4 changes: 2 additions & 2 deletions apps/server/src/ServerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { WrappedServer } from "./WrappedServer.js";
import { exit } from "node:process";
import { log } from "@rusty/util";
import { handleWebRequests } from "@rusty/web";
import { processWebRequests } from "@rusty/web";

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

View check run for this annotation

Codecov / codecov/patch

apps/server/src/ServerController.ts#L7

Added line #L7 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Ensure handleWebRequests is completely removed from the codebase.

The import processWebRequests has been correctly added and used, but handleWebRequests is still present in libs/web/src/index.ts. Please remove all occurrences of handleWebRequests.

  • libs/web/src/index.ts: log.debug("web.handleWebRequests");
Analysis chain

Verify the usage of the new import and ensure the old import is removed.

The processWebRequests import replaces handleWebRequests. Ensure that the new import is used correctly and that the old import is completely removed from the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `processWebRequests` and ensure `handleWebRequests` is removed.

# Test: Search for the usage of `processWebRequests`. Expect: Only occurances of `processWebRequests`.
rg --type python -A 5 $'processWebRequests'

# Test: Ensure `handleWebRequests` is removed. Expect: No occurances of `handleWebRequests`.
rg --type python -A 5 $'handleWebRequests'

Length of output: 146


Script:

#!/bin/bash
# Description: Verify the usage of `processWebRequests` and ensure `handleWebRequests` is removed.

# Test: Search for the usage of `processWebRequests`. Expect: Only occurrences of `processWebRequests`.
rg --type typescript -A 5 $'processWebRequests'

# Test: Ensure `handleWebRequests` is removed. Expect: No occurrences of `handleWebRequests`.
rg --type typescript -A 5 $'handleWebRequests'

Length of output: 162


Script:

#!/bin/bash
# Description: Verify the usage of `processWebRequests` and ensure `handleWebRequests` is removed.

# Test: Search for the usage of `processWebRequests`. Expect: Only occurrences of `processWebRequests`.
rg -A 5 $'processWebRequests'

# Test: Ensure `handleWebRequests` is removed. Expect: No occurrences of `handleWebRequests`.
rg -A 5 $'handleWebRequests'

Length of output: 1781

Tools
GitHub Check: codecov/patch

[warning] 7-7: apps/server/src/ServerController.ts#L7
Added line #L7 was not covered by tests

import { headersToRecords } from "./headersToRecords.js";

/**
Expand All @@ -16,7 +16,7 @@
req: import("node:http").IncomingMessage,
res: import("node:http").ServerResponse
) {
const response = await handleWebRequests({
const response = await processWebRequests({

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

View check run for this annotation

Codecov / codecov/patch

apps/server/src/ServerController.ts#L19

Added line #L19 was not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved
headers: headersToRecords(req.headers),
remoteAddress: req.socket.remoteAddress || "",
method: req.method || "",
Expand Down
27 changes: 25 additions & 2 deletions apps/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
// IMPORTANT: Make sure to import `instrument.js` at the top of your file.
// If you're using ECMAScript Modules (ESM) syntax, use `import "./instrument.js";`
void import ("./instrument.js");

Check warning on line 3 in apps/server/src/index.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/index.ts#L3

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

// All other imports below
import * as Sentry from "@sentry/node";

Check warning on line 6 in apps/server/src/index.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/index.ts#L6

Added line #L6 was not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved
import { ServerController } from "./ServerController.js";

const serverController = new ServerController();
void serverController.start();
process.on("unhandledRejection", (reason, promise) => {
console.error("Unhandled Rejection at:", promise, "reason:", reason);
Sentry.captureException(reason as Error);
process.exit(1);
})

Check warning on line 13 in apps/server/src/index.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/index.ts#L9-L13

Added lines #L9 - L13 were not covered by tests
Comment on lines +9 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Consider adding tests for unhandled promise rejections.

The addition of global error handling for unhandled promise rejections enhances the robustness of the application by logging and capturing errors with Sentry.

However, consider adding tests to ensure this logic works as expected.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 9-13: apps/server/src/index.ts#L9-L13
Added lines #L9 - L13 were not covered by tests


process.on("uncaughtException", (error) => {
console.error("Uncaught Exception thrown", error);
Sentry.captureException(error);
process.exit(1);
})

Check warning on line 19 in apps/server/src/index.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/index.ts#L15-L19

Added lines #L15 - L19 were not covered by tests
Comment on lines +15 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Consider adding tests for uncaught exceptions.

The addition of global error handling for uncaught exceptions enhances the robustness of the application by logging and capturing errors with Sentry.

However, consider adding tests to ensure this logic works as expected.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 15-19: apps/server/src/index.ts#L15-L19
Added lines #L15 - L19 were not covered by tests


function main() {
const serverController = new ServerController();
void serverController.start();
}

Check warning on line 24 in apps/server/src/index.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/index.ts#L21-L24

Added lines #L21 - L24 were not covered by tests
Comment on lines +21 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Consider adding tests for the main function.

Encapsulating the server startup logic within a main function improves the organization of the code and provides a clear entry point for the application.

However, consider adding tests to ensure this logic works as expected.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 21-24: apps/server/src/index.ts#L21-L24
Added lines #L21 - L24 were not covered by tests


main();

Check warning on line 26 in apps/server/src/index.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/index.ts#L26

Added line #L26 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test coverage for the invocation of the main function.

The invocation of the main function is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 26-26: apps/server/src/index.ts#L26
Added line #L26 was not covered by tests


18 changes: 18 additions & 0 deletions apps/server/src/instrument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Import with `import * as Sentry from "@sentry/node"` if you are using ESM
drazisil marked this conversation as resolved.
Show resolved Hide resolved
import * as Sentry from "@sentry/node";
import { nodeProfilingIntegration } from "@sentry/profiling-node";

Check warning on line 3 in apps/server/src/instrument.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/instrument.ts#L2-L3

Added lines #L2 - L3 were not covered by tests

if (typeof process.env.SENTRY_DSN === "undefined" || process.env.SENTRY_DSN === "") {
console.error("No SENTRY_DSN provided");
process.exit(1);
}

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

View check run for this annotation

Codecov / codecov/patch

apps/server/src/instrument.ts#L5-L8

Added lines #L5 - L8 were not covered by tests
Comment on lines +5 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve DSN validation.

The current DSN validation only checks for undefined or empty values. Consider using a more robust validation method to ensure the DSN is a valid URL.

- if (typeof process.env.SENTRY_DSN === "undefined" || process.env.SENTRY_DSN === "") {
+ const isValidUrl = (url) => {
+   try {
+     new URL(url);
+     return true;
+   } catch (_) {
+     return false;
+   }
+ };
+ 
+ if (!isValidUrl(process.env.SENTRY_DSN)) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (typeof process.env.SENTRY_DSN === "undefined" || process.env.SENTRY_DSN === "") {
console.error("No SENTRY_DSN provided");
process.exit(1);
}
const isValidUrl = (url) => {
try {
new URL(url);
return true;
} catch (_) {
return false;
}
};
if (!isValidUrl(process.env.SENTRY_DSN)) {
console.error("No SENTRY_DSN provided");
process.exit(1);
}
Tools
GitHub Check: codecov/patch

[warning] 5-8: apps/server/src/instrument.ts#L5-L8
Added lines #L5 - L8 were not covered by tests


Sentry.init({
dsn: process.env.SENTRY_DSN,
integrations: [nodeProfilingIntegration()],

Check warning on line 12 in apps/server/src/instrument.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/instrument.ts#L10-L12

Added lines #L10 - L12 were not covered by tests
// Performance Monitoring
tracesSampleRate: 1.0, // Capture 100% of the transactions

Check warning on line 14 in apps/server/src/instrument.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/instrument.ts#L14

Added line #L14 was not covered by tests

// Set sampling rate for profiling - this is relative to tracesSampleRate
profilesSampleRate: 1.0,
});

Check warning on line 18 in apps/server/src/instrument.ts

View check run for this annotation

Codecov / codecov/patch

apps/server/src/instrument.ts#L17-L18

Added lines #L17 - L18 were not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions libs/config/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
files: ["eslint.config.js", "vitest.config.js", "**/*.d.ts"],
...tseslint.configs.disableTypeChecked,
},
{
ignores: ["**/coverage/*", "**/dist/*"],
}
);
1 change: 1 addition & 0 deletions libs/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { getServerURL } from "./src/index.js";
42 changes: 42 additions & 0 deletions libs/config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@rusty/config",
"version": "1.0.0",
"private": true,
"type": "module",
"imports": {
"#internal": "./dist/src/index.js"
},
"exports": {
".": "./dist/index.js"
},
"types": "./dist/index.d.ts",
"scripts": {
"clean": "rm -rf dist",
"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.12",
"@types/pino": "7.0.5",
"@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",
"vite": "2.0.4",
"vitest": "^2.0.4"
},
"dependencies": {
"@rusty/util": "workspace:*",
"@sentry/node": "^8.20.0",
"@sentry/profiling-node": "^8.20.0",
"pino": "9.3.1"
}
}
4 changes: 4 additions & 0 deletions libs/config/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function getServerURL(): string {
const serverURL = process.env.SERVER_URL ?? "https://rusty-motors.com";
return serverURL;
}

Check warning on line 4 in libs/config/src/config.ts

View check run for this annotation

Codecov / codecov/patch

libs/config/src/config.ts#L2-L4

Added lines #L2 - L4 were not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions libs/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { getServerURL } from "./config.js";
24 changes: 24 additions & 0 deletions libs/config/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export type rawHttpRequestData = {
headers: Record<string, string>;
remoteAddress: string;
method: string;
url: string;
};

export type parsedHttpRequestData = {
headers: Record<string, string>;
remoteAddress: string;
method: string;
pathname: string;
searchParams: URLSearchParams;
};
export type RequestResponse = {
statusCode: number;
body: string;
headers: Record<string, string>;
};

export type User = {
username: string;
password: string;
};
13 changes: 13 additions & 0 deletions libs/config/test/config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, it } from "vitest";
import { getServerURL } from "@rusty/config";

describe("config", () => {
it("should have a default serverURL if SERVER_URL environment variable is not set", () => {
expect(getServerURL()).toBe("https://rusty-motors.com");
});

it("should use the SERVER_URL environment variable if set", () => {
process.env.SERVER_URL = "https://example.com";
expect(getServerURL()).toBe("https://example.com");
});
});
11 changes: 11 additions & 0 deletions libs/config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"declarationDir": "./dist",
"composite": true
},
"include": ["index.ts", "src/**/*.ts", "test/**/*.ts"],
"exclude": ["node_modules", "dist"],
"references": [{ "path": "../util" }]
}
20 changes: 20 additions & 0 deletions libs/config/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
coverage: {
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: 2 additions & 0 deletions libs/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"vitest": "^2.0.4"
},
"dependencies": {
"@sentry/node": "^8.20.0",
"@sentry/profiling-node": "^8.20.0",
"pino": "9.3.1"
}
}
10 changes: 9 additions & 1 deletion libs/web/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
export { handleWebRequests } from "./src/index.js";
export { processWebRequests } from "./src/index.js";
export { RouteHandlers } from "./src/processors/index.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Export name change: Inconsistency found.

The function handleWebRequests has been renamed to processWebRequests, but there is still a reference to handleWebRequests in the codebase. Please update the following reference to ensure consistency:

  • libs/web/src/index.ts: log.debug("web.handleWebRequests");
Analysis chain

Export name change: Ensure consistency.

The function handleWebRequests has been renamed to processWebRequests. Ensure that all references to this function in the codebase are updated accordingly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to `handleWebRequests` are updated to `processWebRequests`.

# Test: Search for references to `handleWebRequests`. Expect: No references to `handleWebRequests`.
rg --type js 'handleWebRequests'

Length of output: 32


Script:

#!/bin/bash
# Description: Verify all references to `handleWebRequests` are updated to `processWebRequests`.

# Test: Search for references to `handleWebRequests` across all file types.
rg 'handleWebRequests'

# Test: Search for references to `processWebRequests` to confirm its presence and correct usage.
rg 'processWebRequests'

Length of output: 409

export {
ErrorUserNotFound,
handleCreateUserError,
ErrorMissingCredentials,
ErrorUserExists,
} from "./src/errors.js";
export { createUser, userLogin, deleteUser } from "./src/services/AuthLogin.js";
6 changes: 6 additions & 0 deletions libs/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "1.0.0",
"private": true,
"type": "module",
"imports": {
"#internal": "./dist/src/index.js"
},
"exports": {
".": "./dist/index.js"
},
Expand Down Expand Up @@ -32,6 +35,9 @@
},
"dependencies": {
"@rusty/util": "workspace:*",
"@sentry/node": "^8.20.0",
"@sentry/profiling-node": "^8.20.0",
"@rusty/config": "workspace:*",
"pino": "9.3.1",
"sequelize": "6.37.3",
"sqlite3": "5.1.7"
Expand Down
2 changes: 1 addition & 1 deletion libs/web/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
export const db = new Sequelize({
dialect: "sqlite",
storage: DATABASE_URL,
logging: console.log, // Enable logging
logging: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Consider the impact of disabling logging.

Disabling logging (logging: false) can enhance performance but may reduce visibility of database operations during development. Ensure that this change aligns with your logging strategy.

Additionally, the new configuration is not covered by tests.

  • The logging configuration change is only present in libs/web/src/db.ts and is not covered by any test cases.
Analysis chain

Consider the impact of disabling logging.

Disabling logging (logging: false) can enhance performance but may reduce visibility of database operations during development. Ensure that this change aligns with your logging strategy.

Additionally, the new configuration is not covered by tests.


Consider the impact of disabling logging.

Disabling logging (logging: false) can enhance performance but may reduce visibility of database operations during development. Ensure that this change aligns with your logging strategy.

Additionally, the new configuration is not covered by tests.


Consider the impact of disabling logging.

Disabling logging (logging: false) can enhance performance but may reduce visibility of database operations during development. Ensure that this change aligns with your logging strategy.

Additionally, the new configuration is not covered by tests.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify test coverage for the logging configuration change.

# Test: Search for test cases covering the db configuration. Expect: Test cases covering the db configuration.
rg --type test -A 5 'Sequelize'

Length of output: 60


Script:

#!/bin/bash
# Description: Verify test coverage for the logging configuration change.

# Find test files and search for Sequelize mentions within those files
fd --type f --extension js --extension ts --glob "*test*" | xargs rg 'Sequelize'

Length of output: 80


Script:

#!/bin/bash
# Description: Verify if the logging configuration is mentioned elsewhere in the codebase.

# Search for mentions of logging configuration in the codebase
rg 'logging:\s*false' -A 5

Length of output: 284

Tools
GitHub Check: codecov/patch

[warning] 8-9: libs/web/src/db.ts#L8-L9
Added lines #L8 - L9 were not covered by tests

});

Check warning on line 9 in libs/web/src/db.ts

View check run for this annotation

Codecov / codecov/patch

libs/web/src/db.ts#L8-L9

Added lines #L8 - L9 were not covered by tests

db.authenticate()
.then(() => db.sync())
Expand Down
32 changes: 32 additions & 0 deletions libs/web/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ErrorMissingCredentials } from "./errors.js";
import type { parsedHttpRequestData } from "./types.js";

/**
* Extracts the username and password from the parsed HTTP request data.
* @param info - The parsed HTTP request data.
* @returns An object containing the extracted username and password.
*/
export function extractCredentials(info: parsedHttpRequestData): {
username: string;
password: string;
} {
const username = (info.searchParams.get("username") as string) || "";
const password = (info.searchParams.get("password") as string) || "";
return { username, password };
}

Check warning on line 16 in libs/web/src/helpers.ts

View check run for this annotation

Codecov / codecov/patch

libs/web/src/helpers.ts#L12-L16

Added lines #L12 - L16 were not covered by tests
Comment on lines +8 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test coverage for extractCredentials.

The extractCredentials function should be covered by tests to ensure it correctly extracts the username and password.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 8-8: libs/web/src/helpers.ts#L8
Added line #L8 was not covered by tests


[warning] 11-15: libs/web/src/helpers.ts#L11-L15
Added lines #L11 - L15 were not covered by tests


/**
* Validates the provided username and password.
* @param {string} username - The username to validate.
* @param {string} password - The password to validate.
* @throws {ErrorMissingCredentials} If either the username or password is empty.
*/
export function validateCredentials(username: string, password: string): void {
if (username === "") {
throw new ErrorMissingCredentials("Username is required");
}

Check warning on line 27 in libs/web/src/helpers.ts

View check run for this annotation

Codecov / codecov/patch

libs/web/src/helpers.ts#L24-L27

Added lines #L24 - L27 were not covered by tests

if (password === "") {
throw new ErrorMissingCredentials("Password is required");
}
}

Check warning on line 32 in libs/web/src/helpers.ts

View check run for this annotation

Codecov / codecov/patch

libs/web/src/helpers.ts#L29-L32

Added lines #L29 - L32 were not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 5 additions & 14 deletions libs/web/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import { log } from "@rusty/util";
import type { parsedHttpRequestData, rawHttpRequestData, RequestResponse } from "./types.js";
import { handleAuthLogin } from "./services/AuthLogin.js";
import type { rawHttpRequestData, RequestResponse } from "./types.js";
import { RouteHandlers } from "./processors/index.js";

Check warning on line 3 in libs/web/src/index.ts

View check run for this annotation

Codecov / codecov/patch

libs/web/src/index.ts#L3

Added line #L3 was not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved
export { User } from "./models/User.js";
export type { UserAttributes } from "./models/User.js";

const RouteHandlers: Record<
string,
(info: parsedHttpRequestData) => Promise<{
statusCode: number;
body: string;
headers: Record<string, string>;
}>
> = {
"/AuthLogin": handleAuthLogin,
};

export async function handleWebRequests({
export async function processWebRequests({

Check warning on line 7 in libs/web/src/index.ts

View check run for this annotation

Codecov / codecov/patch

libs/web/src/index.ts#L7

Added line #L7 was not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved
headers,
remoteAddress,
method,
Expand Down
6 changes: 6 additions & 0 deletions libs/web/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
id: number;
username: string;
password: string;
customerId: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Consider adding tests for the new attribute.

Adding customerId to the UserAttributes interface expands the data structure to accommodate an additional identifier that links users to customers.

However, consider adding tests to ensure this new attribute is handled correctly.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

}

export interface UserCreationAttributes
Expand All @@ -17,6 +18,7 @@
declare id: number;
declare username: string;
declare password: string;
declare customerId: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Consider adding tests for the new attribute.

Declaring customerId in the User class ensures that the class instance reflects the new attribute.

However, consider adding tests to ensure this new attribute is handled correctly.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

}

User.init(
Expand All @@ -35,6 +37,10 @@
type: DataTypes.STRING,
allowNull: false,
},
customerId: {
type: DataTypes.INTEGER,
allowNull: false,
},

Check warning on line 43 in libs/web/src/models/User.ts

View check run for this annotation

Codecov / codecov/patch

libs/web/src/models/User.ts#L40-L43

Added lines #L40 - L43 were not covered by tests
Comment on lines +40 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Consider adding tests for the new schema definition.

Adding customerId to the model's schema definition in the init method specifies the data type and enforces that the field cannot be null, reinforcing data integrity.

However, consider adding tests to ensure this new schema definition is handled correctly.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 40-43: libs/web/src/models/User.ts#L40-L43
Added lines #L40 - L43 were not covered by tests

},
{
sequelize: db,
Expand Down
13 changes: 13 additions & 0 deletions libs/web/src/processors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { parsedHttpRequestData } from "../types.js";
import { authenticateUser } from "./processLogin.js";

Check warning on line 2 in libs/web/src/processors/index.ts

View check run for this annotation

Codecov / codecov/patch

libs/web/src/processors/index.ts#L2

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

export const RouteHandlers: Record<

Check warning on line 4 in libs/web/src/processors/index.ts

View check run for this annotation

Codecov / codecov/patch

libs/web/src/processors/index.ts#L4

Added line #L4 was not covered by tests
string,
(info: parsedHttpRequestData) => Promise<{
statusCode: number;
body: string;
headers: Record<string, string>;
}>
> = {
"/AuthLogin": authenticateUser,
};

Check warning on line 13 in libs/web/src/processors/index.ts

View check run for this annotation

Codecov / codecov/patch

libs/web/src/processors/index.ts#L11-L13

Added lines #L11 - L13 were not covered by tests
drazisil marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading