1
0
mirror of https://github.com/flutter/samples.git synced 2026-05-18 21:08:20 +00:00

Compass app (#2446)

This commit is contained in:
Eric Windmill
2024-09-27 18:49:27 -04:00
committed by GitHub
parent fcf2552cda
commit 46b5a26b26
326 changed files with 53272 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
// 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/repositories/booking/booking_repository.dart';
import 'package:compass_app/data/repositories/booking/booking_repository_remote.dart';
import 'package:compass_app/utils/result.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../../testing/fakes/services/fake_api_client.dart';
import '../../../../testing/models/booking.dart';
void main() {
group('BookingRepositoryRemote tests', () {
late BookingRepository bookingRepository;
late FakeApiClient fakeApiClient;
setUp(() {
fakeApiClient = FakeApiClient();
bookingRepository = BookingRepositoryRemote(
apiClient: fakeApiClient,
);
});
test('should get booking', () async {
final result = await bookingRepository.getBooking(0);
final booking = result.asOk.value;
expect(booking, kBooking.copyWith(id: 0));
});
test('should create booking', () async {
expect(fakeApiClient.bookings, isEmpty);
final result = await bookingRepository.createBooking(kBooking);
expect(result, isA<Ok<void>>());
expect(fakeApiClient.bookings.first, kBookingApiModel);
});
test('should get list of booking', () async {
final result = await bookingRepository.getBookingsList();
final list = result.asOk.value;
expect(list, [kBookingSummary]);
});
test('should delete booking', () async {
// Ensure no bookings exist
expect(fakeApiClient.bookings, isEmpty);
// Add a booking
var result = await bookingRepository.createBooking(kBooking);
expect(result, isA<Ok<void>>());
// Delete the booking
result = await bookingRepository.delete(0);
expect(result, isA<Ok<void>>());
// Check if the booking was deleted from the server
expect(fakeApiClient.bookings, isEmpty);
});
});
}