-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3a62e8
commit d9f76bd
Showing
4 changed files
with
100 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { GET } from '../src/app/api/health/route'; | ||
|
||
describe('Health Check API', () => { | ||
it('should return a 200 status with a message', async () => { | ||
process.env.TEST_ERROR = 'false'; | ||
const response = await GET(); | ||
expect(response.status).toBe(200); | ||
expect(await response.json()).toEqual({ message: "'It works!'" }); | ||
}); | ||
|
||
it('should handle errors gracefully', async () => { | ||
process.env.TEST_ERROR = 'true'; | ||
const response = await GET(); | ||
expect(response.status).toBe(500); | ||
expect(await response.json()).toEqual({ | ||
message: 'An error occurred while health check.', | ||
}); | ||
process.env.TEST_ERROR = 'false'; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use client'; | ||
import axios from 'axios'; | ||
import { useState } from 'react'; | ||
import type { NextPage } from 'next'; | ||
|
||
const CreateUser: NextPage = () => { | ||
const [email, setEmail] = useState(''); | ||
const [name, setName] = useState(''); | ||
|
||
const handleSubmit = async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
try { | ||
const response = await axios.post('/api/users', { | ||
email, | ||
name, | ||
}); | ||
console.log(response.data); | ||
alert('User created!'); | ||
setEmail(''); | ||
setName(''); | ||
} catch (error) { | ||
console.error(error); | ||
alert('Failed to create user'); | ||
} | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<div> | ||
<label htmlFor="email">Email:</label> | ||
<input | ||
type="email" | ||
id="email" | ||
value={email} | ||
onChange={e => setEmail(e.target.value)} | ||
/> | ||
</div> | ||
<div> | ||
<label htmlFor="name">Name:</label> | ||
<input | ||
type="text" | ||
id="name" | ||
value={name} | ||
onChange={e => setName(e.target.value)} | ||
/> | ||
</div> | ||
<button type="submit">Submit</button> | ||
</form> | ||
); | ||
}; | ||
|
||
export default CreateUser; |