/* global describe, it */

import assert from 'assert';
import {KATAS_URL, URL_PREFIX} from '../src/config.js';
import GroupedKata from '../src/grouped-kata.js';

describe('load ES6 kata data', function() {

  it('loaded data are as expected', function(done) {
    const loadRemoteFileStub = (url, onLoaded) => {
      let validData = JSON.stringify({groups: {}});
      onLoaded(null, validData);
    };
    function onSuccess(groupedKatas) {
      assert.ok(groupedKatas);
      done();
    }
  
    new GroupedKata(loadRemoteFileStub, KATAS_URL).load(() => {}, onSuccess);
  });
  describe('on error, call error callback and the error passed', function() {
    
    it('invalid JSON', function(done) {
      const loadRemoteFileStub = (url, onLoaded) => {
        onLoaded(new Error(''));
      };
      function onError(err) {
        assert.ok(err);
        done();
      }

      new GroupedKata(loadRemoteFileStub, '').load(onError);
    });
    it('for invalid data', function(done) {
      const invalidData = JSON.stringify({propertyGroupsMissing:{}});
      const loadRemoteFileStub = (url, onLoaded) => {
        onLoaded(null, invalidData);
      };
      function onError(err) {
        assert.ok(err);
        done();
      }

      new GroupedKata(loadRemoteFileStub, '').load(onError);
    });
  });
});

@@ -53,64 +53,8 @@
 t';%0A
-import %7BKATAS_URL, URL_PREFIX%7D from '../src/config.js';%0A
 impo
@@ -104,1130 +104,1307 @@
 ';%0A%0A
-describe('load ES6 kata 
+function remoteFileLoaderWhichReturnsGivenData(
 data
-', function() %7B%0A%0A  it('loaded data are as expected', function(done) %7B%0A    const loadRemoteFileStub = (url, onLoaded) =%3E %7B%0A      let validData = JSON.stringify(%7Bgroups: %7B%7D%7D);%0A      onLoaded(null, validData);%0A    %7D;%0A    function onSuccess(groupedKatas) %7B%0A      assert.ok(groupedKatas);%0A      done();%0A    %7D%0A  %0A    new GroupedKata(loadRemoteFileStub, KATAS_URL).load(() =%3E %7B%7D, onSuccess);%0A  %7D);%0A  describe('on error, call error callback and the error passed', function() %7B%0A    %0A    it('invalid JSON', function(done) %7B%0A      const loadRemoteFileStub = (url, onLoaded) =%3E %7B%0A        onLoaded(new Error(''));%0A      %7D;%0A      function onError(err) %7B%0A        assert.ok(err);%0A        done();%0A      %7D%0A%0A      new GroupedKata(loadRemoteFileStub, '').load(onError);%0A    %7D);%0A    it('for invalid data', function(done) %7B%0A      const invalidData = JSON.stringify(%7BpropertyGroupsMissing:%7B%7D%7D);%0A      const loadRemoteFileStub = (url, onLoaded) =%3E %7B%0A        onLoaded(null, invalidData);%0A      %7D;%0A      function onError(err) %7B%0A        assert.ok(err);%0A        done();%0A      %7D%0A%0A      new GroupedKata(loadRemoteFileStub, '
+) %7B%0A  return (url, onLoaded) =%3E %7B%0A    onLoaded(null, data);%0A  %7D;%0A%7D%0Afunction remoteFileLoaderWhichReturnsError(error) %7B%0A  return (url, onLoaded) =%3E %7B%0A    onLoaded(error);%0A  %7D;%0A%7D%0A%0Adescribe('load ES6 kata data', function() %7B%0A%0A  it('loaded data are as expected', function(done) %7B%0A    function onSuccess(groupedKatas) %7B%0A      assert.ok(groupedKatas);%0A      done();%0A    %7D%0A  %0A    const validData = JSON.stringify(%7Bgroups: %7B%7D%7D);%0A    const loaderStub = remoteFileLoaderWhichReturnsGivenData(validData);%0A    new GroupedKata(loaderStub, 'irrelevant url').load(() =%3E %7B%7D, onSuccess);%0A  %7D);%0A  describe('on error, call error callback and the error passed', function() %7B%0A    %0A    it('invalid JSON', function(done) %7B%0A      function onError(err) %7B%0A        assert.ok(err);%0A        done();%0A      %7D%0A%0A      const loaderStub = remoteFileLoaderWhichReturnsError(new Error(''));%0A      new GroupedKata(loaderStub, 'irrelevant url').load(onError);%0A    %7D);%0A    it('for invalid data', function(done) %7B%0A      function onError(err) %7B%0A        assert.ok(err);%0A        done();%0A      %7D%0A%0A      const invalidData = JSON.stringify(%7BpropertyGroupsMissing:%7B%7D%7D);%0A      const loaderStub = remoteFileLoaderWhichReturnsGivenData(invalidData);%0A      new GroupedKata(loaderStub, 'irrelevant url
 ').l

Refactor duplication out of tests.