-
Notifications
You must be signed in to change notification settings - Fork 521
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
base: master
Are you sure you want to change the base?
Workflow #389
Conversation
WalkthroughThis 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 Changes
Uplevel your code reviews with CodeRabbit ProCodeRabbit ProIf 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.
src/js/api/auth/login.js
Outdated
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.
|
||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.
import { defineConfig } from "cypress"; | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
// implement node event listeners here | ||
}, | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
+ },
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.
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); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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');
});
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.' | ||
); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged | ||
npx lint-staged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe('login function', () => { | ||
it('fetch and store token in browser storage', async () => { | ||
global.fetch = fetchsuccess; | ||
const data =await login({}); | ||
expect(data).toEqual(USER_DATA) | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
+
cypress/e2e/logout.cy.js
Outdated
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/'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: });
+
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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.' | ||
); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test cases look good, but there are a few improvements that can be made:
-
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. -
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files selected (1)
- ReadME.md (1)
Review comments generated (1)
- Review: 1
- LGTM: 0
Tips
Chat with 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.
# 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.
cy.visit("/"); | ||
cy.wait(1500); | ||
cy.get(".btn-close:visible").click({ multiple: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 });
cy.get(window.localStorage.getItem("token")).should("not.to.be.empty"); | ||
cy.get(window.localStorage.getItem("profile")).should("not.to.be.empty"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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');
cy.then(() => expect(window.localStorage.getItem("token")).to.be.null); | ||
cy.then(() => expect(window.localStorage.getItem("profile")).to.be.null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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');
Summary by CodeRabbit
Release Notes:
apple.js
with properties such as color, texture, animalProduct, and rating..gitignore
for better file structure management.