forked from eatvio/eatvio_app
merged
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class DevToolsScreen extends StatelessWidget {
|
||||
const DevToolsScreen({super.key});
|
||||
|
||||
static const name = 'devToolsScreen';
|
||||
static const path = '/dev-tools-screen';
|
||||
|
||||
@@ -34,6 +35,7 @@ class _DevToolsScreenContentState extends State<DevToolsScreenContent> {
|
||||
GetChatRoomIdByUserSlug(),
|
||||
GetBlogPostList(),
|
||||
GetRecipes(),
|
||||
CreateRecipeTask(),
|
||||
GetDiets(),
|
||||
GetPlans(),
|
||||
GetBlogPostComments(),
|
||||
@@ -59,27 +61,18 @@ class _DevToolsScreenContentState extends State<DevToolsScreenContent> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Для разработчиков'),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Text('BaseUrl: ${baseUrlForTest}'),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(padding: const EdgeInsets.all(8.0), child: Row(children: [Text('BaseUrl: ${baseUrlForTest}')])),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: CustomTextFormField(
|
||||
controller: controller,
|
||||
hintText: 'type new base url',
|
||||
),
|
||||
),
|
||||
Expanded(child: CustomTextFormField(controller: controller, hintText: 'type new base url')),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
@@ -91,9 +84,7 @@ class _DevToolsScreenContentState extends State<DevToolsScreenContent> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (baseUrlForTest != baseUrl)
|
||||
CustomOutlinedButton(
|
||||
text: 'Set dev2 base url',
|
||||
@@ -104,78 +95,62 @@ class _DevToolsScreenContentState extends State<DevToolsScreenContent> {
|
||||
},
|
||||
buttonStyle: ButtonStyle(),
|
||||
),
|
||||
SizedBox(
|
||||
height: baseUrlForTest != baseUrl ? 40 : 10,
|
||||
),
|
||||
if (baseUrlForTest != 'https://eatvio.ru')
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: testCases.length,
|
||||
itemBuilder: (context, index) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text('${index + 1}. ${testCases[index].name}'),
|
||||
),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CustomOutlinedButton(
|
||||
text: 'run',
|
||||
height: 20,
|
||||
width: 60,
|
||||
onPressed: () async {
|
||||
if (testsStates[index] == TestState.loading) return;
|
||||
SizedBox(height: baseUrlForTest != baseUrl ? 40 : 10),
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: testCases.length,
|
||||
itemBuilder:
|
||||
(context, index) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(child: Text('${index + 1}. ${testCases[index].name}')),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CustomOutlinedButton(
|
||||
text: 'run',
|
||||
height: 20,
|
||||
width: 60,
|
||||
onPressed: () async {
|
||||
if (testsStates[index] == TestState.loading) return;
|
||||
|
||||
setState(() {
|
||||
testsStates[index] = TestState.loading;
|
||||
});
|
||||
final result = await testCases[index].run(baseUrl: baseUrlForTest);
|
||||
if (result) {
|
||||
setState(() {
|
||||
testsStates[index] = TestState.success;
|
||||
testsStates[index] = TestState.loading;
|
||||
});
|
||||
showSuccessToast('${testCases[index].name} passed');
|
||||
} else {
|
||||
setState(() {
|
||||
testsStates[index] = TestState.fail;
|
||||
});
|
||||
showErrorToast('${testCases[index].name} failed');
|
||||
}
|
||||
},
|
||||
buttonStyle: ButtonStyle(),
|
||||
),
|
||||
SizedBox(width: 5),
|
||||
switch (testsStates[index]) {
|
||||
TestState.success => Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
color: Colors.green,
|
||||
),
|
||||
TestState.fail => Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
color: Colors.red,
|
||||
),
|
||||
TestState.notRun => Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
color: Colors.grey,
|
||||
),
|
||||
TestState.loading => Container(
|
||||
final result = await testCases[index].run(baseUrl: baseUrlForTest);
|
||||
if (result) {
|
||||
setState(() {
|
||||
testsStates[index] = TestState.success;
|
||||
});
|
||||
showSuccessToast('${testCases[index].name} passed');
|
||||
} else {
|
||||
setState(() {
|
||||
testsStates[index] = TestState.fail;
|
||||
});
|
||||
showErrorToast('${testCases[index].name} failed');
|
||||
}
|
||||
},
|
||||
buttonStyle: ButtonStyle(),
|
||||
),
|
||||
SizedBox(width: 5),
|
||||
switch (testsStates[index]) {
|
||||
TestState.success => Container(width: 20, height: 20, color: Colors.green),
|
||||
TestState.fail => Container(width: 20, height: 20, color: Colors.red),
|
||||
TestState.notRun => Container(width: 20, height: 20, color: Colors.grey),
|
||||
TestState.loading => Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: SizedBox(height: 20, width: 20, child: Center(child: CircularProgressIndicator())),
|
||||
),
|
||||
},
|
||||
],
|
||||
),
|
||||
],
|
||||
},
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -5,6 +5,9 @@ import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/utils/date_time_utils.dart';
|
||||
import 'package:eatvio_app/features/chat/services/chat_service.dart';
|
||||
import 'package:eatvio_app/features/create_recipe/models/recipe_model.dart';
|
||||
import 'package:eatvio_app/features/create_recipe/models/step.dart';
|
||||
import 'package:eatvio_app/features/create_recipe/reporitories/recipe_repository.dart';
|
||||
import 'package:eatvio_app/features/diets/services/diet_service.dart';
|
||||
import 'package:eatvio_app/features/feed/services/feed_service.dart';
|
||||
import 'package:eatvio_app/features/profile/services/profile_service.dart';
|
||||
@@ -16,6 +19,33 @@ sealed class TestCases {
|
||||
Future<bool> run({required String baseUrl}) async => throw UnimplementedError();
|
||||
}
|
||||
|
||||
class CreateRecipeTask implements TestCases {
|
||||
@override
|
||||
String get name => 'api/recipes/create';
|
||||
|
||||
@override
|
||||
Future<bool> run({required String baseUrl}) async {
|
||||
try {
|
||||
final dio = sl<Dio>();
|
||||
final recipeRepository = RecipeRepository(recipeService: CreateRecipeService(dio, baseUrl: baseUrl));
|
||||
await recipeRepository.publishRecipe(
|
||||
RecipeModel(
|
||||
title: 'Title',
|
||||
state: 'active',
|
||||
description: 'desc',
|
||||
type: 'first_meals',
|
||||
servings: 10,
|
||||
energyPerServing: 10,
|
||||
steps: [Step(description: 'desc')],
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class Test850task implements TestCases {
|
||||
@override
|
||||
String get name => 'task #850';
|
||||
@@ -50,12 +80,7 @@ class Test850task implements TestCases {
|
||||
await Future.delayed(Duration(seconds: 3));
|
||||
}
|
||||
try {
|
||||
await dietsService.startDiet(
|
||||
id: diet.id,
|
||||
body: {
|
||||
'date': yesterday.format('yyyy-MM-dd'),
|
||||
},
|
||||
);
|
||||
await dietsService.startDiet(id: diet.id, body: {'date': yesterday.format('yyyy-MM-dd')});
|
||||
|
||||
return false;
|
||||
} catch (e) {
|
||||
@@ -64,12 +89,7 @@ class Test850task implements TestCases {
|
||||
|
||||
// test start diet with correct date
|
||||
try {
|
||||
await dietsService.startDiet(
|
||||
id: diet.id,
|
||||
body: {
|
||||
'date': today.format('yyyy-MM-dd'),
|
||||
},
|
||||
);
|
||||
await dietsService.startDiet(id: diet.id, body: {'date': today.format('yyyy-MM-dd')});
|
||||
} catch (e) {
|
||||
log('unexpected error2: $e');
|
||||
return false;
|
||||
@@ -87,12 +107,7 @@ class Test850task implements TestCases {
|
||||
|
||||
// test start diet with correct date
|
||||
try {
|
||||
await dietsService.startDiet(
|
||||
id: diet.id,
|
||||
body: {
|
||||
'date': tomorrow.format('yyyy-MM-dd'),
|
||||
},
|
||||
);
|
||||
await dietsService.startDiet(id: diet.id, body: {'date': tomorrow.format('yyyy-MM-dd')});
|
||||
} catch (e) {
|
||||
log('unexpected error4: $e');
|
||||
return false;
|
||||
@@ -304,9 +319,7 @@ class GetBlogPostComments implements TestCases {
|
||||
final feedService = FeedService(dio, baseUrl: baseUrl);
|
||||
final blogPostsModel = await feedService.getBlogPostList(page: 1, query: null);
|
||||
final blogPosts = blogPostsModel.feedBlogPostList;
|
||||
await feedService.getBlogPostComments(
|
||||
id: blogPosts.first.id.toString(),
|
||||
);
|
||||
await feedService.getBlogPostComments(id: blogPosts.first.id.toString());
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
@@ -325,10 +338,7 @@ class SendBlogPostComment implements TestCases {
|
||||
final feedService = FeedService(dio, baseUrl: baseUrl);
|
||||
final blogPostsModel = await feedService.getBlogPostList(page: 1, query: null);
|
||||
final blogPosts = blogPostsModel.feedBlogPostList;
|
||||
await feedService.sendBlogPostComment(
|
||||
id: blogPosts.first.id.toString(),
|
||||
body: 'auto test message',
|
||||
);
|
||||
await feedService.sendBlogPostComment(id: blogPosts.first.id.toString(), body: 'auto test message');
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
@@ -347,9 +357,7 @@ class GetDietsComments implements TestCases {
|
||||
final feedService = FeedService(dio, baseUrl: baseUrl);
|
||||
final dietsModel = await feedService.getDiets(page: 1, query: null);
|
||||
final diets = dietsModel.data;
|
||||
await feedService.getDietsComments(
|
||||
id: diets.first.id.toString(),
|
||||
);
|
||||
await feedService.getDietsComments(id: diets.first.id.toString());
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
@@ -368,10 +376,7 @@ class SendDietsComment implements TestCases {
|
||||
final feedService = FeedService(dio, baseUrl: baseUrl);
|
||||
final dietsModel = await feedService.getDiets(page: 1, query: null);
|
||||
final diets = dietsModel.data;
|
||||
await feedService.sendDietsComment(
|
||||
id: diets.first.id.toString(),
|
||||
body: 'auto test message',
|
||||
);
|
||||
await feedService.sendDietsComment(id: diets.first.id.toString(), body: 'auto test message');
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
@@ -390,9 +395,7 @@ class GetPlansComments implements TestCases {
|
||||
final feedService = FeedService(dio, baseUrl: baseUrl);
|
||||
final plansModel = await feedService.getPlans(page: 1, query: null);
|
||||
final plans = plansModel.data;
|
||||
await feedService.getPlansComments(
|
||||
slug: plans.first.slug,
|
||||
);
|
||||
await feedService.getPlansComments(slug: plans.first.slug);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
@@ -411,10 +414,7 @@ class SendPlansComment implements TestCases {
|
||||
final feedService = FeedService(dio, baseUrl: baseUrl);
|
||||
final plansModel = await feedService.getPlans(page: 1, query: null);
|
||||
final plans = plansModel.data;
|
||||
await feedService.sendPlansComment(
|
||||
slug: plans.first.slug,
|
||||
body: 'auto test message',
|
||||
);
|
||||
await feedService.sendPlansComment(slug: plans.first.slug, body: 'auto test message');
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
@@ -437,9 +437,7 @@ class GetRecipesComments implements TestCases {
|
||||
final tagsIds = tags.map((e) => e.id).toList();
|
||||
final recipesModel = await feedService.getRecipes(page: 1, tags: tagsIds, query: null);
|
||||
final recipes = recipesModel.recipesList;
|
||||
await feedService.getRecipesComments(
|
||||
id: recipes.first.id.toString(),
|
||||
);
|
||||
await feedService.getRecipesComments(id: recipes.first.id.toString());
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user