Skip to content

Commit a595097

Browse files
committed
Fixed type errors in test.
1 parent b975d2a commit a595097

File tree

3 files changed

+41
-42
lines changed

3 files changed

+41
-42
lines changed

src/routes/(v2)/v2/debounce-username/+page.server.ts

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { zod } from '$lib/adapters/zod.js';
33
import { fail } from '@sveltejs/kit';
44
import { schema } from './schema.js';
55
import type { Actions } from './$types.js';
6+
import { takenUsernames } from './usernames.js';
67

78
const usernameSchema = schema.pick({ username: true });
89

@@ -29,43 +30,14 @@ export const actions: Actions = {
2930
console.log(formData);
3031

3132
const form = await superValidate(formData, zod(usernameSchema));
32-
if (!form.valid) return { form };
33+
console.log(form);
3334

34-
console.log('🚀 ~ check: ~ form:', form);
35+
if (!form.valid) return { form };
3536

36-
if (natoAlphabetNames.includes(form.data.username)) {
37+
if (takenUsernames.includes(form.data.username)) {
3738
return setError(form, 'username', 'Username is already taken.');
3839
}
3940

4041
return { form };
4142
}
4243
};
43-
44-
const natoAlphabetNames = [
45-
'Alpha',
46-
'Bravo',
47-
'Charlie',
48-
'Delta',
49-
'Echo',
50-
'Foxtrot',
51-
'Golf',
52-
'Hotel',
53-
'India',
54-
'Juliet',
55-
'Kilo',
56-
'Lima',
57-
'Mike',
58-
'November',
59-
'Oscar',
60-
'Papa',
61-
'Quebec',
62-
'Romeo',
63-
'Sierra',
64-
'Tango',
65-
'Uniform',
66-
'Victor',
67-
'Whiskey',
68-
'Xray',
69-
'Yankee',
70-
'Zulu'
71-
].map((n) => n.toLowerCase());
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { json } from '@sveltejs/kit';
2-
import { schema } from '../../schema';
3-
import { RequestHandler } from './$types';
4-
import { actionResult, setError, superValidate } from 'sveltekit-superforms';
5-
import { zod } from 'sveltekit-superforms/adapters';
1+
import { schema } from '../../schema.js';
2+
import type { RequestHandler } from './$types.js';
3+
import { actionResult, setError, superValidate } from '$lib/index.js';
4+
import { zod } from '$lib/adapters/zod.js';
5+
import { takenUsernames } from '../../usernames.js';
66

77
const usernameSchema = schema.pick({ username: true });
88

@@ -11,13 +11,12 @@ export const POST: RequestHandler = async ({ params }) => {
1111
await new Promise((res) => setTimeout(res, Math.random() * 500));
1212

1313
const form = await superValidate({ username: params.username }, zod(usernameSchema));
14-
if (!form.valid) return actionResult('failure', { form })
14+
if (!form.valid) return actionResult('failure', { form });
1515

16-
if (natoAlphabetNames.includes(form.data.username)) {
16+
if (takenUsernames.includes(form.data.username)) {
1717
setError(form, 'username', 'Username is already taken.');
18-
return actionResult('failure', { form })
18+
return actionResult('failure', { form });
1919
}
2020

21-
return
21+
return actionResult('success', { form });
2222
};
23-
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export const takenUsernames = [
2+
'Alpha',
3+
'Bravo',
4+
'Charlie',
5+
'Delta',
6+
'Echo',
7+
'Foxtrot',
8+
'Golf',
9+
'Hotel',
10+
'India',
11+
'Juliet',
12+
'Kilo',
13+
'Lima',
14+
'Mike',
15+
'November',
16+
'Oscar',
17+
'Papa',
18+
'Quebec',
19+
'Romeo',
20+
'Sierra',
21+
'Tango',
22+
'Uniform',
23+
'Victor',
24+
'Whiskey',
25+
'Xray',
26+
'Yankee',
27+
'Zulu'
28+
].map((n) => n.toLowerCase());

0 commit comments

Comments
 (0)