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

Handling Leap Year Issue and more #126

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"devDependencies": {
"@shelf/jest-mongodb": "^4.1.7",
"@shelf/jest-mongodb": "^4.2.0",
"@types/bcryptjs": "^2.4.2",
"@types/jest": "^29.5.3",
"@types/jsonwebtoken": "^8.5.0",
Expand Down Expand Up @@ -34,62 +34,64 @@
"watch:test": "jest --watch --noStackTrace"
},
"dependencies": {
"@babel/core": "^7.22.9",
"@babel/preset-env": "^7.22.9",
"@babel/preset-typescript": "^7.12.7",
"@babel/core": "^7.23.7",
"@babel/preset-env": "^7.23.7",
"@babel/preset-typescript": "^7.23.3",
"@netlify/functions": "^1.0.0",
"@sendgrid/mail": "^7.7.0",
"@tsconfig/svelte": "^5.0.0",
"@types/aws-lambda": "^8.10.95",
"@types/node": "^17.0.25",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"@xstate/cli": "^0.5.1",
"@xstate/cli": "^0.5.15",
"@xstate/svelte": "^2.1.0",
"@xstate/test": "^1.0.0-alpha.1",
"babel-jest": "^29.6.1",
"babel-jest": "^29.7.0",
"bcryptjs": "^2.4.3",
"carbon-icons-svelte": "^12.0.0",
"carbon-icons-svelte": "^12.4.2",
"concurrently": "^7.1.0",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.8.1",
"dotenv": "^16.0.0",
"eslint": "^8.45.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte": "^2.32.4",
"eslint-plugin-svelte": "^2.35.1",
"eslint-watch": "^8.0.0",
"http-server": "^14.1.0",
"jest": "29.6.1",
"jest-environment-jsdom": "^29.6.1",
"jest": "29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-environment-node": "^29.7.0",
"jsonwebtoken": "^9.0.1",
"merge": "^2.1.1",
"mini-css-extract-plugin": "^2.7.6",
"mongodb": "^5.8.0",
"mongodb-client-encryption": "^2.3.0",
"mongodb-memory-server": "^8.5.1",
"normalize-url": "^8.0.0",
"picomatch": "^2.3.1",
"prando": "^6.0.1",
"prettier": "2.6.2",
"prettier-plugin-svelte": "^2.10.1",
"rimraf": "^3.0.2",
"sass": "^1.63.6",
"saslprep": "^1.0.3",
"sass": "^1.69.6",
"sass-loader": "^13.3.2",
"style-loader": "^3.3.3",
"svelte": "^3.0.0",
"svelte-loader": "^3.1.9",
"svelte-preprocess": "^5.0.4",
"svelte-preprocess": "5.1.3",
"ts-jest": "^29.1.1",
"ts-loader": "^9.3.0",
"ts-loader": "^9.5.1",
"ts-node": "^10.1.0",
"typescript": "^5.3.2",
"webpack": "^5.76.0",
"webpack-bundle-analyzer": "^4.9.0",
"webpack": "^5.89.0",
"webpack-bundle-analyzer": "^4.10.1",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.15.1",
"webpack-license-plugin": "^4.2.2",
"webpack-license-plugin": "^4.4.2",
"xstate": "^4.38.1",
"yarn": "^1.22.18"
"yarn": "^1.22.21"
},
"resolutions": {
"@cypress/request": "^3.0.0",
Expand Down
7 changes: 6 additions & 1 deletion src/lib/crypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ export const comparePassword = async (
export const getAuthToken = (
user: string,
exp: number = getExpirationTime(YEAR_SECONDS)
): string => jwt.sign({ user, exp }, process.env.JWT_SECRET)
): string => {
if (!process.env.JWT_SECRET) {
throw new Error("JWT_SECRET is not defined")
}
return jwt.sign({ user, exp }, process.env.JWT_SECRET)
}
26 changes: 15 additions & 11 deletions src/simple-comment-icebreakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ declare global {
const storageKey = "icebreakerQuestions"
const timeStampKey = "icebreakerQuestionsTimeStamp"

const toSlug = (str: string): string =>
str
.toLowerCase()
.replace(/ /g, "-")
.replace(/[^\w-]+/g, "")
.replace(/_/g, "")
.replace(/-{2,}/g, "-")
.replace(/-$/, "")
.replace(/^-/, "")
const toSlug = (str: string): string => {
return str
.toLowerCase() // Convert to lower case
.trim() // Remove leading and trailing spaces
.replace(/_/g, "-") // Replace underscores with dashes
.replace(/\s+/g, "-") // Replace all spaces with dashes
.replace(/[^a-z0-9-]/g, "") // Remove characters that are not lowercase letters, numbers, or dashes
.replace(/-+/g, "-") // Merge consecutive dashes into a single dash
}
Comment on lines +9 to +17
Copy link
Owner

Choose a reason for hiding this comment

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

👍🏻

Copy link
Owner

Choose a reason for hiding this comment

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

I like the simplification and comments here. House style is to avoid a return statement when there are no local variables nor otherwise any need for a command block (curly brackets).


const isSlugMatch = (slug: string, question: string) =>
slug === toSlug(question)
Expand All @@ -24,7 +24,7 @@ const reverseSlug = (slug: string, questions: string[]) =>

const fetchAndStoreQuestions = () =>
new Promise<string[]>((resolve, reject) => {
const currentTimestamp =
const currentTimestamp: string =
document?.getElementById("questions-time-stamp")?.innerText || "0"
const storedTimestamp = localStorage.getItem(timeStampKey)

Expand All @@ -40,7 +40,11 @@ const fetchAndStoreQuestions = () =>
fetchQuestions(currentTimestamp, resolve, reject)
})

const fetchQuestions = async (currentTimestamp, resolve, reject) => {
const fetchQuestions = async (
currentTimestamp: string,
resolve: (questions: string[]) => void,
reject: (reason?: unknown) => void
) => {
try {
const questionFile = await fetch(
"https://raw.githubusercontent.com/rendall/icebreakers/master/QUESTIONS.md"
Expand Down
9 changes: 6 additions & 3 deletions src/tests/backend/crypt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ describe("Test crypt", () => {
it("Test auth token", async () => {
const name = "Rendall"
const token = getAuthToken(name)


// Use a defined JWT_SECRET or a default for testing
const jwtSecret = process.env.JWT_SECRET || "default_test_secret"
Copy link
Owner

Choose a reason for hiding this comment

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

This is a good idea!


const claim: TokenClaim = (await jwt.verify(
token,
process.env.JWT_SECRET
jwtSecret
)) as {
user: UserId
exp: number
Expand All @@ -29,4 +32,4 @@ describe("Test crypt", () => {

expect(expirationDate.getFullYear()).toBe(nowDate.getFullYear() + 1)
})
})
})
33 changes: 20 additions & 13 deletions src/tests/frontend/frontend-utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,35 +150,35 @@ describe("debounce", () => {
})

describe("longFormatDate", () => {
const localesArr = [
["af-ZA", "23 Julie 2023 13:31"],
const localesArr = [ // ISO 8601
["af-ZA", "23 Julie 2023 om 13:31"],
["ar-SA", "٥ محرم ١٤٤٥ هـ في ١:٣١ م"],
["de-DE", "23. Juli 2023 um 13:31"],
["el-GR", "23 Ιουλίου 2023 - 1:31 μ.μ."],
["el-GR", "23 Ιουλίου 2023 στις 1:31 μ.μ."],
["en-AU", "23 July 2023 at 1:31 pm"],
["en-GB", "23 July 2023 at 13:31"],
["en-IN", "23 July 2023 at 1:31 pm"],
["en-US", "July 23, 2023 at 1:31 PM"],
["es-ES", "23 de julio de 2023, 13:31"],
["es-MX", "23 de julio de 2023, 13:31"],
["es-MX", "23 de julio de 2023, 1:31 p.m."],
["fi-FI", "23. heinäkuuta 2023 klo 13.31"],
["fr-CA", "23 juillet 2023 à 13 h 31"],
["fr-FR", "23 juillet 2023 à 13:31"],
["he-IL", "23 ביולי 2023 בשעה 13:31"],
["hi-IN", "23 जुलाई 2023 को 1:31 pm"],
["id-ID", "23 Juli 2023 13.31"],
["it-IT", "23 luglio 2023 13:31"],
["hi-IN", "23 जुलाई 2023 को 1:31 pm बजे"],
["id-ID", "23 Juli 2023 pukul 13.31"],
["it-IT", "23 luglio 2023 alle ore 13:31"],
Comment on lines -168 to +170
Copy link
Owner

Choose a reason for hiding this comment

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

Confused about these. These tests pass on my box and in the Github actions. Are they not passing for you?

["ja-JP", "2023年7月23日 13:31"],
["ko-KR", "2023년 7월 23일 오후 1:31"],
["nl-NL", "23 juli 2023 om 13:31"],
["pl-PL", "23 lipca 2023 13:31"],
["pt-BR", "23 de julho de 2023 13:31"],
["pt-BR", "23 de julho de 2023 às 13:31"],
["pt-PT", "23 de julho de 2023 às 13:31"],
["ru-RU", "23 июля 2023 г., 13:31"],
["sv-SE", "23 juli 2023 13:31"],
["th-TH", "23 กรกฎาคม 2566 13:31"],
["ru-RU", "23 июля 2023 г. в 13:31"],
["sv-SE", "23 juli 2023 kl. 13:31"],
["th-TH", "23 กรกฎาคม 2566 เวลา 13:31"],
["tr-TR", "23 Temmuz 2023 13:31"],
["vi-VN", "13:31 23 tháng 7, 2023"],
["vi-VN", "lúc 13:31 23 tháng 7, 2023"],
["zh-CN", "2023年7月23日 13:31"],
["zh-TW", "2023年7月23日 下午1:31"],
]
Expand Down Expand Up @@ -211,4 +211,11 @@ describe("longFormatDate", () => {
const result = longFormatDate(date)
expect(result).toBe("Invalid Date")
})
})

it("should handle incorrect string date format", () => {
const date = "2023-07-32" // Invalidly formatted date
const result = longFormatDate(date)
expect(result).toBe("Invalid Date")
})

})
Loading
Loading