{"size": 1641, "ext": "js", "max_stars_repo_path": "test/unit/callbacks/afterDestroy.destroy.js", "max_stars_repo_name": "iamonuwa/waterline", "max_stars_repo_stars_event_min_datetime": "2021-04-23T21:52:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-23T21:52:07.000Z", "max_issues_repo_path": "test/unit/callbacks/afterDestroy.destroy.js", "max_issues_repo_name": "iamonuwa/waterline", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/unit/callbacks/afterDestroy.destroy.js", "max_forks_repo_name": "iamonuwa/waterline", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.4925373134, "max_line_length": 110, "alphanum_fraction": 0.5112736137}
var assert = require('assert');
var Waterline = require('../../../lib/waterline');

describe('After Destroy Lifecycle Callback ::', function() {
  describe('Destroy ::', function() {
    var person;
    var status;

    before(function(done) {
      var waterline = new Waterline();
      var Model = Waterline.Model.extend({
        identity: 'user',
        connection: 'foo',
        primaryKey: 'id',
        fetchRecordsOnCreate: true,
        fetchRecordsOnDestroy: true,
        attributes: {
          id: {
            type: 'number'
          },
          name: {
            type: 'string'
          }
        },

        afterDestroy: function(destroyedRecord, cb) {
          status = destroyedRecord.status;
          cb();
        }
      });

      waterline.registerModel(Model);

      // Fixture Adapter Def
      var adapterDef = {
        destroy: function(con, query, cb) { return cb(undefined, [{ status: true, id: 1 }]); },
        create: function(con, query, cb) { return cb(undefined, { status: true, id: 1 }); }
      };

      var connections = {
        'foo': {
          adapter: 'foobar'
        }
      };

      waterline.initialize({ adapters: { foobar: adapterDef }, datastores: connections }, function(err, orm) {
        if (err) {
          return done(err);
        }
        person = orm.collections.user;
        return done();
      });
    });

    it('should run afterDestroy', function(done) {
      person.destroy({ name: 'test' }, function(err) {
        if (err) {
          return done(err);
        }

        assert.equal(status, true);
        return done();
      });
    });
  });
});
