[verified] Publish ReelBox source under GPLv3
This commit is contained in:
commit
db2b505ca3
445 files changed
+105274
No files matched your search
@@ -0,0 +1,86 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:reelbox/data/api_service.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'api_service_test.dart' as fixtures;
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
setUp(() => SharedPreferences.setMockInitialValues({}));
|
||||
|
||||
for (final key in ['reelbox.api-selection.v1', 'reelbox.trusted-api.v1']) {
|
||||
for (final initializeFirst in [true, false]) {
|
||||
test(
|
||||
'migrates $key before ${initializeFirst ? 'initialization' : 'first request'} without touching local data',
|
||||
() async {
|
||||
const library =
|
||||
'{"saved":[{"id":7}],"locale":"fa","unknown":"keep exactly"}';
|
||||
SharedPreferences.setMockInitialValues({
|
||||
key: 'https://ninwinios.info/api/',
|
||||
'reelbox.local.v1': library,
|
||||
'unrelated-setting': 'keep',
|
||||
});
|
||||
String? valueAtRequest;
|
||||
final adapter = fixtures.StubAdapter((request) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
valueAtRequest = prefs.getString(key);
|
||||
return fixtures.jsonBody([]);
|
||||
});
|
||||
final api = ApiService(dio: Dio()..httpClientAdapter = adapter);
|
||||
if (initializeFirst) {
|
||||
await api.initialize();
|
||||
expect(adapter.requests, isEmpty);
|
||||
}
|
||||
await api.genres();
|
||||
expect(
|
||||
valueAtRequest,
|
||||
key == 'reelbox.api-selection.v1' ? 'primary' : isNull,
|
||||
);
|
||||
expect(
|
||||
adapter.requests.single.uri.origin,
|
||||
'https://reelbox.dartty.top',
|
||||
);
|
||||
expect(api.baseUrl, ApiService.iranBaseUrl);
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
expect(prefs.getString('reelbox.api-selection.v1'), 'primary');
|
||||
expect(prefs.getString('reelbox.local.v1'), library);
|
||||
expect(prefs.getString('unrelated-setting'), 'keep');
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
test(
|
||||
'Original API cannot be selected or injected as a production backend',
|
||||
() async {
|
||||
const original = 'https://ninwinios.info/api/';
|
||||
expect(() => ApiService(baseUrl: original), throwsA(isA<ApiException>()));
|
||||
final adapter = fixtures.StubAdapter((_) => fixtures.jsonBody([]));
|
||||
final api = ApiService(dio: Dio()..httpClientAdapter = adapter);
|
||||
await expectLater(api.setBaseUrl(original), throwsA(isA<ApiException>()));
|
||||
expect(api.baseUrl, ApiService.iranBaseUrl);
|
||||
for (final url in [
|
||||
'${original}genre/all/public/',
|
||||
'https://ninnies-server.info/api-user/newapi/config-server186.txt',
|
||||
]) {
|
||||
await expectLater(api.get(url), throwsA(isA<ApiException>()));
|
||||
}
|
||||
expect(adapter.requests, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'production starts on Iran without configuration discovery traffic',
|
||||
() async {
|
||||
final adapter = fixtures.StubAdapter((_) => fixtures.jsonBody([]));
|
||||
final api = ApiService(dio: Dio()..httpClientAdapter = adapter);
|
||||
await api.initialize();
|
||||
expect(api.baseUrl, ApiService.iranBaseUrl);
|
||||
expect(ApiService.defaultBaseUrl, ApiService.iranBaseUrl);
|
||||
expect(adapter.requests, isEmpty);
|
||||
await api.genres();
|
||||
expect(adapter.requests.single.uri.origin, 'https://reelbox.dartty.top');
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user