Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
added initial login tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lewislarsen committed Aug 13, 2024
1 parent 8f5e039 commit 1f2b82c
Show file tree
Hide file tree
Showing 7 changed files with 581 additions and 6 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/flutter_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Flutter CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
name: Run Flutter tests and checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.x'
channel: 'stable'

- name: Install dependencies
run: flutter pub get

- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .

- name: Analyze project source
run: flutter analyze

- name: Generate mocks
run: flutter pub run build_runner build --delete-conflicting-outputs

- name: Run unit tests
run: flutter test

build-android:
name: Build Android APK
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.x'
channel: 'stable'
- run: flutter pub get
- run: flutter build apk
- uses: actions/upload-artifact@v2
with:
name: release-apk
path: build/app/outputs/flutter-apk/app-release.apk

build-ios:
name: Build iOS IPA
needs: test
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.x'
channel: 'stable'
- run: flutter pub get
- run: flutter build ios --release --no-codesign
- uses: actions/upload-artifact@v2
with:
name: release-ios
path: build/ios/iphoneos
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

# Generated mocks
*.mocks.dart
13 changes: 7 additions & 6 deletions lib/user_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ class UserProvider with ChangeNotifier {
User? _user;
User? get user => _user;
final AuthManager authManager;
final http.Client httpClient;

UserProvider({required this.authManager});
UserProvider({required this.authManager, http.Client? client})
: httpClient = client ?? http.Client();

Future<bool> login(String email, String password) async {
if (authManager.baseUrl == null) {
throw Exception('API base URL not set');
}

try {
final response = await http.post(
final response = await httpClient.post(
Uri.parse('${authManager.baseUrl}/login'),
headers: {'Content-Type': 'application/json'},
body: json.encode({'email': email, 'password': password}),
Expand Down Expand Up @@ -47,15 +49,14 @@ class UserProvider with ChangeNotifier {
}

try {
final response = await http.get(
final response = await httpClient.get(
Uri.parse('${authManager.baseUrl}/api/user'),
headers: authManager.headers,
);

if (response.statusCode == 200) {
final jsonResponse = json.decode(response.body);
if (jsonResponse is Map<String, dynamic> &&
jsonResponse.containsKey('data')) {
if (jsonResponse is Map<String, dynamic>) {
_user = User.fromJson(jsonResponse);
notifyListeners();
return true;
Expand All @@ -76,4 +77,4 @@ class UserProvider with ChangeNotifier {
_user = null;
notifyListeners();
}
}
}
Loading

0 comments on commit 1f2b82c

Please sign in to comment.