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

Create README.md #242

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Create README.md #242

wants to merge 10 commits into from

Conversation

skyfalir
Copy link

@skyfalir skyfalir commented Aug 7, 2023

Summary by CodeRabbit

Release Notes

  • New Feature: Added ESLint configuration for improved code quality checks.
  • Chore: Updated .gitignore to ignore .eslintcache.
  • Test: Introduced end-to-end tests for login functionality using Cypress.
  • Test: Added unit test for login function in auth API.

Here's to the code that's now more neat, 🧹
With ESLint checks, it's quite a feat. 💪
Tests for login, both E2E and unit, 🧪
Ensuring our app won't throw a fit. 🚀
So raise your glasses, let's give a cheer, 🥂
For the code that's become so dear! 🎉

@github-actions
Copy link

github-actions bot commented Aug 9, 2023

Image description CodeRabbit


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 5cdcf16 and 1c04a8b commits.
Files selected (2)
  • .eslintrc.json (1)
  • .gitignore (1)
Files ignored due to filter (2)
  • package-lock.json
  • package.json
Review comments generated (2)
  • Review: 2
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

.gitignore Outdated
Comment on lines 0 to 3
/node_modules
/dist No newline at end of file
/dist
.eslintcache
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [3-4]

It's a good practice to always end your files with a newline. This is because some tools, especially those that are used in Unix environments, might not properly recognize or handle the last line if it doesn't end with a newline.

Suggested change
/node_modules
/dist
\ No newline at end of file
/dist
.eslintcache
/node_modules
/dist
.eslintcache

.eslintrc.json Outdated
Comment on lines 1 to 13
{
"env": {
"browser": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
}
}
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

The ESLint configuration seems fine for a basic setup. However, it would be beneficial to add some specific rules that enforce code quality and consistency. Here's an example of how you might want to configure your rules:

  "rules": {
+     "indent": ["error", 2],
+     "linebreak-style": ["error", "unix"],
+     "quotes": ["error", "single"],
+     "semi": ["error", "always"],
+     "no-console": "warn"
  }

These rules enforce 2-space indentation, Unix line breaks, single quotes, semicolons at the end of lines, and warn when console functions are used.

Remember, these are just examples and you should adjust the rules according to your project's style guide.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 1c04a8b and 8964ccc commits.
Files selected (2)
  • .husky/pre-commit (1)
  • 6 (1)
Files ignored due to filter (2)
  • package-lock.json
  • package.json
Files skipped from review due to trivial changes (1)
  • .husky/pre-commit
Review comments generated (4)
  • Review: 3
  • LGTM: 1

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

6 Outdated
Comment on lines 3 to 5

56 packages are looking for funding
run `npm fund` for details
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

While it's not a code issue, it's worth noting that the message "56 packages are looking for funding" indicates that many of the project's dependencies are open-source projects seeking financial support. Consider supporting these projects if possible.

6 Outdated
Comment on lines 6 to 10

3 high severity vulnerabilities

To address all issues, run:
npm audit fix
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

The message "3 high severity vulnerabilities" is concerning. It's crucial to address these vulnerabilities as soon as possible to maintain the security of your application. Running npm audit fix as suggested should automatically fix these issues in most cases. However, some fixes may introduce breaking changes, so it's important to thoroughly test your application after running this command.

6 Outdated
Comment on lines 11 to 12

Run `npm audit` for details.
Copy link

Choose a reason for hiding this comment

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

Image description CodeRabbit

Running npm audit will provide more detailed information about the vulnerabilities in your project. This can be helpful if npm audit fix is unable to resolve all issues, as it can guide you towards manual fixes or updates.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 8964ccc and e7ef950 commits.
Files selected (7)
  • .eslintrc.json (1)
  • .gitignore (1)
  • cypress/e2e/Frontpage.cy.js (1)
  • cypress/support/commands.js (1)
  • cypress/support/e2e.js (1)
  • index.html (1)
  • src/js/api/auth/login.test.js (1)
Files ignored due to filter (4)
  • babel.config.json
  • cypress/fixtures/example.json
  • package-lock.json
  • package.json
Files not summarized due to errors (1)
  • index.html (diff tokens exceeds limit)
Files skipped from review due to trivial changes (5)
  • .eslintrc.json
  • .gitignore
  • cypress/support/commands.js
  • cypress/support/e2e.js
  • index.html (diff too large)
