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

Workflow #389

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

Workflow #389

wants to merge 34 commits into from

Conversation

EF-Pami
Copy link

@EF-Pami EF-Pami commented Jan 17, 2024

Summary by CodeRabbit

Release Notes:

  • New Feature: Introduced a new module apple.js with properties such as color, texture, animalProduct, and rating.
  • Refactor: Major overhaul of API-related modules, listeners, templates, UI, views, core utilities, and storage for improved performance and maintainability.
  • Test: Added comprehensive unit and end-to-end tests to ensure application reliability and robustness.
  • Chore: Updated linting and formatting configurations for consistent code style. Enhanced package management and audit processes.
  • Documentation: Updated README.md with workflow setup details.
  • CI Setup: Implemented GitHub Actions workflows for automated unit and end-to-end testing.
  • File Structure: Updated .gitignore for better file structure management.

Copy link

github-actions bot commented Jan 17, 2024

Image description CodeRabbit

Walkthrough

This comprehensive update introduces a robust testing framework, enhances API interactions, improves UI and view rendering, refines templates, and optimizes core utilities. It also includes linting/formatting configurations, package management updates, and continuous integration setup for automated testing. A new feature is introduced in src/js/apple.js and documentation is updated accordingly.

Changes

Category Files Summary
Test-related changes *.test.js, *.cy.js Introduced unit and end-to-end tests for various functionalities like authentication, post creation, and user interactions.
Linting and formatting configuration .eslintrc.json, .husky/pre-commit Configured ESLint for code quality checks and Husky for pre-commit hooks.
API-related changes src/js/api/*.js Enhanced API interactions with improved request headers, state management, and CRUD operations for posts and profiles.
Listener-related changes src/js/listeners/*.js Improved event listeners for authentication, post interactions, and profile actions.
Template-related changes src/js/templates/*.js Refined templates for comments, posts, and profiles to enhance UI rendering.
UI-related changes src/js/ui/*.js Optimized UI components including header, footer, modals, and view rendering.
View-related changes src/js/views/*.js Enhanced views for post lists, post pages, profile lists, and profile pages.
Core and utility changes src/js/*.js, src/js/storage/*.js, src/js/tools/*.js Optimized core utilities, data storage, and tools. Introduced a new feature in src/js/apple.js.
Package management and audit changes package.json, package-lock.json Added new packages and performed an audit.
Cypress configuration and support files changes cypress.config.js, cypress/support/*.js Configured Cypress for end-to-end testing.
File structure changes .gitignore Updated the .gitignore file to exclude unnecessary files from version control.
Documentation changes README.md Updated documentation to reflect new features, configurations, and testing setup.
Continuous Integration (CI) setup .github/workflows/*.yml Set up GitHub Actions workflows for automated unit and end-to-end testing.

🐇 "In the land of code, where logic is king,

Changes abound, improvements they bring.

Tests now ensure our functions don't fail,

Linting keeps our syntax on the trail.

APIs refined, listeners tuned just right,

Templates and views, a delightful sight.

Core utilities optimized, with new features in hand,

CI setup for tests, across the land.

So here's to the code, ever enhancing,

To bugs and errors, we're always dancing!" 🎉


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. Moreover, CodeRabbit Pro is free for open source projects.

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 1ddda9a commits.
Files selected (1)
  • .eslintrc.json (1)
Files ignored due to filter (2)
  • package-lock.json
  • package.json
Files skipped from review due to trivial changes (1)
  • .eslintrc.json
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.

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 1ddda9a and bfa910a commits.
Files selected (80)
  • src/js/api/apiBase.js (1)
  • src/js/api/auth/index.js (1)
  • src/js/api/auth/login.js (1)
  • src/js/api/auth/logout.js (1)
  • src/js/api/auth/register.js (1)
  • src/js/api/auth/state.js (1)
  • src/js/api/constants.js (1)
  • src/js/api/headers.js (2)
  • src/js/api/index.js (1)
  • src/js/api/posts/comment.js (1)
  • src/js/api/posts/create.js (1)
  • src/js/api/posts/delete.js (1)
  • src/js/api/posts/index.js (1)
  • src/js/api/posts/react.js (1)
  • src/js/api/posts/read.js (1)
  • src/js/api/posts/update.js (1)
  • src/js/api/profiles/delete.js (1)
  • src/js/api/profiles/follow.js (1)
  • src/js/api/profiles/index.js (1)
  • src/js/api/profiles/read.js (1)
  • src/js/api/profiles/unfollow.js (1)
  • src/js/api/profiles/update.js (1)
  • src/js/data/blank/post.js (1)
  • src/js/index.js (1)
  • src/js/listeners/auth/index.js (1)
  • src/js/listeners/auth/login.js (1)
  • src/js/listeners/auth/logout.js (1)
  • src/js/listeners/auth/register.js (1)
  • src/js/listeners/index.js (1)
  • src/js/listeners/post/comment.js (1)
  • src/js/listeners/post/index.js (1)
  • src/js/listeners/post/reaction.js (1)
  • src/js/listeners/profile/follow.js (1)
  • src/js/listeners/profile/index.js (1)
  • src/js/listeners/profile/unfollow.js (1)
  • src/js/router/index.js (1)
  • src/js/router/searchParams.js (1)
  • src/js/storage/index.js (1)
  • src/js/storage/load.js (1)
  • src/js/storage/save.js (1)
  • src/js/templates/comment/badge.js (1)
  • src/js/templates/comment/comment.js (3)
  • src/js/templates/comment/form.js (1)
  • src/js/templates/comment/index.js (1)
  • src/js/templates/index.js (1)
  • src/js/templates/instance.js (1)
  • src/js/templates/post/actions.js (1)
  • src/js/templates/post/comments.js (1)
  • src/js/templates/post/footer.js (1)
  • src/js/templates/post/form.js (3)
  • src/js/templates/post/header.js (1)
  • src/js/templates/post/index.js (1)
  • src/js/templates/post/loader.js (1)
  • src/js/templates/post/media.js (2)
  • src/js/templates/post/page.js (1)
  • src/js/templates/post/reactions.js (1)
  • src/js/templates/post/tabs.js (1)
  • src/js/templates/post/tags.js (1)
  • src/js/templates/post/thumbnail.js (1)
  • src/js/templates/profile/button.js (1)
  • src/js/templates/profile/followers.js (1)
  • src/js/templates/profile/following.js (1)
  • src/js/templates/profile/follows.js (1)
  • src/js/templates/profile/index.js (1)
  • src/js/templates/profile/page.js (1)
  • src/js/templates/profile/thumbnail.js (1)
  • src/js/tools/clear.js (1)
  • src/js/tools/emojiSubset.js (1)
  • src/js/tools/index.js (1)
  • src/js/ui/auth.js (1)
  • src/js/ui/footer.js (1)
  • src/js/ui/header.js (1)
  • src/js/ui/index.js (1)
  • src/js/ui/modals.js (1)
  • src/js/ui/renderView.js (1)
  • src/js/views/index.js (1)
  • src/js/views/postList.js (1)
  • src/js/views/postPage.js (2)
  • src/js/views/profileList.js (1)
  • src/js/views/profilePage.js (1)
Files ignored due to filter (1)
  • package.json
Files skipped from review due to trivial changes (79)
  • src/js/api/apiBase.js
  • src/js/api/auth/index.js
  • src/js/api/auth/logout.js
  • src/js/api/auth/register.js
  • src/js/api/auth/state.js
  • src/js/api/constants.js
  • src/js/api/headers.js
  • src/js/api/index.js
  • src/js/api/posts/comment.js
  • src/js/api/posts/create.js
  • src/js/api/posts/delete.js
  • src/js/api/posts/index.js
  • src/js/api/posts/react.js
  • src/js/api/posts/read.js
  • src/js/api/posts/update.js
  • src/js/api/profiles/delete.js
  • src/js/api/profiles/follow.js
  • src/js/api/profiles/index.js
  • src/js/api/profiles/read.js
  • src/js/api/profiles/unfollow.js
  • src/js/api/profiles/update.js
  • src/js/data/blank/post.js
  • src/js/index.js
  • src/js/listeners/auth/index.js
  • src/js/listeners/auth/login.js
  • src/js/listeners/auth/logout.js
  • src/js/listeners/auth/register.js
  • src/js/listeners/index.js
  • src/js/listeners/post/comment.js
  • src/js/listeners/post/index.js
  • src/js/listeners/post/reaction.js
  • src/js/listeners/profile/follow.js
  • src/js/listeners/profile/index.js
  • src/js/listeners/profile/unfollow.js
  • src/js/router/index.js
  • src/js/router/searchParams.js
  • src/js/storage/index.js
  • src/js/storage/load.js
  • src/js/storage/save.js
  • src/js/templates/comment/badge.js
  • src/js/templates/comment/comment.js
  • src/js/templates/comment/form.js
  • src/js/templates/comment/index.js
  • src/js/templates/index.js
  • src/js/templates/instance.js
  • src/js/templates/post/actions.js
  • src/js/templates/post/comments.js
  • src/js/templates/post/footer.js
  • src/js/templates/post/form.js
  • src/js/templates/post/header.js
  • src/js/templates/post/index.js
  • src/js/templates/post/loader.js
  • src/js/templates/post/media.js
  • src/js/templates/post/page.js
  • src/js/templates/post/reactions.js
  • src/js/templates/post/tabs.js
  • src/js/templates/post/tags.js
  • src/js/templates/post/thumbnail.js
  • src/js/templates/profile/button.js
  • src/js/templates/profile/followers.js
  • src/js/templates/profile/following.js
  • src/js/templates/profile/follows.js
  • src/js/templates/profile/index.js
  • src/js/templates/profile/page.js
  • src/js/templates/profile/thumbnail.js
  • src/js/tools/clear.js
  • src/js/tools/emojiSubset.js
  • src/js/tools/index.js
  • src/js/ui/auth.js
  • src/js/ui/footer.js
  • src/js/ui/header.js
  • src/js/ui/index.js
  • src/js/ui/modals.js
  • src/js/ui/renderView.js
  • src/js/views/index.js
  • src/js/views/postList.js
  • src/js/views/postPage.js
  • src/js/views/profileList.js
  • src/js/views/profilePage.js
Review comments generated (1)
  • Review: 1
  • 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.

Comment on lines 0 to 21
import { apiPath } from "../constants.js";
import { headers } from "../headers.js";
import { save } from '../../storage/index.js'
import { save } from "../../storage/index.js";

export async function login(email, password) {
const response = await fetch(`${apiPath}/social/auth/login`, {
method: "post",
body: JSON.stringify({ email, password }),
headers: headers("application/json")
})
headers: headers("application/json"),
});

if (response.ok) {
const profile = await response.json()
save("token", profile.accessToken)
delete profile.accessToken
save("profile", profile)
return profile
const profile = await response.json();
save("token", profile.accessToken);
delete profile.accessToken;
save("profile", profile);
return profile;
}

throw new Error(response.statusText)
} No newline at end of file
throw new Error(response.statusText);
}

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 [5-22]

The login function does not handle the case when the fetch request fails (e.g., network error). This could lead to unhandled promise rejections. It's a good practice to wrap fetch calls in a try-catch block to handle potential errors.

 export async function login(email, password) {
+   try {
   const response = await fetch(`${apiPath}/social/auth/login`, {
     method: "post",
     body: JSON.stringify({ email, password }),
    headers: headers("application/json"),
  });
 
   if (response.ok) {
    const profile = await response.json();
    save("token", profile.accessToken);
    delete profile.accessToken;
    save("profile", profile);
    return profile;
   }
 
  throw new Error(response.statusText);
+   } catch (error) {
+     console.error(error);
+     throw error;
+   }
}

Also, it would be better to use more specific error messages for different types of errors (network error, non-ok response status), instead of throwing the same response.statusText for all cases.

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 bfa910a and b530979 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 (1)
  • Review: 1
  • 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.

6
Comment on lines +1 to +12

added 54 packages, and audited 368 packages in 4s

60 packages are looking for funding
run `npm fund` for details

3 high severity vulnerabilities

To address all issues (including breaking changes), run:
npm audit fix --force

Run `npm audit` for details.

Choose a reason for hiding this comment

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

Image description CodeRabbit

The changes made in this hunk are related to the package management and audit. It seems like there are 3 high severity vulnerabilities found during the audit. While npm audit fix --force can be used to automatically install any updates that break the current code, it's not always the best solution as it might introduce breaking changes into your application.

Instead of using npm audit fix --force, I would recommend manually reviewing and addressing each vulnerability. This way, you can ensure that the fixes don't unintentionally break other parts of your application. You can use npm audit for more details about each vulnerability.

- To address all issues (including breaking changes), run:
-   npm audit fix --force
+ To address all issues individually, review the output of:
+   npm audit

This change will encourage developers to take a more careful approach when dealing with security vulnerabilities.

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 b530979 and f5aeb40 commits.
Files selected (1)
  • .eslintrc.json (1)
Files ignored due to filter (2)
  • package-lock.json
  • package.json
Files skipped from review due to trivial changes (1)
  • .eslintrc.json
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.

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 b530979 and 58d6f0a commits.
Files selected (2)
  • .eslintrc.json (1)
  • src/js/app.test.js (1)
Files ignored due to filter (2)
  • package-lock.json
  • package.json
Files skipped from review due to trivial changes (2)
  • .eslintrc.json
  • src/js/app.test.js
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.

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 58d6f0a and b68ebbe commits.
Files selected (2)
  • src/js/apple.js (1)
  • src/js/apple.test.js (1)
Files ignored due to filter (3)
  • babel.config.json
  • package-lock.json
  • package.json
Files skipped from review due to trivial changes (1)
  • src/js/apple.js
Review comments generated (1)
  • Review: 0
  • 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.

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 b68ebbe and 45ca825 commits.
Files selected (5)
  • .eslintrc.json (1)
  • .gitignore (1)
  • cypress.config.js (1)
  • cypress/support/commands.js (1)
  • cypress/support/e2e.js (1)
Files ignored due to filter (3)
  • cypress/fixtures/example.json
  • package-lock.json
  • package.json
Files skipped from review due to trivial changes (4)
  • .eslintrc.json
  • .gitignore
  • cypress/support/commands.js
  • cypress/support/e2e.js
Review comments generated (1)
  • Review: 1
  • 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.

Comment on lines +1 to +9
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});

Choose a reason for hiding this comment

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

Image description CodeRabbit

The new hunk introduces a configuration for Cypress using defineConfig. However, the setupNodeEvents function is empty. If there are no node events to set up, consider removing this function to avoid confusion. If you plan to add event listeners in the future, please add a comment indicating this.

-    setupNodeEvents(on, config) {
-      // implement node event listeners here
-    },

If you plan to add event listeners in the future, it would be better to leave a more descriptive comment:

+    setupNodeEvents(on, config) {
+      // TODO: Implement node event listeners as required by the tests
+    },

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 45ca825 and 3893fcd commits.
Files selected (6)
  • cypress/e2e/login.cy.js (1)
  • cypress/e2e/logout.cy.js (1)
  • src/js/api/auth/login.test.js (1)
  • src/js/api/auth/logout.test.js (1)
  • src/js/api/posts/create.test.js (1)
  • src/js/storage/localStorage.mock.js (1)
Files skipped from review due to trivial changes (2)
  • src/js/api/auth/login.test.js
  • src/js/api/posts/create.test.js
Review comments generated (7)
  • Review: 6
  • 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.

Comment on lines +1 to +8
describe('Login Form', () => {
it('can login with valid credentials', () => {
cy.visit('./');
cy.get('input[name=email]').first().type('valid-name@example.com');
cy.get('input[name=password]').first().type('valid-password');
cy.get('#loginForm').submit();
cy.wait(3500);
});

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 logging in with valid credentials does not include any assertions. It's important to verify the outcome of the login attempt, such as checking if the user is redirected to the correct page or if a specific element appears on the page after successful login.

    cy.get('#loginForm').submit();
    cy.wait(3500);
+    // Add an assertion here to check the result of the login attempt
+    // For example, if successful login redirects to a dashboard page:
+    // cy.url().should('include', '/dashboard');
  });

Comment on lines +10 to +20
it('brings out an alert box with invalid credentials', () => {
cy.visit('./');
cy.get('input[name=email]').first().type('invalid-name@example.com');
cy.get('input[name=password]').first().type('invalid-password');
cy.get('#loginForm').submit();
cy.on('window:alert', (alertText) => {
expect(alertText).to.equal(
'Login failed, please check your email or password and try again.'
);
});
});

Choose a reason for hiding this comment

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

Image description CodeRabbit

This test case relies on a window:alert event to handle login failures. This is not a recommended practice because it disrupts the user experience and makes automated testing more difficult. Instead, consider displaying error messages within the application UI. If this alert-based approach is necessary for some reason, the test case is fine as it is.

);
});
});
});

Choose a reason for hiding this comment

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

Image description CodeRabbit

There should be a newline at the end of the file. This is a common convention that helps prevent issues with certain tools that might not handle files without a trailing newline correctly.

});
\ No newline at end of file
+ 

Comment on lines +1 to +30
export default class LocalStorageMock {
constructor() {
this.store = {};
}

clear() {
this.store = {};
}

getItem(key) {
return this.store[key] || null;
}

setItem(key, value) {
this.store[key] = String(value);
}

removeItem(key) {
delete this.store[key];
}

get length() {
return Object.keys(this.store).length;
}

key(n) {
const keys = Object.keys(this.store);
return keys[n] || null;
}
}

Choose a reason for hiding this comment

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

Image description CodeRabbit

The implementation of the LocalStorageMock class looks good. It correctly mimics the behavior of the actual localStorage object in a browser environment, which is useful for testing purposes. However, it's important to note that this mock won't persist data across different tests, as each test will instantiate its own version of LocalStorageMock.

+ export default class LocalStorageMock {
+     constructor() {
+       this.store = {};
+     }
+   
+     clear() {
+       this.store = {};
+     }
+   
+     getItem(key) {
+       return this.store[key] || null;
+     }
+   
+     setItem(key, value) {
+       this.store[key] = String(value);
+     }
+   
+     removeItem(key) {
+       delete this.store[key];
+     }
+   
+     get length() {
+       return Object.keys(this.store).length;
+     }
+   
+     key(n) {
+       const keys = Object.keys(this.store);
+       return keys[n] || null;
+     }
+   }

return keys[n] || null;
}
}

Choose a reason for hiding this comment

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

Image description CodeRabbit

It's a good practice to end files with a newline character. This is a POSIX standard and helps with file processing tools that are designed to work with such files.

- \ No newline at end of file
+ 

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 45ca825 and 21cb4b0 commits.
Files selected (7)
  • .husky/pre-commit (1)
  • cypress/e2e/login.cy.js (1)
  • cypress/e2e/logout.cy.js (1)
  • src/js/api/auth/login.test.js (1)
  • src/js/api/auth/logout.test.js (1)
  • src/js/api/posts/create.test.js (1)
  • src/js/storage/localStorage.mock.js (1)
Review comments generated (8)
  • Review: 7
  • 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.

Comment on lines +1 to +5
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
npx lint-staged

Choose a reason for hiding this comment

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

Image description CodeRabbit

There seems to be a redundancy in your pre-commit hook. The npx lint-staged command is repeated twice, which could lead to unnecessary execution and slow down the commit process.

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
-5: npx lint-staged

Comment on lines +19 to +25
describe('login function', () => {
it('fetch and store token in browser storage', async () => {
global.fetch = fetchsuccess;
const data =await login({});
expect(data).toEqual(USER_DATA)
});
});

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 the login function seems to be missing some important assertions. While it does check if the returned data matches USER_DATA, it doesn't verify if the token is stored in localStorage as expected. This is a crucial part of the login process and should be tested.

describe('login function', () => {
    it('fetch and store token in browser storage', async () => {
        global.fetch = fetchsuccess;
        const data = await login({});
        expect(data).toEqual(USER_DATA);
+        expect(global.localStorage.getItem('token')).toEqual(USER_DATA.token);
    });
});

Also, consider adding error handling tests to ensure your function behaves correctly when the API request fails.

Comment on lines +1 to +34
import { createPost } from './create';

const createTestPost = {
title: 'Blog post title',
body: 'Hey There, welcome to my first post',
media: 'https://media.istockphoto.com/id/1271163410',
tags: ['post', 'climate', 'test'],
};

const { title, body, media, tags } = createTestPost;

const postData = {
title: title,
body: body,
media: media,
tags: tags,
};

function fetchSuccess() {
return Promise.resolve({
ok: true,
status: 200,
statusText: 'success',
json: () => Promise.resolve(createTestPost),
});
}

describe('createPost', () => {
it('create a new item on the API', async() => {
global.fetch = jest.fn(() =>fetchSuccess());
const test = await createPost(postData);
expect(test).toEqual(createTestPost);
});
});

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 seems to be well written and covers the functionality of the createPost function. However, there is a redundancy in your code that can be improved. You are destructuring createTestPost into title, body, media, and tags, and then creating postData with those same variables. This is unnecessary as you can directly use createTestPost instead of postData.

- const { title, body, media, tags } = createTestPost;
- 
- const postData = {
-     title: title,
-     body: body,
-     media: media,
-     tags: tags,
- };

+ const postData = createTestPost;

Also, remember to add a newline at the end of the file to adhere to standard coding conventions.

- \ No newline at end of file
+ 

Comment on lines 1 to 13
describe('Logout Button', () => {
it('logs out a user', () => {
cy.visit('./');
cy.get('input[name=email]').first().type('mane@suiteTeardown.noroff.no');
cy.get('input[name=password]').first().type('mane12345');
cy.get('#loginForm').submit();

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

cy.get('#loginForm').should('be.visible');
cy.url().should('equal', 'http://localhost:55499/');
});
});

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 the logout functionality seems fine. However, it's not a good practice to hardcode user credentials in your test cases. Consider using environment variables or a configuration file that is not committed to the repository to store these sensitive data.

-        cy.get('input[name=email]').first().type('mane@suiteTeardown.noroff.no');
-        cy.get('input[name=password]').first().type('mane12345');
+        cy.get('input[name=email]').first().type(Cypress.env('TEST_USER_EMAIL'));
+        cy.get('input[name=password]').first().type(Cypress.env('TEST_USER_PASSWORD'));

Also, please add a newline at the end of the file to follow best practices and avoid potential parsing issues.

});
\ No newline at end of file
+13: });
+ 

Comment on lines +1 to +30
export default class LocalStorageMock {
constructor() {
this.store = {};
}

clear() {
this.store = {};
}

getItem(key) {
return this.store[key] || null;
}

setItem(key, value) {
this.store[key] = String(value);
}

removeItem(key) {
delete this.store[key];
}

get length() {
return Object.keys(this.store).length;
}

key(n) {
const keys = Object.keys(this.store);
return keys[n] || null;
}
}

Choose a reason for hiding this comment

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

Image description CodeRabbit

The implementation of the LocalStorageMock class seems fine. It correctly mimics the behavior of the actual localStorage object in a browser environment, which is useful for testing purposes. However, it's important to note that this mock won't persist data across different test cases or test files, as each instance of LocalStorageMock will have its own store object.

One potential improvement could be to add error handling for edge cases. For example, in the setItem method, you might want to check if the key and value are not undefined or null before setting them in the store. This would more closely mimic the behavior of the real localStorage, which throws an error when trying to set null or undefined as a key or value.

    setItem(key, value) {
+       if (key === null || key === undefined || value === null || value === undefined) {
+           throw new Error('Invalid key or value');
+       }
      this.store[key] = String(value);
    }

return keys[n] || null;
}
}

Choose a reason for hiding this comment

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

Image description CodeRabbit

It's a good practice to end your file with a newline character. This is a POSIX standard and helps with processing the file using Unix/Linux tools. It also avoids unnecessary changes when someone else edits the file and their editor automatically adds a newline at the end.

  
+ \n

Comment on lines +1 to +21
describe('Login Form', () => {
it('can login with valid credentials', () => {
cy.visit('./');
cy.get('input[name=email]').first().type('valid-name@example.com');
cy.get('input[name=password]').first().type('valid-password');
cy.get('#loginForm').submit();
cy.wait(3500);
});

it('brings out an alert box with invalid credentials', () => {
cy.visit('./');
cy.get('input[name=email]').first().type('invalid-name@example.com');
cy.get('input[name=password]').first().type('invalid-password');
cy.get('#loginForm').submit();
cy.on('window:alert', (alertText) => {
expect(alertText).to.equal(
'Login failed, please check your email or password and try again.'
);
});
});
});

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 cases look good, but there are a few improvements that can be made:

  1. Avoid hardcoding wait times (line 7). It's better to use cy.intercept() to stub network requests or wait for specific network calls to complete.

  2. The second test case assumes that an invalid login will trigger a window alert. This is not a common practice in modern web applications and might not be the best way to handle errors. Consider checking for an error message displayed on the page instead.

Here's how you could improve these tests:

describe('Login Form', () => {
  it('can login with valid credentials', () => {
    cy.visit('./');
    cy.get('input[name=email]').first().type('valid-name@example.com');
    cy.get('input[name=password]').first().type('valid-password');
    cy.get('#loginForm').submit();
-    cy.wait(3500);
+    cy.intercept('POST', '/api/login').as('login');
+    cy.wait('@login');
  });

  it('brings out an alert box with invalid credentials', () => {
    cy.visit('./');
    cy.get('input[name=email]').first().type('invalid-name@example.com');
    cy.get('input[name=password]').first().type('invalid-password');
    cy.get('#loginForm').submit();
-    cy.on('window:alert', (alertText) => {
-      expect(alertText).to.equal(
-        'Login failed, please check your email or password and try again.'
-      );
-    });
+    cy.get('.error-message').should('contain', 'Login failed, please check your email or password and try again.');
  });
});

In the above changes, I've replaced cy.wait(3500) with cy.intercept() and cy.wait(), which will wait for the login API call to complete. In the second test case, I've replaced the window alert check with a check for an error message on the page. Please replace '.error-message' with the actual selector of your error message element.

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 21cb4b0 and a87fe0a commits.
Files selected (1)
  • ReadME.md (1)
Review comments generated (1)
  • Review: 1
  • 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.

Comment on lines +1 to +22
# Workflow CA

In this CA we are tasked with applying workflow skills in installing code formatting tools, configuration and code testing.

# GitHub repository

I fork the gitHub repository from the gitHub provided in the CA brief and clone it to my gitHub desktop. Created the workflow branch in which i did all the workflow tasks and committed into the workflow branch.
Open the github repo on vscode and use the vscode terminal to install and configure the different extensions for the workflow CA.

# Installed dependencies
- npm init
- installing Prettier
- Installing eslint
- npm run lint-fix (to fix errors notice by eslint)
- Installing hooks (npx mrm@2 lint-staged)

# Tests installed and configured for the project

- Installed jest (npm i -D jest@29.2.0) for our unit testings
- npm i -D eslint-plugin-jest (this to setup the environment for the jest configuration)
- Installed babel for jest
- Installed cypress ( for end-to-end testings)

Choose a reason for hiding this comment

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

Image description CodeRabbit

The changes to the README file look good overall, but there's a minor issue. It's a best practice to end a file with a newline character. This is a POSIX standard that ensures easier concatenation of files and better compatibility across different tools and systems.

- Installed cypress ( for end-to-end testings)
+22: - Installed cypress ( for end-to-end testings)
+23: 

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 a87fe0a and 35b2a5c commits.
Files selected (1)
  • src/js/apple.js (1)
Files skipped from review due to trivial changes (1)
  • src/js/apple.js
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.

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 35b2a5c and cd0ce21 commits.
Files selected (1)
  • .github/workflows /unit-test.yml (1)
Files skipped from review due to trivial changes (1)
  • .github/workflows /unit-test.yml
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.

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 cd0ce21 and 7d4d74e commits.
Files selected (1)
  • .github/workflows/e2e-test.yml (1)
Files skipped from review due to trivial changes (1)
  • .github/workflows/e2e-test.yml
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.

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 35b2a5c and 5ec440c commits.
Files selected (1)
  • cypress/e2e/logout.cy.js (1)
Files ignored due to filter (1)
  • package.json
Review comments generated (3)
  • Review: 3
  • 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.

Comment on lines +8 to +10
cy.visit("/");
cy.wait(1500);
cy.get(".btn-close:visible").click({ multiple: true });

Choose a reason for hiding this comment

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

Image description CodeRabbit

The use of cy.wait() is generally discouraged in Cypress tests because it introduces unnecessary delays and can lead to flaky tests. Instead, consider using Cypress's built-in retry-ability with commands like cy.get(), cy.contains(), etc., which will automatically wait for elements to appear.

-    cy.wait(1500);
-    cy.get(".btn-close:visible").click({ multiple: true });
-    cy.wait(1500);
+    cy.get(".btn-close:visible", { timeout: 5000 }).click({ multiple: true });

Comment on lines +20 to +21
cy.get(window.localStorage.getItem("token")).should("not.to.be.empty");
cy.get(window.localStorage.getItem("profile")).should("not.to.be.empty");

Choose a reason for hiding this comment

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

Image description CodeRabbit

Directly accessing window.localStorage inside a cy.get() command might not work as expected due to the asynchronous nature of Cypress commands. Use cy.window() to access the window object.

-    cy.get(window.localStorage.getItem("token")).should("not.to.be.empty");
-    cy.get(window.localStorage.getItem("profile")).should("not.to.be.empty");
+    cy.window().its('localStorage.token').should('not.to.be.empty');
+    cy.window().its('localStorage.profile').should('not.to.be.empty');

Comment on lines +23 to +24
cy.then(() => expect(window.localStorage.getItem("token")).to.be.null);
cy.then(() => expect(window.localStorage.getItem("profile")).to.be.null);

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, use cy.window() to access the window object when checking localStorage values.

-    cy.then(() => expect(window.localStorage.getItem("token")).to.be.null);
-    cy.then(() => expect(window.localStorage.getItem("profile")).to.be.null);
+    cy.window().its('localStorage.token').should('be.null');
+    cy.window().its('localStorage.profile').should('be.null');

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