Skip to content

Commit

Permalink
fix: network config url generation
Browse files Browse the repository at this point in the history
Signed-off-by: Isaac Obella <wizlif@users.noreply.github.com>
  • Loading branch information
wizlif committed Jul 4, 2023
1 parent 8829e1e commit 4258152
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
7 changes: 4 additions & 3 deletions lib/core/config/network_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ part of '../core.dart';

/// Manage all url creation and building
// base static url
final baseStaticUrl = '${dotenv.get('BASE_STATIC_ENDPOINT_URL')}/\$web';
final baseStaticUrl =
Uri.parse(dotenv.get('BASE_STATIC_ENDPOINT_URL')).resolve('\$web');

final nullStaticUrl = '$baseStaticUrl/${null}';
final nullStaticUrl = baseStaticUrl.resolve('null').toString();

extension ImageExtension on String {
String get imageUrl => '$baseStaticUrl/$this';
String get imageUrl => baseStaticUrl.resolve(this).toString();
}
21 changes: 17 additions & 4 deletions test/core/config/network.config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ void main() {
'when the user profile is not null', () async {
// arrange
final userProfile = testUserProfile;

// act
final userAvatarUrl = userProfile.avatarUrl;

// assert
expect(
userAvatarUrl,
equals('$baseStaticUrl/${userProfile.profile.avatar}'),
equals(
Uri.parse(baseStaticUrl)
.resolve(userProfile.profile.avatar)
.toString(),
),
);
});

Expand Down Expand Up @@ -65,7 +70,11 @@ void main() {
// assert
expect(
crowdActionBannerUrl,
equals('$baseStaticUrl/${crowdAction.images.banner}'),
equals(
Uri.parse(baseStaticUrl)
.resolve(crowdAction.images.banner)
.toString(),
),
);
});

Expand Down Expand Up @@ -99,7 +108,9 @@ void main() {
// assert
expect(
crowdActionCardUrl,
equals('$baseStaticUrl/${crowdAction.images.card}'),
equals(
Uri.parse(baseStaticUrl).resolve(crowdAction.images.card).toString(),
),
);
});

Expand Down Expand Up @@ -133,7 +144,9 @@ void main() {
// assert
expect(
participationAvatarUrl,
equals('$baseStaticUrl/${participation.avatar}'),
equals(
Uri.parse(baseStaticUrl).resolve(participation.avatar).toString(),
),
);
});

Expand Down
2 changes: 1 addition & 1 deletion test/presentation/auth/profile_photo_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void main() {
GetIt.I.registerSingleton<AvatarBloc>(avatarBloc);

// Auth Bloc
authBloc = MockAuthBloc();
authBloc = MockAuthBloc();
when(() => authBloc.state).thenAnswer(
(_) => AuthState.initial(),
);
Expand Down

0 comments on commit 4258152

Please sign in to comment.