Skip to content

Commit f614189

Browse files
committed
Add test for orderBy with Date
1 parent 532af4c commit f614189

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

test/unit/firestore-collection.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ describe('MockFirestoreCollection', function () {
334334
}).catch(done);
335335
});
336336

337-
it('returns documents ordered by date', function(done) {
337+
it('returns documents ordered by timestamp', function(done) {
338338
db.collection('group').doc().create({
339339
name: 'a',
340340
date: Timestamp.fromMillis(1000)
@@ -363,6 +363,36 @@ describe('MockFirestoreCollection', function () {
363363
}).catch(done);
364364
db.flush();
365365
});
366+
367+
it('returns documents ordered by date', function(done) {
368+
db.collection('group').doc().create({
369+
name: 'a',
370+
date: new Date(1000)
371+
}).catch(done);
372+
db.flush();
373+
db.collection('group').add({
374+
name: 'b',
375+
date: new Date(2000)
376+
}).catch(done);
377+
db.flush();
378+
379+
db.collection('group').orderBy('date', 'asc').get().then(function (snap) {
380+
expect(snap.size).to.equal(2);
381+
expect(snap.docs[0].data().name).to.equal('a');
382+
expect(snap.docs[0].data().date).to.have.property('seconds');
383+
expect(snap.docs[1].data().name).to.equal('b');
384+
expect(snap.docs[1].data().date).to.have.property('seconds');
385+
386+
db.collection('group').orderBy('date', 'desc').get().then(function (snap) {
387+
expect(snap.size).to.equal(2);
388+
expect(snap.docs[0].data().name).to.equal('b');
389+
expect(snap.docs[1].data().name).to.equal('a');
390+
done();
391+
}).catch(done);
392+
db.flush();
393+
}).catch(done);
394+
db.flush();
395+
});
366396
});
367397

368398
describe('#limit', function () {

0 commit comments

Comments
 (0)