           .send(sampleMetadata)
           .expect(404)
           .end (err, res) ->
-            if err
-              done err
-            else
-              done()         
+            return done err if err
+            done()         
                 
                 
                 

          .send(testMetadata)
          .expect(201)
          .end (err, res) ->
            if err
              done err
            else
              res.body.errors.length.should.equal 1
              res.body.successes.length.should.equal 4
              done()
                
      it  "should fail to validate invalid metadata and return status 400 - bad request", (done) ->
        testMetadata = {}
        testMetadata = JSON.parse JSON.stringify sampleMetadata
        testMetadata.InvalidField = { "name": "value" }
        request("https://localhost:8080")
          .post("/metadata/validate")
          .set("auth-username", testUtils.rootUser.email)
          .set("auth-ts", authDetails.authTS)
          .set("auth-salt", authDetails.authSalt)
          .set("auth-token", authDetails.authToken)
          .send(testMetadata)
          .expect(400)
          .end (err, res) ->
            if err
              done err
            else
              done()
      
      it  "should not allow a non admin user to validate metadata", (done) ->
        request("https://localhost:8080")

          .send(sampleMetadata)
          .expect(201)
          .end (err, res) ->
            return done err if err
            
            statusCheckObj = { Valid: 0, Conflict: 0, Error: 0 }
            for row in res.body.rows
              statusCheckObj[row.status] = statusCheckObj[row.status] + 1
              
            statusCheckObj.Valid.should.equal 5
            statusCheckObj.Conflict.should.equal 0
            statusCheckObj.Error.should.equal 0
            done()
      
      
      it  "should validate partially valid metadata and return status 201", (done) ->
        testMetadata = {}
        testMetadata = JSON.parse JSON.stringify sampleMetadata
        testMetadata.Channels = [{ "Invalid Channel" }]
        
        request("https://localhost:8080")
          .post("/metadata/validate")
          .set("auth-username", testUtils.rootUser.email)
