Skip to content

Commit b2d3402

Browse files
Merge pull request #18 from ReallySmallSoftware/fix/querySnapshotLog
Various small fixes
2 parents 96e4f81 + 3944e12 commit b2d3402

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package uk.co.reallysmall.cordova.plugin.firestore;
2+
3+
import com.google.firebase.firestore.Query;
4+
5+
import org.junit.Test;
6+
7+
import static org.mockito.Mockito.mock;
8+
import static org.mockito.Mockito.verify;
9+
10+
public class LimitQueryHandlerTest {
11+
LimitQueryHandler limitQueryHandler = new LimitQueryHandler();
12+
13+
Query query = mock(Query.class);
14+
15+
16+
@Test
17+
public void testShouldHandleStringArgument() {
18+
limitQueryHandler.handle(query, "10");
19+
verify(query).limit(10);
20+
}
21+
22+
@Test
23+
public void testShouldHandleIntArgument() {
24+
limitQueryHandler.handle(query, 10);
25+
verify(query).limit(10);
26+
}
27+
28+
@Test(expected = IllegalArgumentException.class)
29+
public void testShouldThrowIllegalArgumentExceptiononArrayArgument() {
30+
limitQueryHandler.handle(query, new String[5]);
31+
}
32+
}
33+

src/android/uk/co/reallysmall/cordova/plugin/firestore/FirestoreLog.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,35 @@ public static void setLogLevel(String logLevel) {
2020
_logLevel = Log.WARN;
2121
break;
2222
default:
23-
FirestoreLog.w(FirestorePlugin.TAG, "New logLevel unknown, leaving previous setting : " + _logLevel);
23+
FirestoreLog.e(FirestorePlugin.TAG, "New logLevel unknown, leaving previous setting : " + _logLevel);
2424
break;
2525
}
26+
27+
FirestoreLog.d(FirestorePlugin.TAG, "New logLevel : " + _logLevel);
2628
}
2729

2830
public static void d(String TAG, String message) {
29-
if (_logLevel >= Log.DEBUG) {
31+
if (_logLevel <= Log.DEBUG) {
3032
Log.d(TAG, message);
3133
}
3234
}
3335
public static void w(String TAG, String message) {
34-
if (_logLevel >= Log.WARN) {
36+
if (_logLevel <= Log.WARN) {
3537
Log.w(TAG, message);
3638
}
3739
}
3840
public static void w(String TAG, String message, Exception e) {
39-
if (_logLevel >= Log.WARN) {
41+
if (_logLevel <= Log.WARN) {
4042
Log.w(TAG, message, e);
4143
}
4244
}
4345
public static void e(String TAG, String message) {
44-
if (_logLevel >= Log.ERROR) {
46+
if (_logLevel <= Log.ERROR) {
4547
Log.e(TAG, message);
4648
}
4749
}
4850
public static void e(String TAG, String message, Exception e) {
49-
if (_logLevel >= Log.ERROR) {
51+
if (_logLevel <= Log.ERROR) {
5052
Log.e(TAG, message, e);
5153
}
5254
}

src/android/uk/co/reallysmall/cordova/plugin/firestore/LimitQueryHandler.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
public class LimitQueryHandler implements QueryHandler {
77
@Override
88
public Query handle(Query query, Object limit) {
9-
return query.limit(Long.parseLong((String) limit));
9+
System.out.println("Type of limit " + limit.getClass().getName());
10+
Long longLimit;
11+
if (limit instanceof String) {
12+
longLimit = Long.parseLong((String) limit);
13+
} else if(limit instanceof Number) {
14+
longLimit = ((Number) limit).longValue();
15+
} else {
16+
throw new IllegalArgumentException("Limit should be instanceof String or Number, got : " + limit.getClass().getName());
17+
}
18+
19+
return query.limit(longLimit);
1020
}
1121
}

www/android_ios/document_reference.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ describe('DocumentReference', () => {
2222
describe('collection', () => {
2323
it('should return a CollectionReference with proper path', () => {
2424

25-
console.log('What is document_reference in test', typeof DocumentReference);
2625
const subCollectionRef = (parentDocRef).collection(subCollection);
2726
expect(subCollectionRef).toBeInstanceOf(CollectionReference);
2827
expect(subCollectionRef.path).toBe('root/parent/sub');

www/android_ios/query_snapshot.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
var QueryDocumentSnapshot = require('./query_document_snapshot');
22

33
function QuerySnapshot(data) {
4-
console.log('building query_snapshot', data);
54
this._data = data;
65
}
76

0 commit comments

Comments
 (0)