-
Notifications
You must be signed in to change notification settings - Fork 1
/
remote-collections-tests.js
138 lines (100 loc) · 5.5 KB
/
remote-collections-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Import Tinytest from the tinytest Meteor package.
// meteor test-packages jkuester:remote-collections
import {Tinytest} from "meteor/tinytest";
// Import and rename a variable exported by remote-collections.js.
import {RemoteCollections} from "meteor/jkuester:remote-collections";
import {RemoteCollectionsProvider} from 'meteor/jkuester:remote-collections-provider';
//------------------------------------------------------------------//
// GLOBAL USAGE AMONG ALL TESTS
//------------------------------------------------------------------//
//NOTE: Make sure you a second application with the specific methods
// running on the specific port.
const CURRENT_CONNECTION_ID = "tinytest-current-connection";
const CURRENT_CONNECTION_URL = "http://localhost:3030";
const CURRENT_REMOTE_LOAD_METHOD = RemoteCollectionsProvider.DEFAULT_GET_COLLECTIONS; // 'RemoteProvider.getPrivateDatabases';
const CURRENT_REMOTE_SUBSCRIBE_METHOD = RemoteCollectionsProvider.DEFAULT_GET_PUBLICATIONS; //"RemoteProvider.getAvailableSubscriptions";
const HAS_REMOTE_COLLECTIONS_PROVIDER = RemoteCollectionsProvider.HAS_REMOTE_COLLECTIONS_PROVIDER; //"RemoteProvider.hasRemoteCollectionsProvider";
const EXPECTED_COLLECTION_NAME = RemoteCollectionsProvider.DEFAULT_COLLECTION; //"tests";
const observe = {
added: function (item) {
//console.log('-- remote item added--');
//console.log(item);
//GLOBAL_TEST_OBJ.isNotNull(item);
},
removed: function (item) {
//console.log('-- remote items removed--');
//console.log(item);
//GLOBAL_TEST_OBJ.isNotNull(item);
}
};
//------------------------------------------------------------------//
// STARTUP SETTINGS
//------------------------------------------------------------------//
Meteor.startup(() => {
Tinytest.add('remote-collections - subscriptions', function (test) {
const results = RemoteCollections.loadRemoteSubscriptions({id: CURRENT_CONNECTION_ID, method: CURRENT_REMOTE_SUBSCRIBE_METHOD });
testExists(test, results, "results");
test.equal(results[CURRENT_CONNECTION_ID], true);
const subscriptions = RemoteCollections.getSubscriptionsById(CURRENT_CONNECTION_ID);
console.log(subscriptions);
testExists(test, subscriptions, "subscriptions");
testObjectHasChildren(test, subscriptions, 1);
const collections = RemoteCollections.getCollections();
testExists(test, collections, "collections");
const collectionsNames = Object.keys(collections);
test.equal(collectionsNames.length, 1);
const currentCollectionName = collectionsNames[0];
testExists(test, currentCollectionName, "currentCollectionName");
test.equal(currentCollectionName, EXPECTED_COLLECTION_NAME);
const currentCollection = collections[EXPECTED_COLLECTION_NAME];
testExists(test, currentCollection, "currentCollection");
test.notEqual(currentCollection.hasOwnProperty('find'), true);
const found = currentCollection.find({});
testExists(test,found, "found");
//test.notEqual(found.count(), 0); //TODO why is 0 here? Items are added though...
});
});
Tinytest.add('remote-collections - import not null', function (test) {
//importing a fresh RemoteCollections class
testExists(test, RemoteCollections, "RemoteCollections");
RemoteCollections.setDebug(true);
});
Tinytest.add('remote-collections - initial status', function (test) {
const initialRemoteCollections = RemoteCollections.getCollections();
testObjectHasChildren(test, initialRemoteCollections, 0);
test.equal(initialRemoteCollections, {}), "initial collection is not empty";
});
Tinytest.add('remote-collections - create single remote ddp connections', function (test) {
RemoteCollections.addDDPConnectionURL(CURRENT_CONNECTION_ID, CURRENT_CONNECTION_URL);
const connection = RemoteCollections.getDDPConnection(CURRENT_CONNECTION_ID);
testExists(test, connection, "connection");
const allConnections = RemoteCollections.getAllDDPConnections();
testObjectHasChildren(test, allConnections, 1);
});
Tinytest.add('remote-collections - load single collection', function (test) {
RemoteCollections.loadRemoteCollections({id:CURRENT_CONNECTION_ID, method:CURRENT_REMOTE_LOAD_METHOD, observe:observe});
const collections = RemoteCollections.getCollections();
testExists(test, collections, "collections");
const collectionsNames = Object.keys(collections);
test.equal(collectionsNames.length, 1, "unexpected collection length: ");
const currentCollectionName = collectionsNames[0];
testExists(test, currentCollectionName, "currentCollectionName");
test.equal(currentCollectionName, EXPECTED_COLLECTION_NAME);
const currentCollection = collections[EXPECTED_COLLECTION_NAME];
testExists(test, currentCollection, "currentCollection");
test.notEqual(currentCollection.hasOwnProperty('find'), true);
const found = currentCollection.find({});
testExists(test,found, "found");
});
function testExists(test, obj, optionalName){
if (!optionalName)
optionalName = "";
test.isNotNull(obj, "unexpected object is null ("+optionalName+")");
test.isNotUndefined(obj, "unexpected: object is undefined ("+optionalName+")");
}
function testObjectHasChildren(test, obj, expectedChildCount){
testExists(test, obj);
const keys = Object.keys(obj);
testExists(test, keys);
test.equal(keys.length, expectedChildCount, "unexpected: childcount is " + keys.length+", expected is "+expectedChildCount);
}