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

Feat/testing approaches #61

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Feat/testing approaches #61

wants to merge 4 commits into from

Conversation

G0maa
Copy link
Member

@G0maa G0maa commented Oct 19, 2024

  • E2E, Integration (kind of) & unit testing (also kind of).

Copy link

netlify bot commented Oct 19, 2024

Deploy Preview for disworse ready!

Name Link
🔨 Latest commit 628abc4
🔍 Latest deploy log https://app.netlify.com/sites/disworse/deploys/6713676d5b1a5f00082380de
😎 Deploy Preview https://deploy-preview-61--disworse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +36 to +47
session({
secret: configService.getOrThrow<string>("SESSION_SECRET"),
resave: false,
saveUninitialized: false,
cookie: {
maxAge: configService.getOrThrow<number>("COOKIE_MAX_AGE"),
httpOnly: true,
},
store: new RedisStore({
client: redisClient,
}),
}),

Check warning

Code scanning / CodeQL

Clear text transmission of sensitive cookie Medium test

Sensitive cookie sent without enforcing SSL encryption.

Copilot Autofix AI 19 days ago

To fix the problem, we need to ensure that the session cookie is only transmitted over HTTPS by setting the secure attribute to true. This change should be made in the session configuration object within the beforeAll method of the TestManager class.

  1. Locate the session configuration object in the beforeAll method.
  2. Add the secure: true attribute to the cookie object within the session configuration.
Suggested changeset 1
apps/api/test/TestManager.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/apps/api/test/TestManager.ts b/apps/api/test/TestManager.ts
--- a/apps/api/test/TestManager.ts
+++ b/apps/api/test/TestManager.ts
@@ -42,2 +42,3 @@
                     httpOnly: true,
+                    secure: true,
                 },
EOF
@@ -42,2 +42,3 @@
httpOnly: true,
secure: true,
},
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link

codecov bot commented Oct 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
apps/api/src/app.resolver.ts 90.00% <100.00%> (+0.52%) ⬆️
apps/api/src/app.service.ts 100.00% <100.00%> (+18.75%) ⬆️
apps/api/src/modules/users/entities/user.entity.ts 100.00% <100.00%> (ø)

Copy link
Contributor

Choose a reason for hiding this comment

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

Why are that fields like created_at nullable?

Copy link
Member Author

Choose a reason for hiding this comment

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

@bassiounix iirc this is the type of the result of find by Drizzle.


await testManager.app.init();

// TODO: Apply Database migrations/seeders.
Copy link
Contributor

Choose a reason for hiding this comment

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

Where are the db stuff?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm... I can't recall why I didn't add them, I can work on them this weekend, but I prefer that we merge this anway.

export class TestManager {
// biome-ignore lint/suspicious/noExplicitAny: it is any.
public httpServer: any;
public app: INestApplication;
Copy link
Contributor

Choose a reason for hiding this comment

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

INestApplication<NestExpressApplication> could be more expressive. not mandatory.

@@ -0,0 +1,47 @@
import { ContextIdFactory } from "@nestjs/core";
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused imports!!!

Copy link
Contributor

@bassiounix bassiounix left a comment

Choose a reason for hiding this comment

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

Test coverage is low, not many functions are being tested.
Otherwise .. LGTM.

Copy link
Contributor

Choose a reason for hiding this comment

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

A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them.

appears when trying to run jest.

Also test:e2e shows a similar message:

Force exiting Jest: Have you considered using `--detectOpenHandles` to detect async operations that kept running after all tests finished?

Copy link
Member Author

@G0maa G0maa Oct 23, 2024

Choose a reason for hiding this comment

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

@bassiounix
The intention of this branch is not to test. The intention is to show developer working on Disworse HOW to test. With examples on Unit, E2E, and ((kind of)) integration tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also on the Jest error, I never managed to fix it, I usually silence it with --forceExit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants