mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-27 21:16:48 +00:00
* Embed device platform information into token request * Remove username and password from userProfile * Display icon to show if profile has associated user token * Remove username / password from login settings screen * Refactor login procedure around token auth * Refactoring * Add profile login screen - Username / password values are not stored - Just to fetch api token * Login with basic auth * Pass profile to API when connecting * Remove _BASE_URL accessor - Fixes URL caching bug * Add more context to login screen * Add helper functions for unit tests - Change default port to 8000 (makes testing easier with local inventree instance) * api.dart handles basic auth now * fix api_test.dart * Further test improvements * linting fixes * Provide feedback when login fails * More linting * Record user details on login, and display in "about" widget * Fix string lookup * Add extra debug * Fix auth values * Fix user profile test
114 lines
3.0 KiB
Dart
114 lines
3.0 KiB
Dart
/*
|
|
* Unit tests for the API class
|
|
*/
|
|
|
|
import "package:test/test.dart";
|
|
import "package:inventree/user_profile.dart";
|
|
|
|
import "setup.dart";
|
|
|
|
void main() {
|
|
setupTestEnv();
|
|
|
|
setUp(() async {
|
|
// Ensure we have a user profile available
|
|
// This profile will match the dockerized InvenTree setup, running locally
|
|
|
|
// To start with, there should not be *any* profiles available
|
|
var profiles = await UserProfileDBManager().getAllProfiles();
|
|
|
|
for (var prf in profiles) {
|
|
await UserProfileDBManager().deleteProfile(prf);
|
|
}
|
|
|
|
// Check that there are *no* profiles in the database
|
|
profiles = await UserProfileDBManager().getAllProfiles();
|
|
expect(profiles.length, equals(0));
|
|
|
|
// Now, create one!
|
|
bool result = await UserProfileDBManager().addProfile(UserProfile(
|
|
name: testServerName,
|
|
server: testServerAddress,
|
|
selected: true,
|
|
));
|
|
|
|
expect(result, equals(true));
|
|
|
|
// Ensure we have one profile available
|
|
// expect(profiles.length, equals(1));
|
|
profiles = await UserProfileDBManager().getAllProfiles();
|
|
|
|
expect(profiles.length, equals(1));
|
|
|
|
int key = -1;
|
|
|
|
// Find the first available profile
|
|
for (var p in profiles) {
|
|
if (p.key != null) {
|
|
key = p.key ?? key;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Select the profile
|
|
await UserProfileDBManager().selectProfile(key);
|
|
});
|
|
|
|
// Run a set of tests for user profile functionality
|
|
group("Profile Tests:", () {
|
|
|
|
test("Add Invalid Profiles", () async {
|
|
// Add a profile with missing data
|
|
bool result = await UserProfileDBManager().addProfile(
|
|
UserProfile()
|
|
);
|
|
|
|
expect(result, equals(false));
|
|
|
|
// Add a profile with a new name
|
|
result = await UserProfileDBManager().addProfile(
|
|
UserProfile(
|
|
name: "Another Test Profile",
|
|
)
|
|
);
|
|
|
|
expect(result, equals(true));
|
|
|
|
// Check that the number of protocols available is still the same
|
|
var profiles = await UserProfileDBManager().getAllProfiles();
|
|
|
|
expect(profiles.length, equals(2));
|
|
});
|
|
|
|
test("Profile Name Check", () async {
|
|
bool result = await UserProfileDBManager().profileNameExists("doesnotexist");
|
|
expect(result, equals(false));
|
|
|
|
result = await UserProfileDBManager().profileNameExists("Test Server");
|
|
expect(result, equals(true));
|
|
});
|
|
|
|
test("Select Profile", () async {
|
|
// Ensure that we can select a user profile
|
|
final prf = await UserProfileDBManager().getSelectedProfile();
|
|
|
|
expect(prf, isNot(null));
|
|
|
|
if (prf != null) {
|
|
UserProfile p = prf;
|
|
|
|
expect(p.name, equals(testServerName));
|
|
expect(p.server, equals(testServerAddress));
|
|
|
|
expect(p.toString(), equals("<${p.key}> Test Server : http://localhost:8000/"));
|
|
|
|
// Test that we can update the profile
|
|
p.name = "different name";
|
|
|
|
bool result = await UserProfileDBManager().updateProfile(p);
|
|
expect(result, equals(true));
|
|
}
|
|
});
|
|
});
|
|
|
|
} |