Review comments generated (9)
  • Review: 5
  • LGTM: 4

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +7 to +16
it("allows the user to log in and access their profile", () => {
cy.wait(1000);
cy.get("#loginButton").click();
cy.wait(1000);

cy.get("#loginEmail").type("sandersan@stud.noroff.no");
cy.get("#loginPassword").type("Sander124");
cy.get("#loginForm").submit();

cy.url().should("include", "/?view=profile");

Choose a reason for hiding this comment

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

Image description CodeRabbit

The test case for successful login seems to be hardcoding the user credentials. This could lead to maintenance issues if the credentials change in the future. Consider using environment variables or a configuration file to store these values.

-    cy.get("#loginEmail").type("sandersan@stud.noroff.no");
-    cy.get("#loginPassword").type("Sander124");
+    cy.get("#loginEmail").type(Cypress.env('username'));
+    cy.get("#loginPassword").type(Cypress.env('password'));

Comment on lines +29 to +37
it("allows the user to log out with the logout button", () => {
cy.get("#loginButton").click();
cy.wait(1000);
cy.get("#loginEmail").type("sandersan@stud.noroff.no");
cy.get("#loginPassword").type("Sander124");
cy.get("#loginForm").submit();

cy.get('[data-auth="logout"]').click();
});

Choose a reason for hiding this comment

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

Image description CodeRabbit

Similar to the previous comment, consider using environment variables or a configuration file to store user credentials.

-    cy.get("#loginEmail").type("sandersan@stud.noroff.no");
-    cy.get("#loginPassword").type("Sander124");
+    cy.get("#loginEmail").type(Cypress.env('username'));
+    cy.get("#loginPassword").type(Cypress.env('password'));

Comment on lines +1 to +8
import { login } from "./login";
import * as storage from "../../storage/index.js";
import "jest-localstorage-mock";

jest.mock("../../storage/index.js", () => ({
save: jest.fn(),
load: jest.fn(),
}));

Choose a reason for hiding this comment

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

Image description CodeRabbit

The mocking of the storage module seems fine. However, it's a good practice to restore the original implementation after the tests have run to prevent any side effects that might affect other tests. You can use afterEach for this.

+  afterEach(() => {
+    jest.restoreAllMocks();
+  });

Comment on lines +15 to +23
it("should fetch and store a token in browser storage", async () => {
const mockEmail = "test@example.com";
const mockPassword = "password";
const mockAccessToken = "mockToken";

global.fetch = jest.fn().mockResolvedValue({
ok: true,
json: jest.fn().mockResolvedValue({ token: mockAccessToken }),
});

Choose a reason for hiding this comment

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

Image description CodeRabbit

The mocking of the fetch function is done correctly. However, it's better to use jest.spyOn instead of directly assigning global.fetch. This way, you can easily restore the original function after the test using mockRestore.

- global.fetch = jest.fn().mockResolvedValue({
+ const fetchMock = jest.spyOn(global, 'fetch').mockResolvedValue({
    ok: true,
    json: jest.fn().mockResolvedValue({ token: mockAccessToken }),
  });

And then in afterEach:

+  afterEach(() => {
+    fetchMock.mockRestore();
+    jest.restoreAllMocks();
+  });

Comment on lines +24 to +40

await login(mockEmail, mockPassword);

expect(fetch).toHaveBeenCalledWith(
"https://nf-api.onrender.com/api/v1/social/auth/login",
{
method: "post",
body: JSON.stringify({ email: mockEmail, password: mockPassword }),
headers: expect.any(Object),
},
);

expect(storage.save).toHaveBeenCalledWith(
"profile",
expect.objectContaining({ token: mockAccessToken }),
);
});

Choose a reason for hiding this comment

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

Image description CodeRabbit

The test case itself looks good. It properly checks if the fetch and storage.save functions are called with the correct arguments. The usage of expect.any(Object) for headers is acceptable as we're not interested in the exact headers in this test case.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between e7ef950 and aafb6c4 commits.
Files selected (1)
  • README.md (1)
Files not summarized due to errors (1)
  • README.md (nothing obtained from openai)
Files not reviewed due to errors (1)
  • README.md (no response)
Review comments generated (0)
  • Review: 0
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

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.

1 participant