Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/src/client_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class ClientIO extends ClientBase with ClientMixin {
_endPoint.startsWith(RegExp("http://|https://")),
"endPoint $_endPoint must start with 'http'",
);
init();
}

@override
Expand Down
68 changes: 68 additions & 0 deletions test/src/client_io_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@TestOn('vm')
import 'dart:io';

import 'package:flutter_test/flutter_test.dart';
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
import 'package:appwrite/src/client_io.dart';

class FakePathProvider extends PathProviderPlatform {
late String _tempPath;

FakePathProvider() {
_tempPath = Directory.systemTemp.createTempSync('appwrite_test_').path;
}

@override
Future<String?> getApplicationDocumentsPath() async => _tempPath;
}

void main() {
group('ClientIO', () {
late FakePathProvider fakePathProvider;

setUp(() {
fakePathProvider = FakePathProvider();
PathProviderPlatform.instance = fakePathProvider;
});

tearDown(() {
try {
Directory(fakePathProvider._tempPath).deleteSync(recursive: true);
} catch (_) {}
});

test('constructor should not eagerly call init()', () {
// Creating a ClientIO should NOT trigger init() immediately.
// If init() is called eagerly, it causes "No JNI instance is available"
// errors on Android in release mode because the platform channels
// are not yet ready when the constructor runs.
final client = ClientIO(
endPoint: 'https://cloud.appwrite.io/v1',
selfSigned: false,
);

// init() should not have been called yet - initialization should
// be deferred until the first API call
expect(client.initProgress, isFalse,
reason: 'init() should not be called eagerly in the constructor');
expect(client.initialized, isFalse,
reason: 'Client should not be initialized until first API call');
});

test('init() should be called lazily on first API call', () async {
final client = ClientIO(
endPoint: 'https://cloud.appwrite.io/v1',
selfSigned: false,
);

// Before any call, client should not be initialized
expect(client.initialized, isFalse);

// Trigger initialization by calling init() directly
await client.init();

// After init, client should be initialized
expect(client.initialized, isTrue);
});
});
Comment on lines +54 to +67

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test title doesn't match what's actually tested

The test is named 'init() should be called lazily on first API call', but it never exercises the call() code path — it invokes client.init() directly. This means the guard logic in call() (lines 508-513 of client_io.dart) that triggers lazy init is never exercised by any test in this file. If someone accidentally removed or broke that guard, these tests would still pass.

}
Loading