Skip to content

Commit 65de3d5

Browse files
committed
Connect APIs and mocks for registration and login *need to repaire architecture
1 parent 483afa1 commit 65de3d5

File tree

7 files changed

+28
-11
lines changed

7 files changed

+28
-11
lines changed

src/shared/mocks/browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { setupWorker } from 'msw/browser';
2-
import { handlers } from './handlers';
2+
import { handlers } from './';
33

44

55
export const worker = setupWorker(...handlers);

src/shared/mocks/handlers/index.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/shared/mocks/handlers/auth.js renamed to src/shared/mocks/handlers/login.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {http, HttpResponse} from 'msw'
2-
import { API_URL } from '../../config/api';
2+
import { API_URL } from '../../config/api'
33

4-
export const authHandlers = [
4+
export const loginHandlers = [
55
http.post(`${API_URL}/login`, async ({ request }) => {
66
const { email, password } = await request.json();
7-
if (email === 'admin' && password === 'admin'){
7+
if (email === 'Admin' && password === 'AdminAdmin!'){
88
return HttpResponse.json({message: 'Authorisation success!'}, {status: 200});
99
}
1010
return HttpResponse.json({message: 'Invalid email or password'}, {status: 401});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {http, HttpResponse} from 'msw'
2+
import { API_URL } from '../../config/api'
3+
4+
5+
export const registrationHandlers = [
6+
http.post(`${API_URL}/registration`, async ({ request }) => {
7+
const {email, password, name} = request.json();
8+
if(email !== "" && password !== "" && name !== ""){
9+
return HttpResponse.json({message: "Registration successful!"}, {status: 200});
10+
}
11+
return HttpResponse.json({message: "Missing fields"}, {status: 400})
12+
}),
13+
]

src/shared/mocks/handlers/task.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const taskHandlers = [
99
{id: '3', title: 'Слетать на Марс', priority: 'high'},
1010
])
1111
}),
12+
1213
]

src/shared/mocks/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
import { handlers } from "./handlers";
1+
import { taskHandlers } from "./handlers/task";
2+
import { loginHandlers } from "./handlers/login";
3+
import { registrationHandlers } from "./handlers/registration";
24

3-
export {handlers};
5+
const handlers = [...taskHandlers,
6+
...loginHandlers,
7+
...registrationHandlers,
8+
]
9+
10+
export {handlers}

src/widgets/RegistrationForm/RegistrationForm.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const RegistrationForm = (props) => {
5353

5454

5555
const registration = () => {
56-
// registrationApi.registration(formData)
56+
APIs.registration(formData)
5757
}
5858

5959
const login = () => {

0 commit comments

Comments
 (0)