usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [26/50] [abbrv] incubator-usergrid git commit: add integration tests
Date Fri, 24 Jul 2015 15:21:54 GMT
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ea579cbb/stack/rest_integration_tests/test/queries/location.js
----------------------------------------------------------------------
diff --git a/stack/rest_integration_tests/test/queries/location.js b/stack/rest_integration_tests/test/queries/location.js
new file mode 100644
index 0000000..6fbc96a
--- /dev/null
+++ b/stack/rest_integration_tests/test/queries/location.js
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+var entities = require("../../lib/entities");
+var should = require("should");
+var async = require('async');
+var config = require('../../config');
+var response = require('../../lib/response');
+
+module.exports = {
+    test: function() {
+        describe("filter " + config.genericTestCollection2 + " with location queries", function(done)
{
+            var locationString = config.location.latitude + ", " + config.location.longitude;
+            var query = "location within 1000 of " + locationString;
+            maxNumberOfEntities = Math.max(config.numberOfEntities, 100);
+            it("should return all results with a location within 1000m of " + locationString,
function(done) {
+                entities.getWithQuery(config.genericTestCollection2, query, maxNumberOfEntities,
function(err, body) {
+                    should(err).be.null;
+                    body.entities.should.be.an.instanceOf(Array);
+                    body.entities.forEach(function(entity) {
+                        var distance = response.distanceInMeters(config.location, entity.location);
+                        distance.should.be.lessThan(1000);
+                    });
+                    done();
+                });
+            });
+        });
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ea579cbb/stack/rest_integration_tests/test/queries/order.js
----------------------------------------------------------------------
diff --git a/stack/rest_integration_tests/test/queries/order.js b/stack/rest_integration_tests/test/queries/order.js
new file mode 100644
index 0000000..8cbb78f
--- /dev/null
+++ b/stack/rest_integration_tests/test/queries/order.js
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+var entities = require("../../lib/entities");
+var should = require("should");
+var async = require('async');
+var config = require('../../config');
+
+module.exports = {
+    test: function() {
+        describe("sort " + config.genericTestCollection1 + " with 'order by' queries", function(done)
{
+            var query1 = "order by created desc";
+            it('should return a subset of results ' + query1.replace('order', 'ordered'),
function(done) {
+                entities.getWithQuery(config.genericTestCollection1, query1, maxNumberOfEntities,
function(err, body) {
+                    should(err).be.null;
+                    body.entities.should.be.an.instanceOf(Array);
+                    var comparisonArray = body.entities;
+                    comparisonArray.sort(function(a, b) {
+                        return a.created + b.created;
+                    });
+                    body.entities.should.equal(comparisonArray);
+                    done();
+                });
+            });
+            var query2 = "order by created asc";
+            it('should return a subset of results ' + query2.replace('order', 'ordered'),
function(done) {
+                entities.getWithQuery(config.genericTestCollection1, query2, maxNumberOfEntities,
function(err, body) {
+                    should(err).be.null;
+                    body.entities.should.be.an.instanceOf(Array);
+                    var comparisonArray = body.entities;
+                    comparisonArray.sort(function(a, b) {
+                        return a.created - b.created;
+                    });
+                    body.entities.should.equal(comparisonArray);
+                    done();
+                });
+            });
+            var query3 = "order by optionsProperty desc";
+            it('should return a subset of results ' + query3.replace('order', 'ordered'),
function(done) {
+                entities.getWithQuery(config.genericTestCollection1, query3, maxNumberOfEntities,
function(err, body) {
+                    should(err).be.null;
+                    body.entities.should.be.an.instanceOf(Array);
+                    var comparisonArray = body.entities;
+                    comparisonArray.sort(function(a, b) {
+                        if (a.optionsProperty > b.optionsProperty) return -1;
+                        if (a.optionsProperty < b.optionsProperty) return 1;
+                        return 0;
+                    });
+                    body.entities.should.equal(comparisonArray);
+                    done();
+                });
+            });
+            var query4 = "order by optionsProperty asc";
+            it('should return a subset of results ' + query4.replace('order', 'ordered'),
function(done) {
+                entities.getWithQuery(config.genericTestCollection1, query4, maxNumberOfEntities,
function(err, body) {
+                    should(err).be.null;
+                    body.entities.should.be.an.instanceOf(Array);
+                    var comparisonArray = body.entities;
+                    comparisonArray.sort(function(a, b) {
+                        if (a.optionsProperty < b.optionsProperty) return -1;
+                        if (a.optionsProperty > b.optionsProperty) return 1;
+                        return 0;
+                    });
+                    done();
+                });
+            });
+        });
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ea579cbb/stack/rest_integration_tests/test/setup.js
----------------------------------------------------------------------
diff --git a/stack/rest_integration_tests/test/setup.js b/stack/rest_integration_tests/test/setup.js
new file mode 100644
index 0000000..4fbc664
--- /dev/null
+++ b/stack/rest_integration_tests/test/setup.js
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+// here we're going to do teardown of BaaS environment - deletion of users, entities, etc.
+var users = require("../lib/users");
+var entities = require("../lib/entities");
+var config = require("../config");
+var async = require("async");
+var uuid = require("uuid");
+var should = require("should");
+
+module.exports = {
+    users: [],
+    admins: [],
+    do: function(cb) {
+        console.log("    setup");
+        async.parallel([
+                function(cb) {
+                    // create admin user
+                    var id = uuid.v1().toString().replace("-", "");
+                    var admin = {
+                        username: id + "user",
+                        password: "pwd" + id,
+                        name: id + " name",
+                        email: id + "@uge2e.com"
+                    }
+                    users.add(admin, function(err, user) {
+                        users.addToRole(user.username, "admin", function(err) {
+                            module.exports.admins.push(admin);
+                            cb(err, err ? null : admin);
+                        });
+                    });
+                },
+                function(cb) {
+                    // create app users
+                    var size = config.numberOfUsers;
+                    var userArr = [];
+                    module.exports.users = userArr;
+                    for (var i = 0; i < size; i++) {
+                        var id = uuid.v1().toString().replace("-", "");
+                        userArr.push({
+                            username: id + "user",
+                            password: "pwd" + id,
+                            name: id + " name",
+                            email: id + "@uge2e.com"
+                        });
+                    }
+                    async.each(
+                        userArr,
+                        function(user, cb) {
+                            users.add(user, function(err, user) {
+                                cb(err, user);
+                            });
+                        },
+                        function(err, localUsers) {
+                            cb(err);
+                        }
+                    )
+                },
+                function(cb) {
+                    // create entities
+                    async.parallel([
+                            function(cb) {
+                                entities.create(config.genericTestCollection1, config.numberOfEntities,
function(err, body) {
+                                    cb(err);
+                                });
+                            },
+                            function(cb) {
+                                entities.create(config.genericTestCollection2, config.numberOfEntities,
function(err, body) {
+                                    cb(err);
+                                });
+                            },
+                            function(cb) {
+                                entities.create(config.consumableTestCollection, config.numberOfEntities,
function(err, body) {
+                                    cb(err);
+                                });
+                            }
+                        ],
+                        function(err, data) {
+                            cb(err);
+                        });
+                }
+            ],
+            function(err, data) {
+                should(err).be.null;
+                console.log("      ✓".green + " done".grey);
+                if (cb && typeof(cb) === 'function') cb(err);
+            });
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ea579cbb/stack/rest_integration_tests/test/teardown.js
----------------------------------------------------------------------
diff --git a/stack/rest_integration_tests/test/teardown.js b/stack/rest_integration_tests/test/teardown.js
new file mode 100644
index 0000000..7afdc97
--- /dev/null
+++ b/stack/rest_integration_tests/test/teardown.js
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+var entities = require("../lib/entities");
+var should = require("should");
+var async = require("async");
+var config = require("../config");
+var inflect = require("i")();
+
+module.exports = {
+    do: function(cb) {
+        console.log("    teardown");
+        async.parallel([
+                function(cb) {
+                    entities.deleteAll(config.usersCollection, function(err, body) {
+                        should(err).be.null;
+                        body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(0);
+                        body.count.should.equal(0);
+                        cb(err);
+                    })
+                },
+                function(cb) {
+                    entities.deleteAll(config.genericTestCollection1, function(err, body)
{
+                        should(err).be.null;
+                        body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(0);
+                        body.count.should.equal(0);
+                        cb(err);
+                    })
+                },
+                function(cb) {
+                    entities.deleteAll(config.genericTestCollection2, function(err, body)
{
+                        should(err).be.null;
+                        body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(0);
+                        body.count.should.equal(0);
+                        cb(err);
+                    })
+                },
+                function(cb) {
+                    entities.deleteAll(inflect.pluralize(config.consumableTestCollection),
function(err, body) {
+                        should(err).be.null;
+                        body.entities.should.be.an.instanceOf(Array).and.have.lengthOf(0);
+                        body.count.should.equal(0);
+                        cb(err);
+                    })
+                }
+            ],
+            function(err, data) {
+                console.log("      ✓".green + " done".grey);
+                if (cb && typeof(cb) === 'function') cb(err);
+            });
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ea579cbb/stack/rest_integration_tests/test/users/create.js
----------------------------------------------------------------------
diff --git a/stack/rest_integration_tests/test/users/create.js b/stack/rest_integration_tests/test/users/create.js
new file mode 100644
index 0000000..c62ccc4
--- /dev/null
+++ b/stack/rest_integration_tests/test/users/create.js
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+var should = require("should");
+var uuid = require("uuid");
+var users = require("../../lib/users");
+
+module.exports = {
+    test: function() {
+        describe("create a user", function() {
+            var username = "testuser" + uuid.v1();
+            var password = "password";
+            it("should successfully return a user object", function(done) {
+                users.add({
+                    username: username,
+                    password: password,
+                    name: username + " name",
+                    email: username + "@uge2e.com"
+                }, function(err, userBody) {
+                    should(err).be.null;
+                    userBody.should.not.be.null;
+                    users.login(username, password, function(err, body) {
+                        should(err).be.null;
+                        body.should.not.be.null;
+                        body.should.have.property("access_token");
+                        done();
+                    })
+                });
+            });
+        });
+    }
+}


Mime
View raw message