Skip to content

Commit

Permalink
add tests for export with params
Browse files Browse the repository at this point in the history
  • Loading branch information
jorishermans committed Dec 21, 2014
1 parent 6433ad6 commit 75b8efa
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions lib/cargo_base.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
library cargo;

import 'dart:async';
import 'dart:convert';

part 'src/cargo.dart';
part 'src/shared/memory_impl.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/client/indexdb_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class IndexDbCargo extends Cargo {

int count = 0;

List<String> keys = new List<String>();
Set<String> keys = new Set<String>();

/// Returns true if IndexedDB is supported on this platform.
static bool get supported => IdbFactory.supported;
Expand Down
12 changes: 9 additions & 3 deletions lib/src/shared/cargo_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ part of cargo;
Map queryMap(Map values, Map params) {
Map newValues = new Map();

values.forEach((key, value) {
for ( var key in values.keys) {
var value = values[key];
if (value is String) {
value = JSON.decode(value);
}

if (value is Map) {
Map examen_value = value;

Expand All @@ -14,7 +19,7 @@ Map queryMap(Map values, Map params) {
// use mirrors in the future
newValues[key] = value;
}
});
}
return newValues;
}

Expand Down Expand Up @@ -46,7 +51,8 @@ Map filterCollection(Map coll, collection) {
for ( var key in coll.keys) {
var value = coll[key];
if (key.startsWith(collection)) {
newValues[key] = value;
String newKey = key.replaceAll(collection, '');
newValues[newKey] = value;
}
}
return newValues;
Expand Down
17 changes: 15 additions & 2 deletions test/client/cargo_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:cargo/cargo_client.dart';
import '../logic/collection_tests.dart';
import '../logic/normal_tests.dart';
import '../logic/async_tests.dart';
import '../logic/export_tests.dart';

void main() {
MemoryCargo storageMem = new Cargo(MODE: CargoMode.MEMORY);
Expand All @@ -19,8 +20,8 @@ void main() {
run(storage, "localstorage");
});

group('indexdb_normal', () {
runAsync(storageIndexDB, "indexdb");
group('indexeddb_normal', () {
runAsync(storageIndexDB, "indexedDB");
});

group('memory', () {
Expand All @@ -31,6 +32,18 @@ void main() {
runCollection(storage, "localstorage");
});

group('memory exports', () {
runExports(storageMem, "memory");
});

group('localstorage exports', () {
runExports(storage, "localstorage");
});

/*group('indexedDB exports', () {
runExports(storageIndexDB, "indexedDB");
});*/

/*group('indexdb', () {
runCollection(storage, "indexdb");
});*/
Expand Down
4 changes: 2 additions & 2 deletions test/logic/export_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ void runExports(CargoBase storage, String name) {
return storage.setItem("Facebook", facebookData).then((_) {
return storage.setItem("Medium", mediumData).then((_) {
return storage.export(params: params).then((Map results) {
expect(2, results.length);
expect("Uber", results['Uber']['name']);
expect(results.length, 2);
expect(results['Uber']['name'], "Uber");
});
});
});
Expand Down
12 changes: 6 additions & 6 deletions test/server/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ void main() {
params2['date'] = date2;

test('test contains positive', () {
expect(true, containsByOverlay(values['YO'], params));
expect(containsByOverlay(values['YO'], params), true);
});

test('test contains negative', () {
expect(false, containsByOverlay(values['YO'], params2));
expect(containsByOverlay(values['YO'], params2), false);
});

test('test query map', () {
Map queryResult = queryMap(values, params2);
expect(2, queryResult.length);
expect("Uber", queryResult['Uber']['name']);
expect(queryResult.length, 2);
expect(queryResult['Uber']['name'], 'Uber');
});

test('test query map with params null', () {
Map queryResult = queryMap(values, null);
expect(values.length, queryResult.length);
expect("Uber", queryResult['Uber']['name']);
expect(queryResult.length, values.length);
expect(queryResult['Uber']['name'], 'Uber');
});
}

0 comments on commit 75b8efa

Please sign in to comment.