mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-16 12:15:31 +00:00
Format code
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
|
||||
import "package:flutter/services.dart";
|
||||
import "package:flutter_test/flutter_test.dart";
|
||||
import "package:inventree/api.dart";
|
||||
@ -16,7 +15,8 @@ void setupTestEnv() {
|
||||
CustomBinding();
|
||||
|
||||
// Mock the path provider
|
||||
const MethodChannel channel = MethodChannel("plugins.flutter.io/path_provider");
|
||||
const MethodChannel channel =
|
||||
MethodChannel("plugins.flutter.io/path_provider");
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
|
||||
return ".";
|
||||
@ -29,41 +29,36 @@ const String testServerName = "Test Server";
|
||||
const String testUsername = "testuser";
|
||||
const String testPassword = "testpassword";
|
||||
|
||||
|
||||
/*
|
||||
* Request an API token for the given profile
|
||||
*/
|
||||
Future<bool> fetchProfileToken({
|
||||
UserProfile? profile,
|
||||
String username = testUsername,
|
||||
String password = testPassword
|
||||
}) async {
|
||||
|
||||
Future<bool> fetchProfileToken(
|
||||
{UserProfile? profile,
|
||||
String username = testUsername,
|
||||
String password = testPassword}) async {
|
||||
profile ??= await UserProfileDBManager().getProfileByName(testServerName);
|
||||
|
||||
assert(profile != null);
|
||||
|
||||
final response = await InvenTreeAPI().fetchToken(profile!, username, password);
|
||||
final response =
|
||||
await InvenTreeAPI().fetchToken(profile!, username, password);
|
||||
return response.successful();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Setup a valid profile, and return it
|
||||
*/
|
||||
Future<UserProfile> setupServerProfile({bool select = true, bool fetchToken = false}) async {
|
||||
Future<UserProfile> setupServerProfile(
|
||||
{bool select = true, bool fetchToken = false}) async {
|
||||
// Setup a valid server profile
|
||||
|
||||
UserProfile? profile = await UserProfileDBManager().getProfileByName(testServerName);
|
||||
UserProfile? profile =
|
||||
await UserProfileDBManager().getProfileByName(testServerName);
|
||||
|
||||
if (profile == null) {
|
||||
// Profile does not already exist - create it!
|
||||
bool result = await UserProfileDBManager().addProfile(
|
||||
UserProfile(
|
||||
server: testServerAddress,
|
||||
name: testServerName
|
||||
)
|
||||
);
|
||||
UserProfile(server: testServerAddress, name: testServerName));
|
||||
|
||||
assert(result);
|
||||
}
|
||||
@ -84,15 +79,13 @@ Future<UserProfile> setupServerProfile({bool select = true, bool fetchToken = fa
|
||||
return profile!;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Complete all steps necessary to login to the server
|
||||
*/
|
||||
Future<void> connectToTestServer() async {
|
||||
|
||||
// Setup profile, and fetch user token as necessary
|
||||
final profile = await setupServerProfile(fetchToken: true);
|
||||
|
||||
// Connect to the server
|
||||
assert(await InvenTreeAPI().connectToServer(profile));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user