Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docChanges reports incorrect changes. #224

Closed
ccrusius opened this issue Apr 16, 2022 · 3 comments
Closed

docChanges reports incorrect changes. #224

ccrusius opened this issue Apr 16, 2022 · 3 comments

Comments

@ccrusius
Copy link

The following test fails and shows other incorrect behavior: docChanges is not reporting changes but the new contents of the collection. Nothing is ever deleted, and elements are added multiple times.

The correct sequence of events is "add 1" "add 2" "delete 2", but what is seen is "add 1" "add 1" "add 2" "add 1".

This behavior makes applications that use docChanges not testable with the fake.

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fake_cloud_firestore/fake_cloud_firestore.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  test('Deleting should trigger a delete doc change', () async {
    final Set<String> ids = {};
    final db = FakeFirebaseFirestore();
    final sub = db.collection('docs').snapshots().listen((querySnapshot) {
      for (final change in querySnapshot.docChanges) {
        debugPrint('${change.type} ${change.doc.id}');
        switch (change.type) {
          case DocumentChangeType.removed:
            ids.remove(change.doc.id);
            break;
          default:
            ids.add(change.doc.id);
            break;
        }
      }
    });
    addTearDown(sub.cancel);

    await db.collection('docs').doc('1').set(<String, dynamic>{});
    await pumpEventQueue();
    expect(ids, {'1'});

    await db.collection('docs').doc('2').set(<String, dynamic>{});
    await pumpEventQueue();
    expect(ids, {'1', '2'});

    await db.collection('docs').doc('2').delete();
    await pumpEventQueue();
    expect(ids, {'1'});
  });
}
@ryanhanks-bestow
Copy link

I've run into this as well. Has anyone looked into how difficult this would be to fix?

@msxenon
Copy link

msxenon commented Jul 19, 2023

the same

@atn832
Copy link
Owner

atn832 commented Dec 26, 2023

Thanks to @KholmatovS for fixing this. It's now published to https://pub.dev/packages/fake_cloud_firestore/changelog#245.

@atn832 atn832 closed this as completed Dec 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants