var expect = chai.expect;
var assert = chai.assert;

if (!(typeof MochaWeb === 'undefined')){
  MochaWeb.testOnly(function(){
    describe("Giblet Methods", function(){

      beforeEach(function(done) {
        Giblets.find().fetch().forEach(function(giblet) {
          Giblets.remove(giblet._id);
        });
        gibletData = [
        {
          taskname: 'Find tandem bike',
          url: 'https://sfbay.craigslist.org/search/bik',
          keywords: 'tandem',
          SMS: true,
          email: true,
          frequency: '1'
        },
        {
          taskname: 'Find Fender',
          url: 'https://www.reddit.com/r/Guitar/',
          keywords: 'Fender',
          SMS: false,
          email: false,
          frequency: '1'
        },
        {
          taskname: 'Find job',
          url: 'http://www.indeed.com/jobs?q=engineer&l=San+Francisco%2C+CA',
          keywords: 'javascript, front-end',
          SMS: true,
          email: false,
          frequency: '1'
        }];
        gibletData.forEach(function(giblet) {
          Meteor.call('addGiblet', giblet);
        });
        done();
      });

      it('should be able to fetch Giblets from collection', function() {
        var giblets = Giblets.find().fetch();
        expect(giblets).to.be.a('array');
        expect(giblets).to.have.length(3);
      });
      it('should add new Giblet when addGiblet method is invoked', function(){
        Meteor.call('addGiblet', {
          taskname: 'Pass test',
          url: 'http://www.test.com/',
          keywords: 'pass, testing',
          SMS: false,
          email: false,
          frequency: '1'
        });
        var giblets = Giblets.find().fetch();
        var newGib = Giblets.find({taskname:'Pass test'}).fetch();
        assert.equal(giblets.length, 4);
        expect(newGib).to.have.length(1);
      });

    });
  });
}



// if (!(typeof MochaWeb === 'undefined')){
//   MochaWeb.testOnly(function(){
//     var selectGraceHopper = function(){
//       Session.set("selected_player", Players.findOne({name: "Grace Hopper"})._id);
//     };

//     var unselectPlayer = function(){
//       Session.set("selected_player", null);
//       Meteor.flush();
//     }

//     describe("Select Grace Hopper", function(){
//       before(function(done){
//         Meteor.autorun(function(){
//           var grace = Players.findOne({name: "Grace Hopper"});
//           if (grace){
//             selectGraceHopper();
//             done();
//           }
//         })
//       });

//       it("should show Grace the inside div class='name' (above the give points button)", function(){
//         Meteor.flush();
//         chai.assert.equal($("div.details > div.name").html(), "Grace Hopper");
//       });
//     });

//     describe("Point Assignment", function(){
//       before(function(){
//         selectGraceHopper();
//       });

//       it("should give a player 5 points when they are selected and the button is pressed", function(){
//         var graceInitialPoints = Players.findOne({name: "Grace Hopper"}).score;
//         $("input:button").click();
//         chai.assert.equal(graceInitialPoints + 5, Players.findOne({name: "Grace Hopper"}).score);
//       });
//     });
//   });

@@ -1340,24 +1340,25 @@
 ;%0A      %7D);%0A
+%0A
       it('sh
@@ -1854,24 +1854,597 @@
 %0A      %7D);%0A%0A
+      it('should only display Giblets for current user', function() %7B%0A        var currentUser = Meteor.userId();%0A        Giblets.insert(%7B%0A          createdAt: new Date(),%0A          owner: 'Something else',%0A          taskname: 'Should not be visible',%0A          url: 'http://www.noThanks.com',%0A          keywords: 'bad, not permissioned',%0A          SMS: true,%0A          email: false,%0A          frequency: 4,%0A          active: true%0A        %7D);%0A        var badGib = Giblets.find(%7Btaskname:'Should not be visible'%7D).fetch();%0A        expect(badGib).to.have.length(0);%0A      %7D);%0A
     %7D);%0A  %7D)

Add test for giblet permission