#sprint-1
This commit is contained in:
parent
583ac3643b
commit
577b746b8c
@ -20,13 +20,28 @@ class Auth {
|
||||
}
|
||||
}
|
||||
|
||||
register(String email, String password) async {
|
||||
updateUser(
|
||||
String userId,
|
||||
String firstName,
|
||||
String lastname,
|
||||
String secondName,
|
||||
String datebirthday,
|
||||
String gender,
|
||||
) async {
|
||||
try {
|
||||
final response = await api.post(
|
||||
'/collections/users/records',
|
||||
data: {emailKey: email, passwordKey: password},
|
||||
final response = await api.patch(
|
||||
'/collections/users/record/$userId',
|
||||
data: {
|
||||
'firstname': firstName,
|
||||
'lastname': lastname,
|
||||
'secondname': secondName,
|
||||
'datebirthday': datebirthday,
|
||||
'gender': gender,
|
||||
},
|
||||
);
|
||||
if (response.data != null) {
|
||||
return response.data;
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.connectionError) {
|
||||
lastError = 'Internet Connection Error';
|
||||
@ -35,6 +50,52 @@ class Auth {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
register(
|
||||
String email,
|
||||
String password,
|
||||
String confirmPassword,
|
||||
String firstName,
|
||||
String lastname,
|
||||
String secondName,
|
||||
String datebirthday,
|
||||
String gender,
|
||||
) async {
|
||||
if (password != confirmPassword) {
|
||||
lastError = 'Confirm password != password';
|
||||
} else {
|
||||
try {
|
||||
final response = await api.post(
|
||||
'/collections/users/records',
|
||||
data: {
|
||||
emailKey: email,
|
||||
passwordKey: password,
|
||||
confirmPasswordKey: password,
|
||||
},
|
||||
);
|
||||
if (response.data != null) {
|
||||
final responseData = response.data['id'];
|
||||
final result = await updateUser(
|
||||
responseData,
|
||||
firstName,
|
||||
lastname,
|
||||
secondName,
|
||||
datebirthday,
|
||||
gender,
|
||||
);
|
||||
if (response.data) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.connectionError) {
|
||||
lastError = 'Internet Connection Error';
|
||||
} else {
|
||||
lastError = e.response!.data['message'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final auth = Auth();
|
||||
|
@ -12,6 +12,30 @@ void main() {
|
||||
expect(response['record']['email'], 'example123123@test.ru');
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore: avoid_print
|
||||
print(e);
|
||||
}
|
||||
});
|
||||
|
||||
test('Спринт 2. Создание пользователя', () async {
|
||||
try {
|
||||
final response = await auth.register(
|
||||
'example123123333333@mail.ru',
|
||||
'string213123',
|
||||
'string213123',
|
||||
'testtest',
|
||||
'testtest',
|
||||
'testtest',
|
||||
'testtest',
|
||||
'testtest',
|
||||
);
|
||||
if (response != null) {
|
||||
expect(response['record']['firstname'], 'testtest');
|
||||
} else {
|
||||
expect('1', '2');
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore: avoid_print
|
||||
print(e);
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user