it("should be able to create image only by content, lat and lng", function(){ var images = db.loadImagesModel(); var callback = createSpy('callback'); runs(function(){ images.create({ user_id: 1, content: 'this is a base64 file content', lat: 0, lng: 0 }, callback ); }); waits(100); runs(function(){ expect(callback).toHaveBeenCalledWith(null, { rows : [ { id : 'e2131648c57cb7325ff15f7b42c53112', user_id: 1, description : null, content : 'this is a base64 file content', lat : 0, lng : 0, created_at: jasmine.any(Object) } ], command : 'INSERT', rowCount : 1, oid : 0, addCommandComplete : jasmine.any(Function), addRow : jasmine.any(Function) }); }); });
it("should be able to search for images near location", function(){ var images = db.loadImagesModel(); var callback = createSpy('callback'); runs(function () { images.create({ user_id: 1, content: 'this is a base64 file content', lat: 0, lng: 0 }, function(){ images.near(0, 0, 0, callback); } ); }); waits(100); runs(function () { expect(callback).toHaveBeenCalledWith(null, [ { id : 'e2131648c57cb7325ff15f7b42c53112', user_id: 1, description : null, content : 'this is a base64 file content', lat : 0, lng : 0, created_at: jasmine.any(Object) } ]); }); });
beforeEach(function(){ db.initialize(app); var users = db.loadUsersModel(); var images = db.loadImagesModel(); runs(function(){ users.truncate(function(){ users.create({ id: 1, fb_id: 1, name: 'test user' }, function(){}); }) }); runs(function(err){ images.truncate({cascade: true}, function(){}); }); waits(100); });
it("should be not find images outside the radius near location", function(){ var images = db.loadImagesModel(); var callback = createSpy('callback'); runs(function () { images.create({ user_id: 1, content: 'this is a base64 file content', lat: 0, lng: 0 }, function(){ images.near(90, 180, 0, callback); } ); }); waits(100); runs(function () { expect(callback).toHaveBeenCalledWith(null, []); }); });
it("should extend the base object with images table", function(){ spyOn(app.db.Base, "extend"); db.loadImagesModel(); expect(app.db.Base.extend).toHaveBeenCalledWith({ tableName: 'images', primaryKey: 'id' }); });