#sprint-1 added orders test
This commit is contained in:
parent
f5a75e3fdf
commit
fae269868a
27
lib/apis/orders.dart
Normal file
27
lib/apis/orders.dart
Normal file
@ -0,0 +1,27 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:server/apis/auth.dart';
|
||||
import 'package:server/client.dart';
|
||||
|
||||
class Orders {
|
||||
String lastError = '';
|
||||
createOrder(productId, count) async {
|
||||
final userId = await auth.setToken();
|
||||
try {
|
||||
final response = await api.post(
|
||||
'/collections/orders/records',
|
||||
data: {'user_id': userId, 'product_id': productId, 'count': count},
|
||||
);
|
||||
if (response.data != null) {
|
||||
return response.data;
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.connectionError) {
|
||||
lastError = 'Internet Connection Error';
|
||||
} else {
|
||||
lastError = e.response!.data['message'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final orders = Orders();
|
@ -63,3 +63,5 @@ class Projects {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final projects = Projects();
|
||||
|
@ -1,6 +1,8 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:server/apis/auth.dart';
|
||||
import 'package:server/apis/cart.dart';
|
||||
import 'package:server/apis/orders.dart';
|
||||
import 'package:server/apis/projects.dart';
|
||||
import 'package:server/apis/shop.dart';
|
||||
import 'package:server/apis/tokens.dart';
|
||||
|
||||
@ -20,6 +22,21 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
test('Создание заказа', () async {
|
||||
final productsList = await shop.getCatalog();
|
||||
final firstProduct = productsList['items'][0];
|
||||
|
||||
try {
|
||||
final response = await orders.createOrder(firstProduct['id'], 10);
|
||||
if (response != null) {
|
||||
expect(response['count'], 10);
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore: avoid_print
|
||||
print(e);
|
||||
}
|
||||
});
|
||||
|
||||
test('Спринт 2. Создание пользователя', () async {
|
||||
try {
|
||||
final response = await auth.register(
|
||||
@ -42,6 +59,7 @@ void main() {
|
||||
print(e);
|
||||
}
|
||||
});
|
||||
|
||||
test('Спринт 2. Получение каталога-3', () async {
|
||||
try {
|
||||
final response = await shop.getCatalog();
|
||||
@ -53,6 +71,7 @@ void main() {
|
||||
return Error();
|
||||
}
|
||||
});
|
||||
|
||||
test('Спринт 2. Добавление в корзину', () async {
|
||||
try {
|
||||
final response = await cart.addToCart('string', 10);
|
||||
@ -62,6 +81,7 @@ void main() {
|
||||
return Error();
|
||||
}
|
||||
});
|
||||
|
||||
test('Спринт 2.Получение информации о профиле', () async {
|
||||
try {
|
||||
final response = await auth.getCurrentUser();
|
||||
@ -73,6 +93,7 @@ void main() {
|
||||
return Error();
|
||||
}
|
||||
});
|
||||
|
||||
test('Спринт 2.Логаут пользователя', () async {
|
||||
try {
|
||||
final currentId = await tokens.getAccessToken();
|
||||
@ -85,4 +106,37 @@ void main() {
|
||||
return Error();
|
||||
}
|
||||
});
|
||||
|
||||
test('Создание проекта', () async {
|
||||
try {
|
||||
final response = await projects.createProject(
|
||||
'1233213',
|
||||
'123312321',
|
||||
'123321123',
|
||||
'123321',
|
||||
'123231',
|
||||
'123312',
|
||||
'123312',
|
||||
);
|
||||
if (response != null) {
|
||||
expect(response['title'], '1233213');
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore: avoid_print
|
||||
print(e);
|
||||
}
|
||||
});
|
||||
test('Список проектов', () async {
|
||||
try {
|
||||
final response = await projects.getProjects();
|
||||
if (response != null) {
|
||||
expect(response['perPage'], 30);
|
||||
} else {
|
||||
expect('1', '2');
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore: avoid_print
|
||||
print(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user