run(parentPack, 'save').then(() => {
    t.ok(parentPack.id, 'parent package has an id');
    t.ok(SmackHooks.getPackNamespace('parent'), 'parent package created in the namespace');
    var childPack = run(store, 'createRecord', 'package', { name : 'child' });
    childPack.set('parent', parentPack);

    run(childPack, 'save').then(() => {
      t.ok(childPack.id, 'child package has an id');
      t.ok(SmackHooks.getPackNamespace('parent.child'), 'child package created in the namespace');
      var grandChildPack = run(store, 'createRecord', 'package', { name : 'grandChild' });
      grandChildPack.set('parent', childPack);

      run(grandChildPack, 'save').then(() => {
        t.ok(grandChildPack.id, 'grand child package has an id');
        t.ok(SmackHooks.getPackNamespace('parent.child.grandChild'), 'grandChild package created in the namespace');
        run(parentPack, 'destroyRecord').then(() => {
          run(store, 'findAll', 'package').then(packs => {
            run(store, 'unloadAll', 'package');
            t.equal(get(packs, 'length'), 0, 'all packages were deleted');
            done();
          });
        });
      });
    });
  });
test('execute anonymous', function(t) {
  t.expect(4);
  const done = t.async(2);

  SmackHooks.getPackNamespace('')['math'] = { _f : {
    add : function(a, b) { return a + b; },
    error : function() { throw 'deliberate error'; }
  }};

  var addExec = run(store, 'createRecord', 'execute-anonymous-event',
      { source : 'c = a + b;', arguments : { a : 1, b : 1, c : 0 }});
  run(addExec, 'save').then(() => {
    t.deepEqual(get(addExec, 'result'), { a : 1, b : 1, c : 2 }, 'execution result');
    t.ok(get(addExec, 'success'), 'success status');
    done();
  });

  var errExec = run(store, 'createRecord', 'execute-anonymous-event',
      { source : 'math.error();' });
  run(errExec, 'save').then(() => {
    t.notOk(get(errExec, 'success'), 'success status');
    t.equal(get(errExec, 'errorMessage'), 'deliberate error', 'error message');
    done();
  });
});