Skip to content

Commit 6c92bc3

Browse files
oxlint
1 parent 59e8038 commit 6c92bc3

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

components/Recaptcha.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@
5353
const launch = ref(false)
5454
const emailRules = [
5555
(value) => {
56-
if (value) return true
57-
56+
if (value) {
57+
return true
58+
}
5859
return "E-mail is required."
5960
},
6061
(value) => {
61-
if (/.+@.+\..+/.test(value)) return true
62-
62+
if (/.+@.+\..+/.test(value)) {
63+
return true
64+
}
6365
return "E-mail must be valid."
6466
},
6567
]
@@ -74,14 +76,14 @@
7476
}
7577
}
7678
})
77-
async function submit_recaptcha() {
79+
function submit_recaptcha() {
7880
$fetch(
7981
`/.netlify/functions/recaptcha?name=${name.value}&email=${email.value}&launch=${launch.value}`,
8082
{
8183
onResponse({ response }) {
8284
if (response.ok) {
8385
infra_store.$patch({
84-
is_captcha_validated: response.status == 200,
86+
is_captcha_validated: response.status === 200,
8587
})
8688
}
8789
},

tests/unit/utils/recaptcha.nuxt.test.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,33 @@ describe("recaptcha.js", () => {
66
const name = ""
77
const email = ""
88
const launch = false
9+
const internal_error = 500
10+
const success = 200
11+
912
describe("Wrong params", () => {
10-
test("name", async () => {
13+
test("name", () => {
1114
const name = "test"
1215
const result = check_recaptcha_params(name, email, launch)
13-
expect(result.status).toBe(500)
16+
expect(result.status).toBe(internal_error)
1417
})
15-
test("email", async () => {
18+
19+
test("email", () => {
1620
const email = "test"
1721
const result = check_recaptcha_params(name, email, launch)
18-
expect(result.status).toBe(500)
22+
expect(result.status).toBe(internal_error)
1923
})
20-
test("launch", async () => {
24+
25+
test("launch", () => {
2126
const launch = true
2227
const result = check_recaptcha_params(name, email, launch)
23-
expect(result.status).toBe(500)
28+
expect(result.status).toBe(internal_error)
2429
})
2530
})
2631

2732
describe("Right params", () => {
28-
test("name", async () => {
33+
test("name", () => {
2934
const result = check_recaptcha_params(name, email, launch)
30-
expect(result.status).toBe(200)
35+
expect(result.status).toBe(success)
3136
})
3237
})
3338
})

utils/recaptcha.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
function check_recaptcha_params(name, email, launch) {
2-
if (name !== "") return { status: 500 }
3-
if (email !== "") return { status: 500 }
4-
if (launch !== false) return { status: 500 }
2+
if (name !== "") {
3+
return { status: 500 }
4+
}
5+
if (email !== "") {
6+
return { status: 500 }
7+
}
8+
if (launch !== false) {
9+
return { status: 500 }
10+
}
511
return { status: 200 }
612
}
713

0 commit comments

Comments
 (0)