-
Notifications
You must be signed in to change notification settings - Fork 29
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
Adding custom assertions and example test #17
Conversation
WalkthroughYo, listen up fam! Here's the lowdown on the changes you've made: In this set of changes, you've added some custom assertions and example tests to your codebase. These changes enhance the test coverage and ensure the expected behavior of the code. You've also made modifications to imports, updated assertions, and introduced new custom assertions. Some functions have been replaced with custom assertions for better code readability and maintainability. Overall, these changes bring more 🔥 to your testing game! Changes
Poem
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 (15)
- .eslintrc.cjs (1)
- lib/fixtures/fixtures.ts (1)
- lib/fixtures/toBeOneOfValues.ts (1)
- lib/fixtures/toBeValidDate.ts (1)
- lib/fixtures/typesExpects.ts (1)
- lib/helpers/date.ts (1)
- tests/auth/login.post.spec.ts (2)
- tests/auth/validate.post.spec.ts (2)
- tests/booking/booking.get.spec.ts (5)
- tests/booking/booking.put.spec.ts (3)
- tests/message/message.get.spec.ts (2)
- tests/report/report.get.spec.ts (3)
- tests/room/room.get.spec.ts (2)
- tests/room/room.post.spec.ts (2)
- tests/test.spec.ts (1)
Files ignored due to filter (3)
- package-lock.json
- package.json
- tsconfig.json
Files skipped from review due to trivial changes (5)
- lib/fixtures/typesExpects.ts
- tests/auth/login.post.spec.ts
- tests/booking/booking.get.spec.ts
- tests/room/room.get.spec.ts
- tests/test.spec.ts
Review comments generated (13)
- Review: 8
- LGTM: 5
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.
* Function takes a date as a string and validates that it can be parsed by Date.parse() | ||
* It returns a true or false, great for asserting of the data is properly formatted. | ||
*/ | ||
export function isValidDate(date: string) { | ||
function isValidDate(date: string) { | ||
if (Date.parse(date)) { | ||
return true; | ||
} else { |
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, but no patch was found that overlapped with it. Original lines [22-22]
Bruh, in the lib/helpers/date.ts
file, there's a change that needs your attention. The isValidDate
function was previously exported, but now it's not. This change may impact the external interface of the code. You might want to review this thoroughly and make sure it aligns with your intentions. 🤔
import { mergeExpects } from "@playwright/test"; | ||
import { expect as toBeOneOfValuesExpect } from "@fixtures/toBeOneOfValues"; | ||
import { expect as toBeValidDate } from "@fixtures/toBeValidDate"; | ||
import { expect as typesExpects } from "@fixtures/typesExpects"; | ||
|
||
export { test } from "@playwright/test"; | ||
|
||
export const expect = mergeExpects(toBeOneOfValuesExpect, toBeValidDate, typesExpects); |
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, but no patch was found that overlapped with it. Original lines [22-25]
Bruh, what's going on here? It seems like you added some imports and exports in the lib/fixtures/fixtures.ts
file. But hold up, there's no old code to compare it with. Did you forget to include the original code snippet? Please provide the old hunk so I can review the changes properly. Otherwise, I won't be able to give you any feedback. 😅
Also, just a heads up, make sure you're using consistent naming conventions for your imports and exports. It helps keep things organized and easier to understand. Keep that code clean, fam! 💪🧹
plugins: ["@typescript-eslint"], | ||
root: true, | ||
rules: { | ||
"@typescript-eslint/no-explicit-any": 0, | ||
"no-console": 0, | ||
"no-restricted-syntax": [ | ||
"error", |
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, but no patch was found that overlapped with it. Original lines [22-22]
In this line, you disabled the rule @typescript-eslint/no-explicit-any
by setting its value to 0. This change allows the usage of the "any" type in TypeScript without triggering an error. But hold up, bruh! Disabling this rule can be risky because it removes a valuable type-checking mechanism. Make sure you really need to use the "any" type before disabling this rule. 💡
import { test, expect } from "@fixtures/fixtures"; | ||
import { createToken } from "@datafactory/auth"; |
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.
|
||
expect(body.timestamp).toBeValidDate(); |
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.
Yo, fam! I see you made some changes to the assertions here. Instead of using isValidDate(body.timestamp)
, you're now using body.timestamp.toBeValidDate()
. While it looks fancy, make sure this custom assertion is implemented correctly and actually checks if the received value is a valid date string. Don't want any bogus assertions messing things up, ya know? 👀
That's all for this file, fam! Keep up the good work and review those changes like a boss! 💪🔍
import { expect as baseExpect } from "@playwright/test"; | ||
|
||
export { test } from "@playwright/test"; | ||
|
||
export const expect = baseExpect.extend({ | ||
toBeOneOfValues(received: any, array: any[]) { | ||
const pass = array.includes(received); | ||
if (pass) { | ||
return { | ||
message: () => "passed", | ||
pass: true, | ||
}; | ||
} else { | ||
return { | ||
message: () => `toBeOneOfValues() assertion failed.\nYou expected [${array}] to include '${received}'\n`, | ||
pass: false, | ||
}; | ||
} | ||
}, | ||
}); |
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, but no patch was found that overlapped with it. Original lines [22-22]
Bruh, I see you're adding a custom assertion called toBeOneOfValues
in the lib/fixtures/toBeOneOfValues.ts
file. That's lit! 👌
But fam, I gotta point out a small issue here. In line 1, you imported the expect
function as baseExpect
from the @playwright/test
package. But then in line 5, when you extend it to create your custom expect
object, you're using baseExpect
instead of just expect
. It's like you're playing ping pong with the names, bruh. 😅
To fix this, simply change line 5 to:
export const expect = expect.extend({
That way, you'll be consistent with the naming and avoid any confusion. Keep up the good work, fam! 💪🔥
import { expect as baseExpect } from "@playwright/test"; | ||
|
||
export { test } from "@playwright/test"; | ||
|
||
export const expect = baseExpect.extend({ | ||
toBeValidDate(received: any) { | ||
const pass = Date.parse(received) && typeof received === "string" ? true : false; | ||
if (pass) { | ||
return { | ||
message: () => "passed", | ||
pass: true, | ||
}; | ||
} else { | ||
return { | ||
message: () => `toBeValidDate() assertion failed.\nYou expected '${received}' to be a valid date.\n`, | ||
pass: false, | ||
}; | ||
} | ||
}, | ||
}); |
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.
const pass = Date.parse(received) && typeof received === "string" ? true : false; | ||
if (pass) { |
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.
To check if the received value is a valid date, you're using Date.parse(received)
and checking if the type of received
is "string"
. While this approach may work in some cases, it's not foolproof. For example, Date.parse("2023-10-15")
would return a valid date, but Date.parse("2023-13-15")
would also return a valid date even though December only has 31 days. It's better to use a library like moment.js
or date-fns
for more robust date parsing and validation.
15:
In the failure message of the toBeValidDate
assertion, you're using template literals to construct the message. That's cool and all, but you forgot to include the received value in the message. It would be helpful to show the actual value that failed the assertion. Here's a fix for that:
- message: () => `toBeValidDate() assertion failed.\nYou expected '${received}' to be a valid date.\n`,
+ message: () => `toBeValidDate() assertion failed.\nYou expected '${received}' to be a valid date, but it is not.\n`,
Overall, your changes look pretty solid, fam! Just make sure to address the issues I pointed out and consider using a more robust date parsing/validation library. Keep up the good work! 💪🔥
Summary by CodeRabbit
Alright, fam! Let's break down these changes like a boss and craft some lit release notes for this pull request. Here's the deal:
toBeOneOfValues
andtoBeValidDate
to enhance test coverage and ensure expected behavior. 🚀Remember, folks, code quality is no joke, but here's a punny one for you anyway: "Why did the developer go broke? Because he lost his domain in a bet!" 😄🎉