snapshot of https://github.com/flutter/samples.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Main Branch CI / Test Flutter beta on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter stable on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter beta on macos-latest (push) Has been cancelled
Main Branch CI / Test Flutter stable on macos-latest (push) Has been cancelled

This commit is contained in:
upstream-mirror
2026-09-16 01:43:26 +05:00
commit 9ed6a80afa
2886 changed files with 140184 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
// Copyright 2024 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:compass_app/data/services/api/api_client.dart';
import 'package:compass_app/domain/models/continent/continent.dart';
import 'package:compass_app/utils/result.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../../testing/mocks.dart';
import '../../../../testing/models/activity.dart';
import '../../../../testing/models/booking.dart';
import '../../../../testing/models/destination.dart';
import '../../../../testing/models/user.dart';
import '../../../../testing/utils/result.dart';
void main() {
group('ApiClient', () {
late MockHttpClient mockHttpClient;
late ApiClient apiClient;
setUp(() {
mockHttpClient = MockHttpClient();
apiClient = ApiClient(clientFactory: () => mockHttpClient);
});
test('should get continents', () async {
final continents = [const Continent(name: 'NAME', imageUrl: 'URL')];
mockHttpClient.mockGet('/continent', continents);
final result = await apiClient.getContinents();
expect(result.asOk.value, continents);
});
test('should get activities by destination', () async {
final activites = [kActivity];
mockHttpClient.mockGet(
'/destination/${kDestination1.ref}/activity',
activites,
);
final result = await apiClient.getActivityByDestination(
kDestination1.ref,
);
expect(result.asOk.value, activites);
});
test('should get booking', () async {
mockHttpClient.mockGet(
'/booking/${kBookingApiModel.id}',
kBookingApiModel,
);
final result = await apiClient.getBooking(kBookingApiModel.id!);
expect(result.asOk.value, kBookingApiModel);
});
test('should get bookings', () async {
mockHttpClient.mockGet('/booking', [kBookingApiModel]);
final result = await apiClient.getBookings();
expect(result.asOk.value, [kBookingApiModel]);
});
test('should get destinations', () async {
mockHttpClient.mockGet('/destination', [kDestination1]);
final result = await apiClient.getDestinations();
expect(result.asOk.value, [kDestination1]);
});
test('should get user', () async {
mockHttpClient.mockGet('/user', userApiModel);
final result = await apiClient.getUser();
expect(result.asOk.value, userApiModel);
});
test('should post booking', () async {
mockHttpClient.mockPost('/booking', kBookingApiModel);
final result = await apiClient.postBooking(kBookingApiModel);
expect(result.asOk.value, kBookingApiModel);
});
test('should delete booking', () async {
mockHttpClient.mockDelete('/booking/0');
final result = await apiClient.deleteBooking(0);
expect(result, isA<Ok<void>>());
});
});
}

View File

@@ -0,0 +1,32 @@
// Copyright 2024 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:compass_app/data/services/api/auth_api_client.dart';
import 'package:compass_app/data/services/api/model/login_request/login_request.dart';
import 'package:compass_app/data/services/api/model/login_response/login_response.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../../testing/mocks.dart';
import '../../../../testing/utils/result.dart';
void main() {
group('AuthApiClient', () {
late MockHttpClient mockHttpClient;
late AuthApiClient apiClient;
setUp(() {
mockHttpClient = MockHttpClient();
apiClient = AuthApiClient(clientFactory: () => mockHttpClient);
});
test('should post login', () async {
const loginResponse = LoginResponse(token: 'TOKEN', userId: '123');
mockHttpClient.mockPost('/login', loginResponse, 200);
final result = await apiClient.login(
const LoginRequest(email: 'EMAIL', password: 'PASSWORD'),
);
expect(result.asOk.value, loginResponse);
});
});
}