16
16
*/
17
17
18
18
import { expect } from 'chai' ;
19
- import {
20
- changesFromSnapshot ,
21
- QueryDocumentSnapshot ,
22
- SnapshotMetadata
23
- } from '../../../src/api/database' ;
24
- import { QueryDocumentSnapshot as ExpQueryDocumentSnapshot } from '../../../exp/src/api/snapshot' ;
25
- import { Query } from '../../../src/core/query' ;
19
+ import { QuerySnapshot } from '../../../exp/src/api/snapshot' ;
20
+ import { Query as InternalQuery } from '../../../src/core/query' ;
26
21
import { View } from '../../../src/core/view' ;
27
22
import { documentKeySet } from '../../../src/model/collections' ;
28
23
import { Document } from '../../../src/model/document' ;
@@ -36,13 +31,11 @@ import {
36
31
query
37
32
} from '../../util/helpers' ;
38
33
import { firestore } from '../../util/api_helpers' ;
39
- import { UserDataWriter } from '../../../src/api/user_data_writer' ;
40
-
41
- const userDataWriter = new UserDataWriter ( firestore ( ) ) ;
34
+ import { ExpUserDataWriter , Query } from '../../../exp/src/api/reference' ;
42
35
43
36
describe ( 'DocumentChange:' , ( ) => {
44
37
function expectPositions (
45
- query : Query ,
38
+ query : InternalQuery ,
46
39
initialDocs : Document [ ] ,
47
40
updates : Array < Document | DocumentKey >
48
41
) : void {
@@ -58,29 +51,20 @@ describe('DocumentChange:', () => {
58
51
const expected = documentSetAsArray ( updatedSnapshot . docs ) ;
59
52
const actual = documentSetAsArray ( initialSnapshot . docs ) ;
60
53
61
- const changes = changesFromSnapshot (
62
- updatedSnapshot ,
63
- true ,
64
- ( doc , fromCache , hasPendingWrite ) =>
65
- new QueryDocumentSnapshot (
66
- firestore ( ) ,
67
- new ExpQueryDocumentSnapshot (
68
- firestore ( ) . _delegate ,
69
- userDataWriter ,
70
- doc . key ,
71
- doc ,
72
- new SnapshotMetadata ( hasPendingWrite , fromCache ) ,
73
- /* converter= */ null
74
- )
75
- )
54
+ const db = firestore ( ) . _delegate ;
55
+ const snapshot = new QuerySnapshot (
56
+ db ,
57
+ new ExpUserDataWriter ( db ) ,
58
+ new Query ( db , /* converter= */ null , query ) ,
59
+ updatedSnapshot
76
60
) ;
77
61
78
- for ( const change of changes ) {
62
+ for ( const change of snapshot . docChanges ( ) ) {
79
63
if ( change . type !== 'added' ) {
80
64
actual . splice ( change . oldIndex , 1 ) ;
81
65
}
82
66
if ( change . type !== 'removed' ) {
83
- actual . splice ( change . newIndex , 0 , change . doc . _delegate . _document ! ) ;
67
+ actual . splice ( change . newIndex , 0 , change . doc . _document ! ) ;
84
68
}
85
69
}
86
70
0 commit comments