Use full baseUrl instead of baseUrl's origin

This commit is contained in:
Dat PHAM HOANG
2024-08-15 16:38:11 +07:00
committed by Dat H. Pham
parent e7566fcbe5
commit b073cd9aa8
2 changed files with 81 additions and 1 deletions
@@ -0,0 +1,80 @@
import 'package:core/data/network/config/dynamic_url_interceptors.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('setJmapUrl test', () {
test('should set jmapUrl to the full URI', () {
final dynamicUrlInterceptors = DynamicUrlInterceptors();
const fullUri = 'https://example.com/basicauth';
dynamicUrlInterceptors.setJmapUrl(fullUri);
expect(dynamicUrlInterceptors.jmapUrl, equals(fullUri));
});
test('should set jmapUrl to the full URI when url have multiple sub-paths', () {
final dynamicUrlInterceptors = DynamicUrlInterceptors();
const fullUri = 'https://example.com/basicauth/jmap';
dynamicUrlInterceptors.setJmapUrl(fullUri);
expect(dynamicUrlInterceptors.jmapUrl, equals(fullUri));
});
test('should set jmapUrl to the full URI when url have no sub-paths', () {
final dynamicUrlInterceptors = DynamicUrlInterceptors();
const fullUri = 'https://example.com';
dynamicUrlInterceptors.setJmapUrl(fullUri);
expect(dynamicUrlInterceptors.jmapUrl, equals(fullUri));
});
test('should set jmapUrl to the full URI when url have port and sub-paths', () {
final dynamicUrlInterceptors = DynamicUrlInterceptors();
const fullUri = 'https://example.com:8080/basicauth/jmap/';
dynamicUrlInterceptors.setJmapUrl(fullUri);
expect(dynamicUrlInterceptors.jmapUrl, equals(fullUri));
});
});
group('changeBaseUrl test', () {
test('should set baseUrl to the full URI', () {
final dynamicUrlInterceptors = DynamicUrlInterceptors();
const fullUri = 'https://example.com/basicauth';
dynamicUrlInterceptors.changeBaseUrl(fullUri);
expect(dynamicUrlInterceptors.baseUrl, equals(fullUri));
});
test('should set baseUrl to the full URI when url have multiple sub-paths', () {
final dynamicUrlInterceptors = DynamicUrlInterceptors();
const fullUri = 'https://example.com/basicauth/jmap';
dynamicUrlInterceptors.changeBaseUrl(fullUri);
expect(dynamicUrlInterceptors.baseUrl, equals(fullUri));
});
test('should set baseUrl to the full URI when url have no sub-paths', () {
final dynamicUrlInterceptors = DynamicUrlInterceptors();
const fullUri = 'https://example.com';
dynamicUrlInterceptors.changeBaseUrl(fullUri);
expect(dynamicUrlInterceptors.baseUrl, equals(fullUri));
});
test('should set baseUrl to the full URI when url have port and sub-paths', () {
final dynamicUrlInterceptors = DynamicUrlInterceptors();
const fullUri = 'https://example.com:8080/basicauth/jmap/';
dynamicUrlInterceptors.changeBaseUrl(fullUri);
expect(dynamicUrlInterceptors.baseUrl, equals(fullUri));
});
});
}
@@ -83,7 +83,7 @@ abstract class ReloadableController extends BaseController {
void _handleGetCredentialSuccess(GetCredentialViewState success) {
_setDataToInterceptors(
baseUrl: success.baseUrl.origin,
baseUrl: success.baseUrl.toString(),
userName: success.userName,
password: success.password);
getSessionAction();